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 (GA4)

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

📘

Note

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

Prerequisites

  • An existing Google Analytics 4 (GA4) account and property.
  • A data stream and configured 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.

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.

Report Generation

Use Report Generation to send experiment variations to GA4 as audiences, eliminating the need to manually create custom dimensions and segments. This lets you compare and contrast the performance of variations through custom reports on audiences. See Configure Report Generation for information.

Troubleshoot

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 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.
  3. You may need to re-enable the integration to restore a potentially invalid token.

Confirmation of the integration

You can verify that the integration was connected through the console logs if you enabled the Optimizely logs.

Data discrepancy

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

Misconfigured Google Tag Manager

You may have missed part of the setup if you are using GA4 with Google Tag Manager (GTM). Check the event parameter to ensure it aligns with the documentaiton.

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 Web Experimentation.
  • Consent management – May have misaligned consent between Web Experimentation and GA4.

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

Timing

Timing can also affect your data. Because the 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.

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.