> ## Documentation Index
> Fetch the complete documentation index at: https://docs2.growthbook.io/llms.txt
> Use this file to discover all available pages before exploring further.

# GrowthBook and Google Analytics (GA4)

> Troubleshooting Google Analytics (GA4)

Google Analytics (GA4) is a popular Data Source among GrowthBook users. This article helps troubleshoot common issues encountered when integrating GA4 with GrowthBook, and can be used in combination with our guide on [A/B Testing with Google Analytics 4 (GA4) and GrowthBook](/guide/GA4-google-analytics).

Please watch the [How GrowthBook Works with Your Data](https://youtu.be/hboLeUbpdus) (4 minutes) overview video to better understand the issues and solutions in this troubleshooting guide.

If you are using Google Tag Manager (GTM) in combination with GA4, please review our [Google Tag Manager Setup Guide](/guide/google-tag-manager-and-growthbook) and accompanying [Google Tag Manager (GTM) Troubleshooting Guide](/kb/google-analytics/google-tag-manager-gtm-troubleshooting).

## Special note for the HTML and JavaScript SDKs

### GA4 and GrowthBook's HTML Script Tag SDK

GrowthBook's HTML Script Tag SDK provides [automatic experiment tracking](/lib/script-tag#tracking-experiment-views) if it detects Google Tag Manager (GTM) and/or Google Analytics (GA4) on the webpage.

For each experiment view, the HTML SDK sends an event with the `experiment_id` and any `variation_id`s to these analytics tools if they are present on the webpage.

No additional configuration is needed for these integrations; simply include the HTML script tag as shown in the documentation and the `experiment_viewed` events will be sent automatically.

If you need to define a custom `trackingCallback` you can do so with the `window.growthbook_config.trackingCallback` object. This must be set before loading the script tag.

### GA4 and GrowthBook's JavaScript SDK

Similar to the details above regarding the HTML SDK, the JavaScript SDK can accommodate [an optional plugin](/lib/js#third-party-tracking) that will automatically send `experiment_viewed` events to GTM and/or GA4 if configured. The plugin is **not** enabled by default and must be imported and then added to the `plugins` array when constructing the `growthbook` instance.

## Common issues when integrating GA4 with GrowthBook

The issues described below are commonly reported and can lead to missing or incomplete experiment data in GA4.

### Data propagation delays

There is a known 24-48 hour delay between when events are sent to GA4 and when they appear in your BigQuery instance, which can cause temporary gaps in reporting. Read more about this initial sync delay in our [Google BigQuery (BQ) Troubleshooting Guide](/kb/google-analytics/google-big-query-bq-troubleshooting#initial-sync-delay-for-new-ga4-properties).

### User counts and data discrepancies

GrowthBook and GA4 may count users differently due to factors like bot filtering, data processing differences, or sampling in GA4. This can lead to mismatched user or event counts between the two platforms.

### Experiment Assignment Query (EAQ) issues

#### The default SQL generated by GrowthBook doesn't match the schema in BigQuery

The default [Experiment Assignment Queries](/app/datasources#experiment-assignment-queries) in GrowthBook may not match the connected BigQuery dataset or schema, requiring manual adjustment. If these queries are not set up correctly, GrowthBook will not be able to retrieve experiment data from GA4’s BigQuery export.

Access the Experiment Assignment Query for each Data Source by going to:

1. The Left navigation menu
2. Metrics and Data
3. Data Sources
4. Select the data source in question
5. Scroll down to the Experiment Assignment Queries section
6. Click the right-facing arrow on the right side of each Experiment Assignment Query to view the SQL for the query

Only GrowthBook users with a user role of Analyst, Experimenter, or Admin can modify the Experiment Assignment Queries. Read more about this in our [User & Team Permissions](/account/user-permissions) documentation.

#### Testing the experiment's flow of data

After implementing the `trackingCallback`, check GA4 **and** the data warehouse (usually BigQuery if GA4 is also being used) to confirm that the `experiment_viewed` events are being recorded as expected.

Since the flow of data is from the experiment to GA4 to BigQuery to the results tab in GrowthBook, if no `experiment_viewed` events are present in GA4, they will not be present in BigQuery or in GrowthBook.

You can also test the Experiment Assignment Queries for each Data Source to ensure that they return the expected results. Locate the "Test Query" button for each Experiment Assignment Query and click it. If nothing is returned, try commenting out the lines with `experiment_id` and `variation_id` (one at a time) to see if anything gets returned. This can help narrow down whether the `experiment_viewed` event is making it into GA4.

While testing the Experiment Assignment Queries, If you see a message that says `No data yet. Make sure your experiment is tracking properly.` it often means the `trackingCallback` is not firing or the data is not reaching GA4. It can also mean that you are within the 24-48 hour known sync delay between GA4 and BigQuery.

Please view these resources for more information:

* [No or little traffic flowing into the experiment](/kb/experiments/troubleshooting-experiments#problem-1-no-or-little-traffic-flowing-into-the-experiment)
* [Initial sync delay for new GA4 properties](/kb/google-analytics/google-big-query-bq-troubleshooting#initial-sync-delay-for-new-ga4-properties)

### The `trackingCallback` doesn't fire or is misconfigured

If the GrowthBook SDK’s `trackingCallback` is not implemented correctly, or if it does not send the `experiment_viewed` event to GA4, experiment exposures will not be tracked, resulting in missing or incomplete data in GrowthBook.

The HTML Script Tag SDK handles this automatically and no adjustment should be necessary. Usage of other SDKs requires manually configuring the `trackingCallback` to send `experiment_viewed` events to GA4. Read on for more information.

#### Format for `trackingCallback` for pure GA4 integrations (no GTM)

Use `gtag` in the `trackingCallback` if Google Analytics 4 (GA4) is loaded directly on your page **and** the `window.gtag` function is available on the web page:

```javascript theme={null}
trackingCallback: (experiment, result) => {
  if (window.gtag) {
    window.gtag("event", "experiment_viewed", {
      event_category: "experiment",
      experiment_id: experiment.key,
      variation_id: result.variationId // or result.key depending on SDK version
   });
}
```

#### Format for `trackingCallback` for combined GA4 and GTM integrations

Use `dataLayer` in the `trackingCallback` if you are using Google Tag Manager (GTM) to manage your analytics setup, **or** if `gtag` for GA4 is not available on the web page.

This approach is recommended when GA4 is loaded via GTM because:

* Sometimes `gtag` may not be defined in this type of setup.
* If GA4 is not properly loaded on the page, the `window.gtag` function will not exist, and attempts to send events to `gtag` via GrowthBook's `trackingCallback` will fail silently.
* When GA4 is loaded through GTM, there can be timing issues because GTM loads asynchronously. This creates a potential race condition where GrowthBook might initialize before GA4 is fully loaded, which can affect experiment tracking.

```javascript theme={null}
// JavaScript
trackingCallback: (experiment, result) => {
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
    event: "experiment_viewed",
    experiment_id: experiment.key,
    variation_id: result.variationId // or result.key depending on SDK version
  });
}
```

See the [Tracking via `dataLayer` and GTM](/guide/google-tag-manager-and-growthbook#4-tracking-via-datalayer-and-gtm) documentation for more information.

### Date range mismatches

If the date ranges selected in GA4 and GrowthBook are not identical, reported metrics and user counts will differ.

It's important to note that in some cases, even if the date ranges match, it is still possible for there to be a data discrepancy due to some of the other causes outlined in this troubleshooting guide.

### Consent and cookie banner blocking

If a cookie consent banner blocks analytics until consent is given, the `experiment_viewed` event may be sent before consent, causing it to be dropped.

Delay initializing the GrowthBook SDK and firing the `trackingCallback` (which will send the `experiment_viewed` event) until after the user has granted consent. This ensures that analytics and experiment exposure events are only sent when it is legally and technically permitted.

#### Special instructions if using the HTML Script Tag SDK or the Edge SDK

Read more about cookies and GDPR compliance in the docs for the [HTML Script Tag SDK](/lib/script-tag#cookie-policy-and-gdpr) and [Edge SDK](/lib/edge/lambda#cookie-policy-and-gdpr).

## Prerequisite Configurations

There are a few things that need to be set up properly in GrowthBook in order to troubleshoot GA4 issues, regardless of whether you are using Google Tag Manager (GTM) with GA4 or not.

### Ensure the GA4 Measurement ID is correct

The GA4 Measurement ID is a unique identifier for your GA4 property that's used to send data from your website or app to the correct GA4 account. It looks like "G-XXXXXXXXXX" and is required when configuring GA4 tags in Google Tag Manager or when sending events directly to GA4.

You can see how the Measurement ID is used in the [GrowthBook and GTM integration](/guide/google-tag-manager-and-growthbook#4-tracking-via-datalayer-and-gtm) documentation, where it is entered as a configuration value for sending experiment events to GA4.

### Ensure the GrowthBook SDK is properly configured

Make sure you have created an SDK Connection in the GrowthBook app under **Left navigation menu** > **SDK Configuration** > **SDK Connections**, and that you are using the correct `apiHost` and `clientKey` values in your SDK initialization code. View [the example initialization code](/lib/js#step-1-configure-your-app) (JavaScript) for more information.

#### Verify SDK connection using GrowthBook's DevTools Extension

The SDK connection can be further validated by using GrowthBook's [DevTools Browser Extension](/tools/chrome-extension) (available for [Chrome](https://chromewebstore.google.com/detail/growthbook-devtools/opemhndcehfgipokneipaafbglcecjia) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/growthbook-devtools/)), which allows you to inspect experiments and confirm that DOM mutations are being applied as expected.

If your site is public, the extension should detect the SDK and display active experiments. If you encounter issues, double-check that your SDK code is correctly implemented and that the site is accessible (not behind authentication or firewalls that could block the SDK).

For advanced setups, such as using a proxy or remote evaluation, ensure that the relevant options are enabled both in your SDK Connection and in your SDK initialization (include `remoteEval: true` in the GrowthBook initialization code).

### Ensure the SDK is properly initialized in the application

To properly initialize the GrowthBook SDK in your application, you first need to install the appropriate SDK package for your language or framework (e.g., `npm install @growthbook/growthbook-react` for React, or the relevant package for Java, PHP, etc.).

Follow the [SDK-specific docs](/lib/) and ensure the initialization code being used contains the correct `api_host`, `client_key`, and that any relevant user attributes are present.

#### If GrowthBook is initialized on a specific page (not globally)

To initialize the GrowthBook SDK on a specific page, instead of globally, you can create and configure a GrowthBook instance directly within that page’s component or script, rather than at the global application level.

For example, in a React or Next.js app, ensure that the GrowthBook SDK has been imported and instantiated inside a page component or within a `useEffect` hook.

Of course, make sure that the experiment in question is located on the page that is initializing GrowthBook.

### Ensure the `trackingCallback` is called unconditionally

Try not to bury the `trackingCallback` within conditional application logic. Conditionally calling the `trackingCallback` can cause fewer users to be assigned to the experiment than you are expecting. Refer to [this section](/kb/experiments/troubleshooting-experiments#solution-1-ensure-the-trackingcallback-is-triggered-unconditionally) in our Knowledge Base for more information.

#### Experiment Rule Precedence

Rules associated with a feature in GrowthBook are evaluated from top to bottom as they appear in the GrowthBook UI. When a user matches a rule higher up in the list, they will not be evaluated for any subsequent rules. To ensure that the `trackingCallback` fires for users in an experiment, make sure that the Experiment Rule is the first rule that those users match.

Read more about [Experiment Rules](/features/rules#experiments) in our documentation.

### Ensure GA4 is properly configured as the Data Source in GrowthBook

Double-check that our [GA4 Setup Guide](/guide/GA4-google-analytics) was followed exactly.

Make sure the BigQuery service account used by GrowthBook has the necessary permissions on your BigQuery project (at least BigQuery Data Viewer, Metadata Viewer, and Job User). This allows GrowthBook to read the data in GA4.

Test the Experiment Assignment Query as outlined in the [Experiment Assignment Query (EAQ) issues](#experiment-assignment-query-eaq-issues) section above.

### Ensure the experiment is properly scoped

#### Environments

The environment(s) allowed for the experiment must match the environment(s) allowed for the SDK.

#### Projects

The project(s) allowed for the experiment must match the project(s) allowed for the SDK.

The project(s) allowed for the experiment must also match the project(s) allowed for the Data Source.

## GA4 troubleshooting if **not** using Google Tag Manager (GTM)

If you **are** using GTM with GA4 and GrowthBook, please review our [Google Tag Manager Setup Guide](/guide/google-tag-manager-and-growthbook) and accompanying [Google Tag Manager (GTM) Troubleshooting Guide](/kb/google-analytics/google-tag-manager-gtm-troubleshooting) for this section instead.

### Why are there no `experiment_viewed` events showing in GA4?

#### Possible Answer #1: GA4 is not loaded or `window.gtag` is unavailable

If GA4 is not properly loaded on the page the `window.gtag` function will not exist, and any attempt to send events to it will silently fail.

You can check this by opening your browser's developer console and typing `window.gtag`. If the response is `undefined`, you'll need to make some changes to where or how GA4 is loaded in your application to ensure it's available before GrowthBook tries to send events to it.

#### Possible Answer #2: No users are being bucketed into the experiment

If the GrowthBook SDK is not assigning users to variations (for example, due to missing or incorrect user attributes), the `trackingCallback` will not fire, and no events will be sent.

### Why are there fewer `experiment_viewed` events showing in GA4 than I expect?

#### Possible Answer #1: Experiment assignment issues

If users are not being assigned to the experiment due to targeting rules, missing attributes, or other logic the `trackingCallback` will not fire, and no events will be sent.

#### Possible Answer #2: Conversion windows and data sync

GrowthBook may exclude some conversions if they fall outside the metric conversion window, or there may be delays or issues with data synchronization between GA4 and GrowthBook.

If you have checked your implementation and still see fewer events, we recommended logging the execution of the `trackingCallback` and verifying that `window.gtag` is indeed available and being called as expected. Also, check for any consent or ad blocker issues that might prevent events from reaching GA4.

## Use GA4's built-in debugging tools

Check the Real-Time reports in GA4 for event validation.

## Use GrowthBook's Developer Tools extension to debug GA4 issues

GrowthBook's [DevTools Browser Extension](/tools/chrome-extension) (available for [Chrome](https://chromewebstore.google.com/detail/growthbook-devtools/opemhndcehfgipokneipaafbglcecjia) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/growthbook-devtools/)) is very helpful for debugging issues with GA4 by:

* Inspecting whether the GrowthBook SDK is properly loaded on the web site
* Checking which feature flags and experiments are active
* Verifying that user attributes are set as expected

The extension allows you to see real-time information about feature flags and experiments, which helps to confirm if the SDK is initialized correctly and if experiments are being evaluated as intended. This is especially useful when troubleshooting why experiment exposure events (like `experiment_viewed`) might not be appearing in GA4.

### Initial debugging steps

* Check if the SDK is detected (look for a green dot on the extension icon).
* Inspect which experiments and feature flags are active and their current values.
* Verify that user attributes (such as IDs used for bucketing) are set correctly.
* If you’re not seeing expected experiments or flags, this may indicate issues with SDK initialization, attribute configuration, or experiment targeting, which could explain missing events in GA4.

## Use your browser's Developer Tools Console to debug GTM/GA4 issues

If you've confirmed that the `trackingCallback` is implemented and firing, GA4 is loaded, and you are still not seeing `experiment_viewed` events, we recommend:

* Check for JavaScript errors in the browser's Console that are related to your feature flags.
* Add logging statements throughout the GrowthBook-related code in your application, particularly in and around the SDK's `trackingCallback`, then check in your browser's Developer Tools Console to further debug the issue.
* Monitor the `dataLayer` object in the browser console by typing in `dataLayer` and pressing Enter. Verify the feature flag names match what is shown in the GrowthBook dashboard.
