Disclaimer: This website requires JavaScript to function properly. Some features may not work as expected. Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Integrate Google Analytics 4 with Google Tag Manager

Enable Optimizely Web Experimentation's built-in Google Analytics 4 integration with Google Tag Manager.

📘

Note

See Optimizely's Third-Party Add-Ons & Platform Integration Terms.

Using Optimizely's built-in Google Analytics 4 (GA4) integration, you can integrate with Google Tag Manager (GTM) if you use GTM as a tag management system to add and update your own tags for conversion tracking and site analytics or if you have the GTM script installed on the page.

Benefits of using GTM with the GA4 integration include

  • Streamlined tag management – GTM lets you manage and deploy multiple tags, including GA4 tags, without modifying the codebase.
  • Enhanced data accuracy – By using GTM to deploy GA4 tags, you can ensure consistent and accurate data collection across your website for making informed decisions.
  • Flexible and scalable tracking – GTM's flexible environment lets you track a wide range of user interactions and behaviors, which can impact setting up and analyzing experiments.

Configure the integration

Enable the GA4 integration

  1. Go to Settings > Integrations.
  2. Click Google Analytics 4 - Report Generation.
  3. Click the toggle to turn on the integration and click Accept.

📘

Note

You must be a Project Owner (or above) in Optimizely Web Experimentation to enable the integration.

Add the GA4 integration to an experiment

When you enable the built-in GA4 integration in your account, it displays as an option on your experiments' Integrations page.

  1. Go to Integrations in an experiment.
  2. Select the Tracked check box on each experiment to send data to GA4 if you did not enable the built-in integration by default for new experiments.
  1. Click Save.

Select to use GTM

Select the Use Google Tag Manager for this integration checkbox then click Save. This enables data to sync from your experiments to GTM, increasing the accuracy of analytics and letting you manage and deploy tags.

Add User-Defined Variables in GTM

  1. Go to Workspace > Variables > New.

  2. Enter exp_variant_string in the Untitled Variable field.

  3. Click Variable Configuration and select Data Layer Variable.

  4. Enter exp_variant_string for the Data Layer Variable Name.

  5. Select Version 2 for the Data Layer Version.

  6. Click Save.

  7. Repeat steps 1-6 with the following new information:

    • Enter Holdback in the Untitled Variable field.
    • Enter Holdback for the Data Layer Variable Name. This is case-sensitive.

Set up the configuration tag in GTM

📘

Note

This section connects GTM with GA4. If you already have a configuration tag, you can skip this section and set up the event tag .

  1. Go to Workspace > Tags > New.

  2. Enter Google Analytics - GA4 Configuration in the Untitled Tag field.

  3. Click Tag Configuration and select Google Analytics > Google Tag.

  4. Enter your Tag ID. This is the same as your GA4 Measurement ID which can be found in your GA4 property under Admin Settings > Data Streams. Select the appropriate data stream to find your Measurement ID.

  5. Expand Configuration settings and click Add parameter. Select None in the dropdown list for Configuration Settings Variable, input send_page_view for Configuration Parameter, and set the Value to true.

  6. Click Triggering and select Initialization - All Pages.

  7. Click Save.

Set up the event tag in GTM

  1. Go to Workspace > Tags > New.

  2. Enter Optimizely Web - GA4 Event in the Untitled Tag field.

  3. Click Tag Configuration and select Google Analytics > Google Analytics: GA4 Event.

  4. Enter your Measurement ID from GA4.

  5. Enter experience_impression in the Event Name.

  6. Expand Event Parameters and then click Add Parameter.

  7. Enter exp_variant_string in the Parameter Name.

  8. Click the Value Select icon and choose exp_variant_string.

  9. Click Add Parameter.

  10. Enter Holdback in the Parameter Name. This is case-sensitive.

  11. Click the Value Select icon and choose Holdback.

  12. Click Triggering and click the New Trigger icon.

  13. Enter Optimizely X - GA4 event trigger in the Untitled Trigger field.

  14. Click Trigger Configuration and select Custom Event.

  15. Enter experience_impression in the Event Name.

  16. Click Save and then click Save again on the overall tag setup page.

  17. Submit and publish your workspace changes by going to Workspace >  Submit > Publish (adding any details you would like to the Submission Configuration).

Your data immediately starts syncing to GA4. You should see the experience_impression event name display in the Realtime report once events are triggered within the last 30 minutes.

Troubleshooting

I do not see any visitors in the exported GA4 audiences.

If your audiences do not have visitors, either the experience_impression events are not sent to GA4, or the event does not have the parameters exp_variant_string and Holdback in that exact form. Follow the steps for adding user-defined variables and setting up the event tag.

These elements are required to integrate with GTM. The integration pushes experience_impression to the dataLayer whenever a decision is taken for the visitor. GTM must pick up the event and parameters/variables from the dataLayer and pass it on to GA4. If the variables and parameters are not named correctly, the GA4 Report Generation feature does not receive them because it expects certain names.