Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideProduct feedbackGitHubNuGetDev CommunitySubmit a ticketLog In

Integrate Google Analytics 4 (GA4)

Track your Optimizely Web Experimentation events in Google Analytics 4 (GA4) and export variations in an experiment as audiences in GA4.



Starting July 1, 2023, GA4 replaced standard Google Universal Analytics (UA), which no longer processes data. For more information, see Introducing Google Analytics 4 (GA4).

GA4 integration functionality

Use this integration to track your Optimizely Web Experimentation experiments in Google Analytics 4 (GA4). You can also send specific variations to GA4 as audiences with the optional Report Generation functionality.



You must integrate with Google Tag Manager (GTM) if your site uses GTM or if you have the GTM script installed on your webpages. See Integrate Google Analytics 4 with Google Tag Manager for more information.

If you enabled the GA4 integration and want to send variations to GA4 as audiences, you should:

  1. Complete the second set of steps in the Enable the integration section below.
  2. Select the variations for each experiment you want to send to GA4 as audiences.

The following links are examples of Google Analytics reports you can build with the Report Generation functionality:


  • An existing account with GA4 and a GA4 property.
  • Add a data stream and set up data collection (such as adding the Google tag on your web pages). See How to set up GA4.

Configure GA4 in Optimizely Web Experimentation

For help with setting up the integration, see the GA4 integration demo walkthrough and follow the steps below.

Step 1. Enable the 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.



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

If you want to send variations to GA4 as audiences (Report Generation), continue as follows:

  1. Click Sign in with Google and enter the required information to connect Optimizely Web Experimentation with your Google account.
  1. Click Select All when prompted for what Optimizely can access in your Google account.
  1. Enter your unique 9-digit Google Analytics Property ID. See Google's documentation for help locating this ID.



    You can only connect a single GA4 property to a single Optimizely Web Experimentation project.

  1. Click Save.

Step 2. 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.

Optional: Send variations to GA4 (Report Generation)



You must be an Editor (or above) in the GA4 property to send variations to GA4 as audiences.

  1. Select up to 4 variations for the Variation Audiences you want to send to GA4. Optimizely Web Experimentation limits you to 4 variations per experiment because GA4 reports can include no more than 4 audiences.
  1. Click Save.
  2. Click Continue on the confirmation message that displays.



Make all changes to your variations/audiences before publishing an experiment. GA4 does not retroactively add users to an audience, and Optimizely Web Experimentation does not recreate a deleted audience.

If you delete an audience while an experiment is active, it still displays in the GA4 report but only with data through the time you deleted it.

How the data sends to GA4

If you directly integrate with GA4 without using GTM, Optimizely Web Experimentation sends data to GA4 in the following two ways:

  • Custom dimension – In GA4, the events from Optimizely Web Experimentation display as optimizely_decision. Using this event requires you to set up custom dimensions to create segments in GA4.
  • Pre-defined dimension – In GA4, the events from Optimizely Web Experimentation display as experience_impression. Using this event does not require you to set up custom dimensions to create segments in GA4. You can use the out-of-the-box Experience - variant ID dimension as your segment condition.



There is an option called Mask descriptive names in project code and third-party integrations in the Snippet Settings. Enabling this option hides experiment and variation names and only sends the ID to GA4. Although Optimizely Web Experimentation has this project setting enabled by default, you can disable it to see your experiment and variation names in GA4.



If you want to send Optimizely events to GA4, Optimizely has a listener that is a callback whenever the snippet sends an event. You could use this to forward events tracked in an experiment to GA4. Learn more.


Audience limits and requirements

The GA4 integration sends Optimizely Web Experimentation variations to GA4 as audiences. GA4 has the following limits for the number of audiences you can have, depending on your account:

  • GA4 standard lets you have up to 100 audiences
  • GA4 360 lets you have up to 400 audiences
  • Both versions of GA4 limit reports to include up to 4 audiences

Optimizely Web Experimentation tracks the number of audiences in your connected GA4 account and displays the number of remaining audiences in the Variation Audiences section of the experiment's Integrations page.

When you reach your GA4 audience limit, you can not send any additional variations to GA4. Optimizely Web Experimentation displays a warning message if you try to send additional variations after you have reached your GA4 audience limit.

Audience maintenance

Optimizely Web Experimentation deletes a GA4 audience for you when:

  • You archive an experiment that was sending variations to GA4.
  • You un-map a variation (deselect it on an experiment's Integrations page).



If you delete an audience while an experiment is active, it still displays in the GA4 report but only with data through the time you deleted it.

Data freshness

It can take up to 48 hours for the data to be displayed in the GA4 Reports snapshot from the time it was collected and for the audiences in GA4 to reflect new users due to processing delays. You can verify and validate that the events are accurately sent through Realtime reports by monitoring the experience_impression and optimizely_decision events, which show events triggered within the last 30 minutes.


Error loading Google audiences

If you get an error message when loading Google audiences that prevents you from sending variations, there may be a couple of reasons:

  1. You may be trying to connect an invalid or non-unique GA4 property ID to a project. You can only connect a unique 9-digit GA4 property to a single Optimizely Web Experimentation project. Re-enable the integration with GA4 to solve this issue.
  2. You must be an Editor (or above) in the GA4 property to send variations to GA4 as audiences.

Confirmation of the integration

You can verify that the integration was connected through the console logs.

Data discrepancy

The data collected in GA4 is never identical to the data collected in the Optimizely Web Experimentation's Results Page due to a variety of possibilities causing the discrepancy, such as the ones listed below.

Creating segments

When creating segments in GA4, you should only use Experience - variant id to avoid data discrepancy. See Create segments for information.

Data sampling

Analytics uses data sampling when the number of events returned by an exploration or funnel report exceeds the limit for your property type (such as a standard or 360 property). See Google's article about data sampling for information.

Data thresholds

If your report or exploration is missing data, it may be because Google Analytics has applied a data threshold. Data thresholds are applied to prevent anyone viewing a report or exploration from inferring the identity of individual users based on demographics, interests, or other signals present in the data. See GA4 Data thresholds for information.

Third-party data

You may experience data discrepancy with third-party data for various reasons, such as the following:

  • Scope – Have differences between how the platforms calculate results (like user-based, session-based, or event-based).
  • Events – Have similar visitor counts but different conversion counts for an event. Look closely at the event on each platform.
  • Bots – May or may not filter out bots in your results.
  • Content blockers – Can block any client-side trackers, including Optimizely Web Experimentation.

Learn more about each potential reason and others in Discrepancies in third-party data.


Timing can also affect your data. Because the Optimizely Web Experimentation snippet is often placed high on the page, whereas GA4 often fires later, Optimizely may start logging events before GA4. You can address this timing mismatch by calling holdEvents before the snippet activates and sendEvents from within a callback function provided by your analytics library. See Control the timing of Optimizely Web Experimentation Event dispatch with holdEvents and sendEvents for information.

Audience attribution

When you create an audience based on a given experiment variation, the data collected in GA4 may not automatically get attributed to audiences in real time. However, the users are attributed to the audience in the report snapshot view within 48 hours.

GA4 reprocessing

In rare cases, you may notice data loss in GA4 due to reprocessing experience data, which can cause GA4 to remove the audience ID. For information on reprocessing in GA4, see Google's documentation.

If this happens, there are a couple of workarounds to find your data:

  • Use GA4 Explorations – Resurface the experience-variant ID. This displays users that saw the experiment but is less granular due to Exploration limitations (cannot filter by date range). For information, see Google's documentation on Explorations.
  • Export events using BigQuery – View events and filter by date range. For information, see Google's documentation on BigQuery.