> ## 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.

# A/B Testing with Google Analytics 4 (GA4) and GrowthBook

> This guide walks you through using GrowthBook with Google Analytics 4 (GA4) to track your experiments and measure their impact on your business.

This guide walks you through using GrowthBook with Google Analytics 4 (GA4) for A/B testing. There are a few parts to
this, connecting GA4 to BigQuery, connecting GrowthBook to BigQuery, and then configuring GrowthBook to track correctly
with GA4.

For help debugging GA4 integration issues, please review our [GA4 Troubleshooting Guide](/kb/google-analytics/google-analytics-ga4-troubleshooting).

You can watch a video version of this guide, largely focused on Google Optimize replacement, here:

<Frame>
  <iframe style={{width: "100%", height: "auto", aspectRatio: 16/9}} src="https://www.youtube.com/embed/w8MBaBqcVZI?si=ZwioZRXQ7ftPY6hp" title="GA4 and GrowthBook" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowFullScreen />
</Frame>

## Configuring GrowthBook to use Google Analytics GA4 as a data source

GrowthBook connects to Google Analytics (GA4) via BigQuery. This process is straight forward, and outlined below.
You can also find Google's documentation on how to create this link [here](https://support.google.com/analytics/answer/9823238).

### 1. Create a BigQuery Project (if you don't have one)

If you don't have a BigQuery project, you'll need to create one. Go to your [Google Cloud Console](https://console.cloud.google.com/) and create a new project:

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-1-project-list.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=4959e4a56796a55e4053b2e0bce6c1ec" alt="GA4 - BigQuery create project" width="800" data-path="static/images/guides/GA4-1-project-list.png" />
</Frame>

Click on ***Create new project*** from the right and give your project a name.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-2-create-project.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=a0e61467377057a5e60f01098840170e" alt="GA4 - BigQuery create and name your project" width="500" data-path="static/images/guides/GA4-2-create-project.png" />
</Frame>

Once created, you'll be redirected to the BigQuery dashboard.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-3-new-project.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=5991788f2342c00d6830c4e76e5ca0a3" alt="GA4 - BigQuery new project dashboard" width="800" data-path="static/images/guides/GA4-3-new-project.png" />
</Frame>

If you created a new project, the BigQuery API is automatically enabled. Otherwise, you'll need to [enable it manually](https://console.cloud.google.com/flows/enableapi?apiid=bigquery)

<Note>
  **Using the BigQuery sandbox project**

  If you are just testing GrowthBook with GA4 out, you can use the sandbox project that Google provides for free. When you create a new cloud project the sandbox should be automatically enabled. You can find more information about the sandbox [here](https://cloud.google.com/bigquery/docs/sandbox).
</Note>

### 2. Connect Google Analytics to BigQuery

Log into your Google Analytics account and navigate to the Admin section. From there, make sure you have selected the right property, and scroll down to ***Product Links*** section. Click on the menu named ***BigQuery Links***

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-4-link-to-bigquery-1.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=a6fd9194dd08aba89aff4a8c4f56e6ca" alt="GA4 BigQuery new project dashboard" width="800" data-path="static/images/guides/GA4-4-link-to-bigquery-1.png" />
</Frame>

Click on the ***Link*** button. This will open a menu that allows you select the project. Select on the ***Choose a BigQuery Project*** link.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-2.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=7506a62fa55440ac8c28acc7f58656d0" alt="GA4 BigQuery, choose a project" width="800" data-path="static/images/guides/GA4-5-link-to-bigquery-2.png" />
</Frame>

Select the project you wish to send your GA4 data to:

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-3.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=7ddc017d00dacfe4594059a6a778d65c" alt="GA4 BigQuery connect to project" width="800" data-path="static/images/guides/GA4-5-link-to-bigquery-3.png" />
</Frame>

Then click **Next**.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-4.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=0e0757690703f02dcaed0291f18039fc" alt="GA4 BigQuery connected to project" width="2164" height="1200" data-path="static/images/guides/GA4-5-link-to-bigquery-4.png" />
</Frame>

On the next step you'll be presented with some options about the connection.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-5.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=f5a3d6e36a4f98235b746981604448ad" alt="GA4 BigQuery link options" width="2164" height="1670" data-path="static/images/guides/GA4-5-link-to-bigquery-5.png" />
</Frame>

Here you can choose the frequency of data updates, either daily or streaming. To use Streaming, you'll need a BigQuery account with billing info added. Depending on your use case, daily updates may be sufficient.

On the final step you'll be asked to confirm your choices. When finished, you should see something like this, verifying that the connection was successful.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-6.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=7935d7032d2f416c34224b09d4027380" alt="GA4 BigQuery link created" width="1862" height="376" data-path="static/images/guides/GA4-5-link-to-bigquery-6.png" />
</Frame>

And then your BigQuery link will show up on the listing page:

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-5-link-to-bigquery-7.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=a3375d01bfd19a138ab91ae696b9acb8" alt="GA4 BigQuery successfully connected" width="1000" data-path="static/images/guides/GA4-5-link-to-bigquery-7.png" />
</Frame>

<Note>
  **Loading Google Analytics via Google Tag Manager (GTM)**

  If you are loading Google Analytics via Google Tag Manager (GTM), you may need to add the custom event to GTM to ensure
  the data is passed to GA4 from the datalayer. You can add the custom event by following this [section from the GTM guide](/guide/google-tag-manager-and-growthbook#4-tracking-via-datalayer-and-gtm). Our [Google Tag Manager (GTM) Troubleshooting Guide](/kb/google-analytics/google-tag-manager-gtm-troubleshooting) may be helpful for debugging if needed.
</Note>

### 3. Configure BigQuery for GrowthBook

You'll need to give GrowthBook permissions to your BigQuery project so that we can access the data. We have created a guide just for this, which you can find [here](/guide/bigquery)

### 4. Connect GrowthBook to BigQuery

Within GrowthBook, navigate to the ***Analysis*** section, and then click on the ***Data Sources*** page. Add a new data source, and select ***Google Analytics (GA4)***.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-6-add-GA4-datasource.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=16239ce543b74d42325cfd340f0eb7ae" alt="GA4 GrowthBook connect to GA4" width="500" data-path="static/images/guides/GA4-6-add-GA4-datasource.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/1rsmujQCDzXz2Vho/static/images/guides/GA4-6-add-GA4-datasource2.png?fit=max&auto=format&n=1rsmujQCDzXz2Vho&q=85&s=e0f733e8c95f614c09d4c78f620a3e99" alt="GA4 GrowthBook connect to GA4" width="500" data-path="static/images/guides/GA4-6-add-GA4-datasource2.png" />
</Frame>

Then add your BigQuery connection info. GrowthBook will pre-populate the SQL queries required to use your GA4 data. You
can also add a custom SQL query if you want to use a different table or filter the data in some way as you like.

<Note>
  **Automatic SQL query creation**

  While GrowthBook will pre-populate the SQL queries for you, you may need to adjust the experiment query to match your
  data depending on the way you are tracking your experiments (see the ***trackingCallback*** below).
</Note>

Once connected, you can add any additional metrics or dimensions, and then you can use your GA4 data for your
experiments. You can use all your existing events and tracking- GrowthBook only requires one additional tracking call
when a user is exposed to an experiment.

## Running experiments with GrowthBook and GA4

With the data source connected, you can integrate the GrowthBook SDK into your application to run A/B tests. Once implemented, the SDK will do the random assignments and send the experiment exposure event to GA4 based on the settings in the GrowthBook UI.

<Info>
  **Visual editor for creating experiments**

  We do have a visual editor for creating experiments as part of our Pro plan. Our visual editor is meant for simple
  experiments. Experiments that are more complex are best created by writing code with feature flags.
</Info>

### SDK integration for GA4

The easiest and recommended way to integrate GrowthBook is by using our [Script Tag SDK](/lib/script-tag). This SDK will work out-of-the-box with GA4 without any configuration required.

<Note>
  **Debugging GA4 integrations**

  If your experiment is not firing the `trackingCallback` you can use our
  [Chrome developer tool](https://chrome.google.com/webstore/detail/growthbook-devtools/opemhndcehfgipokneipaafbglcecjia)
  to help you debug and make sure the user attributes are being set correctly.
</Note>

Implementing the experiment variations can be done with code with inline experiments, using the feature flags, or by
using our visual editor.

## Troubleshooting

Please see our our [GA4 Troubleshooting Guide](/kb/google-analytics/google-analytics-ga4-troubleshooting) for help debugging GA4 integrations with GrowthBook. If relevant, see our [GTM Setup Guide](/guide/google-tag-manager-and-growthbook) and our [Google Tag Manager (GTM) Troubleshooting Guide](/kb/google-analytics/google-tag-manager-gtm-troubleshooting).
