Approach 2: GTM Serverless
Integrate ClickMint without replacing existing GA4 tags — ideal for server-side GTM and Consent Mode v2.
Approach 2: GTM Serverless Event Tracking
ClickMint CRO Platform — Client Documentation Last updated: April 2026
Who this is for: GTM-, sGTM-, Consent Mode-, or vendor-managed stacks where your existing Google Tag / GA4 configuration should remain in place.
← GA4 Experiment Tracking: Setup Hub
Overview
This approach keeps your existing Google Tag / GA4 configuration intact while adding ClickMint's experiment tracking into the same GTM measurement flow.
At a high level:
ClickMint script → gtag()/dataLayer → GTM Custom Event trigger → GA4 Event tag → your existing GA4 propertyThat means you do not replace your current GTM / GA4 setup. You add the ClickMint event wiring alongside it.
Why there are now two GTM serverless options
We now recommend two GTM serverless patterns because GTM handles Custom HTML script placement differently than many teams expect.
The important behavior
GTM often appends Custom HTML scripts near the end of <body>, not where you visually placed the tag in the GTM UI. For most marketing tags, that is fine. For ClickMint, it can delay when the experiment becomes visible.
The resulting recommendation
| Option | What GTM owns | Where the ClickMint script lives | When to use |
|---|---|---|---|
| Option A — preferred | Only the cm_tracking event tag, trigger, and variables | Installed manually in the page <head> | Use this whenever you can edit the head or a CMS head field |
| Option B — fallback | The event wiring and the ClickMint script tag | Injected by GTM Custom HTML | Use only when you truly cannot install the script in <head> yourself |
Bottom line: GTM is great for forwarding the event. It is usually not the best place to own the experiment script itself.
When to use this approach
Use this guide if any of the following apply:
- GA4 is managed by GTM or server-side GTM (sGTM)
- You use Consent Mode v2 and want to preserve your current consent chain
- You use Elevar, Littledata, or another vendor-managed GTM / Google Tag setup
- Your GA4 event tags already depend on the current Google Tag and you do not want to replace it
- You want ClickMint to plug into your existing GTM measurement layer instead of moving GA4 into direct page code
If GA4 is already installed directly in site code and you can edit the page head, use Approach 1: Direct / Native Script Installation instead.
Prerequisites
Before you begin, make sure you have:
- Completed GA4 Experiment Tracking Setup
- Access to your web GTM container (not just the server-side container)
- Your GA4 Measurement ID (
G-XXXXXXXXXX) - Your ClickMint org token / script identifier
- Your existing Google Tag or GA4 Configuration tag left in place
Option A — preferred: events-only template + manual head install
This is the recommended pattern for GTM-managed stacks.
What this option does
- GTM handles the
cm_trackingevent dispatch into GA4 - Your existing Google Tag stays exactly where it is
- You install the ClickMint experiment script manually in the page
<head> - You avoid the delay caused by GTM-owned Custom HTML script injection
Step 1 — download and configure the events-only template
Before importing, find and replace the placeholder in the JSON:
Placeholder Replace with REPLACE_WITH_GA4_MEASUREMENT_IDYour GA4 Measurement ID (for example G-XXXXXXXXXX)
📥 Open the Events-Only GTM Template →
Copy the JSON from that page, replace the placeholder, and save as a .json file.
Step 2 — import into GTM
- Go to Admin → Import Container
- Upload the edited JSON file
- Choose Merge
- Choose Rename conflicting tags, triggers, and variables
- Confirm the import
Step 3 — install the ClickMint script manually in <head>
<head>Use the ClickMint script from Approach 1 and place it in the page <head> immediately after your GTM or direct GA4 bootstrap.
Common places to install it:
- Shopify theme head
- WordPress head injection plugin
- Magento / Adobe Commerce HTML Head field
- Next.js / React shared layout
- CMS-wide head code setting
If you need platform-specific placement examples, use Approach 1 as the placement guide — the script snippet is the same.
Step 4 — preview and publish
In GTM Preview / Tag Assistant, confirm:
cm event tracking - serverlessfires oncm_tracking- Your existing Google Tag still fires normally
- The
cm dl *variables resolve with values when the event occurs
Then publish the workspace.
Consent note: if your CMP blocks GA4 entirely until consent is granted, the experiment can still run but the
cm_trackingevent will not be forwarded until GA4 becomes available.
Option B — fallback: complete GTM template
Use this only when you cannot install the ClickMint script in the page <head> yourself.
⚠️ Clear warning: this template lets GTM inject the ClickMint script. That is easier operationally, but it can delay when the experiment appears because GTM Custom HTML is often appended near the bottom of the page. Expect a higher risk of visible flicker or late variant application compared with Option A.
Step 1 — download and configure the complete template
Before importing, find and replace these placeholders in the JSON:
Placeholder Replace with REPLACE_WITH_GA4_MEASUREMENT_IDYour GA4 Measurement ID REPLACE_WITH_ORG_TOKENYour ClickMint org token / script identifier
📥 Open the Complete GTM Template →
Copy the JSON from that page, replace both placeholders, and save as a .json file.
Step 2 — import into GTM
- Admin → Import Container
- Upload the edited file
- Choose Merge
- Choose Rename conflicting tags, triggers, and variables
- Confirm the import
Step 3 — preview the timing, not just the event
In GTM Preview, verify both of these:
- The
cm_trackingevent is reaching GA4 - The experiment is appearing early enough on page load for your storefront UX standards
If you see the original page briefly before the experiment applies, switch to Option A as soon as you have a path to install the script in <head>.
Manual build reference (advanced)
Use this section if you prefer to create the GTM pieces manually instead of importing JSON.
A. Create the GA4 Event tag
Create a tag named cm event tracking - serverless:
- Tag type: Google Analytics: GA4 Event
- Measurement ID: your existing GA4 Measurement ID
- Event name:
cm_tracking
Add these event parameters:
| Parameter name | Value |
|---|---|
event_type | {{cm dl event type}} |
experiment_id | {{cm dl experiment id}} |
experiment_mode | {{cm dl experiment mode}} |
experiment_variant | {{cm dl experiment variant}} |
outcome_id | {{cm dl outcome id}} |
outcome_index | {{cm dl outcome index}} |
outcome_type | {{cm dl outcome type}} |
page_path | {{Page Path}} |
Add this user property:
| Property name | Value |
|---|---|
experiment_id | {{cm dl up experiment id}} |
Use cm tracking event as the trigger.
B. Create the Custom Event trigger
Create a trigger named cm tracking event:
- Trigger type: Custom Event
- Event name:
cm_tracking - Fires on: All Custom Events
C. Create the Data Layer variables
Create these Data Layer Variables (Version 2):
| Variable name | Data Layer Variable Name |
|---|---|
cm dl event type | eventModel.event_type |
cm dl experiment id | eventModel.experiment_id |
cm dl experiment mode | eventModel.experiment_mode |
cm dl experiment variant | eventModel.experiment_variant |
cm dl outcome id | eventModel.outcome_id |
cm dl outcome index | eventModel.outcome_index |
cm dl outcome type | eventModel.outcome_type |
cm dl up experiment id | user_properties.experiment_id |
D. Only for Option B: create the GTM-owned script tag
If you must use the fallback pattern, add a Custom HTML tag named cm script - serverless using the ClickMint snippet, enable Support document.write, and fire it on Initialization - All Pages (or your equivalent consent-aware page trigger).
Keep in mind: this is the part that introduces the delay risk.
E. Tags to keep untouched
Do not replace or delete the following unless ClickMint support explicitly tells you to:
- Your existing Google Tag / GA4 Configuration tag
- Existing GA4 ecommerce event tags such as
purchase,add_to_cart,begin_checkout - Vendor-managed data layer helpers from Elevar, Littledata, etc.
If you need vendor-specific guidance, use the supplemental GTM Platform Notes & Migration Guide.
Data Layer Variable reference
These names are case-sensitive and must match exactly.
| GTM variable name | Data Layer Variable Name | Scope | Description |
|---|---|---|---|
cm dl event type | eventModel.event_type | Event | variant_loaded, control, or error |
cm dl experiment id | eventModel.experiment_id | Event | ClickMint tracking ID |
cm dl experiment mode | eventModel.experiment_mode | Event | production or preview |
cm dl experiment variant | eventModel.experiment_variant | Event | Variant token |
cm dl outcome id | eventModel.outcome_id | Event | Outcome / variant identifier |
cm dl outcome index | eventModel.outcome_index | Event | Numeric variant index as a string |
cm dl outcome type | eventModel.outcome_type | Event | redirect, repaint, control, or error descriptor |
cm dl up experiment id | user_properties.experiment_id | User | Experiment ID user property for GTM-side event forwarding |
{{Page Path}} is a built-in GTM variable and does not require custom setup.
Why user properties still matter
Even in the GTM serverless pattern, ClickMint still depends on a GA4 user-scoped property for downstream conversion attribution.
The GTM event tag forwards the cm_tracking event. Separately, the ClickMint script sets the persistent user-scoped tracking property ClickMint currently relies on:
experiment_id
Outcome details such as experiment_variant, outcome_id, outcome_index, outcome_type, and event_type are carried on the cm_tracking event payload.
GA4 attaches the persisted experiment_id user property to later events in the session, including purchase. That is what allows ClickMint to correlate revenue back to tracked experiment exposure.
If the GTM event is visible in DebugView but experiment_id is missing as a user property, impression diagnostics may work while conversion attribution remains incomplete.
Verifying your setup
Step 1 — GTM Preview / Tag Assistant
Confirm that:
cm event tracking - serverlessfires on thecm_trackingevent- Your existing Google Tag still behaves normally
- The
cm dl *variables resolve to values instead ofundefined
Step 2 — Confirm the ClickMint script loads correctly
- Option A: confirm the script is present in the page
<head>and loads fromexperiments.api.clickmint.com - Option B: confirm the GTM-owned script tag fires and loads from
experiments.api.clickmint.com
Step 3 — GA4 DebugView
- Open GA4 → Admin → DebugView
- Visit a page with an active experiment
- Confirm a
cm_trackingevent appears - Confirm the event includes experiment parameters
- Confirm the relevant user properties appear on the session / event data
Step 4 — Watch for presentation delay
Especially with Option B, visually confirm the experiment is not applying noticeably late.
If the original page flashes before the variant appears, move to Option A.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
cm event tracking - serverless never fires | Trigger is misconfigured | Confirm the trigger type is Custom Event and the event name is exactly cm_tracking |
cm dl * variables show undefined | Data Layer Variable Name typo | Re-check the variable names against the reference table above |
cm_tracking appears but experiment_id is missing as a user property | The ClickMint script is not setting the persistent tracking property or GA4 custom definitions are incomplete | Confirm the ClickMint script is running early enough and re-check the GA4 setup hub |
| The experiment appears late or flickers | You are using GTM-owned script injection | Move to Option A and install the script directly in <head> |
| Existing ecommerce tags break after import | The wrong GTM merge strategy was used or legacy tags were overwritten | Re-import using Merge → Rename conflicting items and restore the GTM workspace version if needed |
| No event is sent before consent | CMP is blocking GA4 completely | This is expected behavior; the experiment can still run but measurement waits for GA4 availability |
| Conversions remain at zero after 48 hours | GA4 custom definitions were not created or are still within processing delay | Revisit the setup hub and confirm experiment_id is registered as a user-scoped dimension and the event-scoped definitions are in place |
Updated 8 days ago
