The Varify A/B Testing template loads the Varify experimentation script into your site through GTM. It handles script injection, instance identification and optional consent-aware tracking, so you can run tests while respecting privacy preferences.
Loads the Varify A/B testing script through Google Tag Manager, with consent-aware tracking and a clean route for pushing experiment data into GA4.
What it does
Features
- Loads varify.js with a single tag, no Custom HTML required
- Identifies your project through a configurable Instance ID (window.varify.iid)
- Consent-aware mode that delays event collection until the visitor consents
- Pushes structured dataLayer events with experiment and variation identifiers
- Debug toggle for troubleshooting script loading and event firing during development
- Works with any GA4 setup through standard dataLayer variables and event triggers
Basic setup, without consent management
- Create a new tag using the Varify A/B Testing template.
- Enter your Instance ID from the Varify dashboard.
- Leave Enable consent-aware tracking unchecked.
- Save the tag.
In this mode Varify loads immediately and pushes dataLayer events as experiments activate. That suits sites without a CMP, or where A/B testing is classified as strictly necessary.
Consent-aware setup
Tick Enable consent-aware tracking and Varify still loads and applies visual changes without flicker, but pushes no dataLayer events. To switch event tracking on after consent, you need something to call varify.setTracking(true). A Custom HTML tag on your CMP's consent-granted trigger is the usual approach:
<script>
if (typeof varify !== 'undefined' &&
typeof varify.setTracking === 'function') {
varify.setTracking(true);
}
</script>Forwarding experiment data to GA4
When Varify activates an experiment it pushes this dataLayer event:
{
event: "varify",
varify_abTestShort: "Homepage Hero - Variant B",
varify_experimentId: "12345",
varify_variationId: "67890"
}To capture it in GA4:
- Create Data Layer Variables for varify_abTestShort, varify_experimentId and varify_variationId.
- Create a Custom Event trigger with the event name varify.
- Create a GA4 Event tag, for example named ab_test_exposure.
- Map the parameters: ab_test_name to varify_abTestShort, experiment_id to varify_experimentId, variation_id to varify_variationId.
- Set the tag to the custom varify trigger, not a page view trigger.
Which trigger to use
Fire the Varify tag on Consent Initialization, All Pages, or on Initialization, All Pages. That loads the script before other tags and prevents flicker while experiments render.
If flicker prevention doesn't matter to you, All Pages on Page View works too, but expect a brief flash when Varify applies its changes.
Troubleshooting
Script not loading. Check the Instance ID and look in the Network tab for https://app.varify.io/varify.js. A blocked request points at your content security policy or an ad blocker.
No dataLayer events. With consent-aware tracking on, nothing fires until varify.setTracking(true) is called. Verify in the console that the call happens after consent, and check the dataLayer panel in GTM Preview for the varify event.
Flicker on page load. Move the tag to an Initialization trigger so the script loads before DOM rendering. On Consent Initialization, confirm your CMP doesn't delay the trigger.
GA4 missing the parameters. The Data Layer Variable names are case-sensitive: varify_abTestShort, varify_experimentId, varify_variationId. Check the GA4 tag uses the custom varify event trigger.
Debug shows nothing. Make sure the Debug checkbox is on, and look in the browser console rather than the GTM Preview panel.
Support
- Varify GTM documentation: https://varify.io/en/userdocumentation/tracking-with-gtm-google-tag-manager/
- Varify help centre: https://varify.io/en/userdocumentation/
- GTM Community Template Gallery: search Varify
- GTM Help Center: https://support.google.com/tagmanager/
Want to talk about this?