Google Analytics
Ttoolab can push experiment exposure and conversion data to window.dataLayer, making it available to Google Tag Manager and Google Analytics 4.
How it works
Section titled “How it works”When the GTM events integration is enabled for your project, the Ttoolab pixel automatically pushes dataLayer entries on:
- Exposure — when a visitor is assigned to experiments (
$exposure) - Conversion — when you call
ttoolab.track()with a custom event
No extra code is required on your site beyond the standard pixel installation and GTM container.
Enable the integration
Section titled “Enable the integration”- Open Integrations → Google Analytics in the Ttoolab dashboard.
- Connect your Google account (OAuth) if you want GA4 property linking for dashboard metrics.
- Enable GTM dataLayer events for your project.
The SDK reads integration settings from the bootstrap response and pushes events when gtmEventsEnabled is true.
dataLayer event structure
Section titled “dataLayer event structure”Exposure event
window.dataLayer.push({ event: "ttoolab_exposure", ttoolab_test: "ttoolab_test", ttoolab_experimentName: "Hero CTA Test", ttoolab_variationName: "Variant B", ttoolab_experimentKey: "hero-cta-test", ttoolab_experimentId: "EXPERIMENT_ID", ttoolab_variantKey: "variant-b", ttoolab_variantId: "VARIANT_ID", ttoolab_isControl: false, ttoolab_eventName: "exposure", ttoolab_eventType: "exposure"});Conversion event
window.dataLayer.push({ event: "ttoolab_conversion", ttoolab_test: "ttoolab_test", ttoolab_experimentName: "Hero CTA Test", ttoolab_variationName: "Variant B", ttoolab_experimentKey: "hero-cta-test", ttoolab_experimentId: "EXPERIMENT_ID", ttoolab_variantKey: "variant-b", ttoolab_variantId: "VARIANT_ID", ttoolab_isControl: false, ttoolab_eventName: "purchase", ttoolab_eventType: "conversion", ttoolab_revenue: 99.90});One dataLayer entry is pushed per active assignment.
GTM trigger setup
Section titled “GTM trigger setup”Create a trigger in GTM:
- Trigger type: Custom Event
- Event name:
ttoolab_exposureorttoolab_conversion
Create GA4 Event tags that map Ttoolab fields to GA4 event parameters.
GA4 custom dimensions
Section titled “GA4 custom dimensions”To compare variants in GA4 reports, register these custom dimensions in GA4 Admin:
| Dimension | Event parameter |
| :-------- | :-------------- |
| Experiment name | ttoolab_experimentName |
| Variation name | ttoolab_variationName |
Without these dimensions, GA4 will receive events but per-variant breakdowns will be limited.
GA4 dashboard integration
Section titled “GA4 dashboard integration”The Ttoolab dashboard can display GA4 metrics alongside experiment results when you connect via OAuth and select a GA4 property.
Troubleshooting
Section titled “Troubleshooting”- Confirm GTM events are enabled in Ttoolab project settings.
- Verify your GTM container loads before or alongside the Ttoolab pixel.
- Check
window.dataLayerin the browser console after a page load with active experiments. - See Common issues.