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 property

That 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

OptionWhat GTM ownsWhere the ClickMint script livesWhen to use
Option A — preferredOnly the cm_tracking event tag, trigger, and variablesInstalled manually in the page <head>Use this whenever you can edit the head or a CMS head field
Option B — fallbackThe event wiring and the ClickMint script tagInjected by GTM Custom HTMLUse 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_tracking event 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:

PlaceholderReplace 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

  1. Go to Admin → Import Container
  2. Upload the edited JSON file
  3. Choose Merge
  4. Choose Rename conflicting tags, triggers, and variables
  5. Confirm the import

Step 3 — install the ClickMint script manually in <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 - serverless fires on cm_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_tracking event 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:

PlaceholderReplace 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

  1. Admin → Import Container
  2. Upload the edited file
  3. Choose Merge
  4. Choose Rename conflicting tags, triggers, and variables
  5. Confirm the import

Step 3 — preview the timing, not just the event

In GTM Preview, verify both of these:

  • The cm_tracking event 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 nameValue
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 nameValue
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 nameData Layer Variable Name
cm dl event typeeventModel.event_type
cm dl experiment ideventModel.experiment_id
cm dl experiment modeeventModel.experiment_mode
cm dl experiment varianteventModel.experiment_variant
cm dl outcome ideventModel.outcome_id
cm dl outcome indexeventModel.outcome_index
cm dl outcome typeeventModel.outcome_type
cm dl up experiment iduser_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 nameData Layer Variable NameScopeDescription
cm dl event typeeventModel.event_typeEventvariant_loaded, control, or error
cm dl experiment ideventModel.experiment_idEventClickMint tracking ID
cm dl experiment modeeventModel.experiment_modeEventproduction or preview
cm dl experiment varianteventModel.experiment_variantEventVariant token
cm dl outcome ideventModel.outcome_idEventOutcome / variant identifier
cm dl outcome indexeventModel.outcome_indexEventNumeric variant index as a string
cm dl outcome typeeventModel.outcome_typeEventredirect, repaint, control, or error descriptor
cm dl up experiment iduser_properties.experiment_idUserExperiment 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 - serverless fires on the cm_tracking event
  • Your existing Google Tag still behaves normally
  • The cm dl * variables resolve to values instead of undefined

Step 2 — Confirm the ClickMint script loads correctly

  • Option A: confirm the script is present in the page <head> and loads from experiments.api.clickmint.com
  • Option B: confirm the GTM-owned script tag fires and loads from experiments.api.clickmint.com

Step 3 — GA4 DebugView

  1. Open GA4 → Admin → DebugView
  2. Visit a page with an active experiment
  3. Confirm a cm_tracking event appears
  4. Confirm the event includes experiment parameters
  5. 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

SymptomLikely causeFix
cm event tracking - serverless never firesTrigger is misconfiguredConfirm the trigger type is Custom Event and the event name is exactly cm_tracking
cm dl * variables show undefinedData Layer Variable Name typoRe-check the variable names against the reference table above
cm_tracking appears but experiment_id is missing as a user propertyThe ClickMint script is not setting the persistent tracking property or GA4 custom definitions are incompleteConfirm the ClickMint script is running early enough and re-check the GA4 setup hub
The experiment appears late or flickersYou are using GTM-owned script injectionMove to Option A and install the script directly in <head>
Existing ecommerce tags break after importThe wrong GTM merge strategy was used or legacy tags were overwrittenRe-import using Merge → Rename conflicting items and restore the GTM workspace version if needed
No event is sent before consentCMP is blocking GA4 completelyThis is expected behavior; the experiment can still run but measurement waits for GA4 availability
Conversions remain at zero after 48 hoursGA4 custom definitions were not created or are still within processing delayRevisit the setup hub and confirm experiment_id is registered as a user-scoped dimension and the event-scoped definitions are in place