# Google Tag Manager + GA4

URL: https://docs.ablyft.com/developers/integrations/google-tag-manager-ga4/

> Send the experiments and variations a visitor saw to Google Analytics 4 through Google Tag Manager.



With the Google Tag Manager (GTM) integration, ABlyft pushes an event to the data layer whenever a visitor sees an
experiment. You forward this event to Google Analytics 4 (GA4) and can analyze experiments beyond ABlyft's own goal
reporting.

## Step 1: Enable the integration in ABlyft

1. Open **Integrations** in the left menu.
2. Turn on the GTM integration.

From now on, each time a visitor sees an experiment, the data layer receives an event `ablyft-viewed-experiment` with
the project, experiment and variation (ID and name).

## Step 2: Create variables in GTM

Optionally create a separate workspace, for example `ABlyft > GA4 connection`. Create six **Data Layer Variables** (Data
Layer Version 2):

| GTM variable                     | Data layer variable |
| -------------------------------- | ------------------- |
| `dlv - ABlyft - project_id`      | `project_id`        |
| `dlv - ABlyft - project_name`    | `project_name`      |
| `dlv - ABlyft - experiment_id`   | `experiment_id`     |
| `dlv - ABlyft - experiment_name` | `experiment_name`   |
| `dlv - ABlyft - variation_id`    | `variation_id`      |
| `dlv - ABlyft - variation_name`  | `variation_name`    |

## Step 3: Create the trigger

* **Name:** `ABlyft GA4 trigger`
* **Type:** Custom event
* **Event name:** `ablyft-viewed-experiment`
* **Fires on:** All custom events

## Step 4: Create the GA4 tag

* **Name:** `ABlyft GA4`
* **Type:** GA4 event, with the measurement ID of your GA4 property
* **Event name:** `ablyft-viewed-experiment`
* **Event parameters:** map each of the six parameter names to its variable, for example `project_id` to
  `{{dlv - ABlyft - project_id}}`
* **Trigger:** `ABlyft GA4 trigger`

## Step 5: Check the setup

1. Publish the GTM changes.
2. In GA4, open **Reports → Real-time** and look at the event count by event name.
3. Open a page with a running experiment in a private window.
4. After a few minutes, `ablyft-viewed-experiment` should appear. Click it to see the parameters.

> Data can take up to 48 hours to appear in other GA4 reports.

Next: [analyze the experiments in GA4](https://docs.ablyft.com/developers/integrations/google-analytics-4-data/).

