# Connect story tracking to Google Tag Manager and Google Analytics

Source: https://knowledge.intractive.app/en/articles/google-tag-manager

Google Tag Manager (GTM) loads your analytics and marketing tags on your project, and lets you send story events to Google Analytics 4 (GA4). You add one container ID in Intractive and set up everything else in GTM.

## What you need first

- A Google Tag Manager container for this project.
- The admin role in the project or its organisation.
- A published story, to test your setup.

## How Google Tag Manager works

Google Tag Manager is a free tool for adding and managing scripts ("tags") on your website from one dashboard, without editing the site's code each time. You install GTM once. After that, you add, change and remove tags in GTM instead of asking a developer.

GTM works with tags, triggers and variables.

- Tags: the snippets that run, such as an analytics pixel, a tracking script or an embed.
- Triggers: when a tag fires, for example on every page or only on `/story/*`.
- Variables: the values a tag or trigger reads, such as the page URL, a click or a `dataLayer` value.

## Add Google Tag Manager to your project

1. In [Google Tag Manager](https://tagmanager.google.com/), open the container for this project.
2. Copy the container ID from the top of the workspace. It looks like `GTM-XXXXXXX`.
3. In Intractive, open the project and go to **Project settings** > **Tracking & scripts**.
4. Click **Add** next to **Google Tag Manager**. It shows where to find the ID.

   \[screenshot: Tracking & scripts after clicking Add, Google Tag Manager ID field empty\]
5. Paste the container ID.

   ![](https://storage.googleapis.com/intractive-knowledge-media/1a78c383ff0f817005bba01b3df4b1775418bc46fb85d7f2235a7eca10ff7f71.png)
6. Click **Save** at the bottom of the **Tools** section.

These are the only steps in Intractive. Everything else, such as which tags fire, their triggers and consent rules, stays in GTM.

Tag Manager now loads on every public page of the project and on its stories. Any tag you set up in the container (GA4, Meta Pixel, LinkedIn Insight, Hotjar or custom HTML) loads there too. When you add or remove a tag in GTM, you don't need to change anything in Intractive. To check that it works, look in Tag Manager itself for incoming visits. The **Google Tag Manager** setting also lists the events your tags can use.

### Remove Google Tag Manager

1. In **Project settings** > **Tracking & scripts**, click **Edit**.
2. Click **Remove**.
3. Click **Save**.

The container stops loading the next time a page loads.

## Story events you can use in GTM

While a story plays, Intractive pushes events onto `window.dataLayer`. In GTM you pick them up with triggers and forward them to GA4 as events. You set this up in GTM, without writing code.

GTM doesn't list Intractive's events in a dropdown. Type the event name in a **Custom Event** trigger and the field name in a **Data Layer Variable**. Intractive pushes the events on every visit, previews included, published or not.

### intractiveStoryMilestone

Fires when the visitor passes 0, 25, 50, 75 and 100% of the story, at most once each per playthrough. Build completion rates on this event. Its values only move forward, also when the visitor leaves and resumes the story, or switches its language.

`0` fires when the visitor opens the story, before they answer anything. It's the base of your funnel: every later milestone is a share of the visitors who reached `0`.

A playthrough that's resumed on a later visit doesn't report `0`, or any milestone it passed before. It reports only the milestones it passes from then on.

| Field | Type | Description |
| --- | --- | --- |
| `event` | `string` | Always `"intractiveStoryMilestone"`. |
| `storyId` | `string` | Internal ID of the story. |
| `sessionId` | `string` | ID of this playthrough. A restarted playthrough is a new session and reports its milestones again from the start. |
| `milestone` | `number` | The milestone the visitor has passed: `0`, `25`, `50`, `75` or `100`. Use this as your dimension. |
| `progress` | `number` | Furthest percent reached (0 to 100), never lower than in a previous push. `0` until the visitor answers their first content block. `100` fires only once the story is complete, so reaching the last block isn't enough. A story that ends by redirecting the visitor away counts as complete when they reach that block. |
| `completed` | `number` | Content blocks the visitor had answered at that furthest point. This is the count behind `progress`. |
| `total` | `number` | The story's potential length at that point: its content blocks plus the longest branch each remaining block could still open. It holds when the visitor takes that branch, and drops when they decline it or take a shorter one. So `completed / total` shows how far the visitor is through their own version of the story. |
| `depth` | `number` | Furthest content block position reached, counted from 1. For context only: `progress` isn't based on it. |

### intractiveStoryProgress

Fires when the visitor's progress through the story changes, typically each time they finish a content block. Read it as the visitor's live position. These values can move backwards, so use `intractiveStoryMilestone` for funnels.

| Field | Type | Description |
| --- | --- | --- |
| `event` | `string` | Always `"intractiveStoryProgress"`. |
| `storyId` | `string` | Internal ID of the story. |
| `sessionId` | `string` | ID of this playthrough, unique per visit. |
| `progress` | `number` | Percent complete, rounded to a whole number (0 to 100). |
| `depth` | `number` | Position of the content block the visitor is on now, counted from 1. Always at least `1`. |
| `total` | `number` | Total number of content blocks currently in scope for this playthrough. This value can grow during the session if the visitor triggers a branch that activates more blocks. |

### intractiveVariablesUpdated

Fires whenever one of the story's variables changes value. Use it if you've set up scoring or branching variables and want them in your analytics.

| Field | Type | Description |
| --- | --- | --- |
| `event` | `string` | Always `"intractiveVariablesUpdated"`. |
| `variables` | `object` | A `{ [@variableName: string]: string }` map of every variable currently in scope and its current value. Each key is `@` followed by the variable name. Each change pushes the full map again. |

### intractiveOutboundLink

Fires when the visitor follows a link out of the story. Redirect blocks, inline links in text and button URLs all count.

| Field | Type | Description |
| --- | --- | --- |
| `event` | `string` | Always `"intractiveOutboundLink"`. |
| `storyId` | `string` | Internal ID of the story. |
| `sessionId` | `string` | Session ID. |
| `url` | `string` | The destination URL the visitor is sent to. UTM parameters that Intractive adds are already included. |

## Example: send an event when a visitor reaches the third content block

This example sends `intractiveStoryProgress` to GA4 as an event called `engaged_visitors` when a visitor reaches their third content block or further. You can optionally send how far the visitor got (`depth`) and which story it was (`storyId`) with the event. In GA4, the users who have this event are the visitors who saw three or more content blocks. Once you've done one event, the others follow the same pattern.

### Create the variable

GTM can't use a field until you've captured it as a variable.

1. In your GTM container, go to **Variables** > **User-Defined Variables** > **New** > **Variable Configuration** > **Data Layer Variable**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/e45b0278fec50c1dc4fa68c5b0ffdb27efc6349268b4bae06c38d1b2278f1836.png)
2. In **Data Layer Variable Name**, type `depth`, exactly as Intractive pushes it.
3. Name the variable `Story Depth`, so you can pick it in the trigger.
4. Optional: create a **Data Layer Variable** in the same way for each other field you want, such as `storyId`. To capture a variable you created in a story, type `variables.@` followed by its name, for example `variables.@score` for a variable called `score`. The names are on the story's **Variables** tab.

> [!TIP]
> **Note:** the **Data Layer Variable Name** must match the field name in the event tables character for character: `depth`, `storyId`, `sessionId`, `url`. A typo doesn't give an error. The value comes through empty, which is the usual reason a parameter shows up blank in GA4.

### Create the trigger

1. Go to **Triggers** > **New** > **Trigger Configuration**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/06099568434e792df1a67880d4d25c50e00eca7d0eade941c07354ac541f1f82.png)
2. Choose **Custom Event**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/e888eddbbd919cbc3df93ff3a5684d044be6862bc8392798048ea00a4b2820d0.png)
3. In **Event name**, type `intractiveStoryProgress` exactly. It's case-sensitive.
4. Select **Some Custom Events**.
5. Select `{{Story Depth}}`.
6. Set the condition to 3 or more, for example **greater than or equal to** `3`.

   ![](https://storage.googleapis.com/intractive-knowledge-media/54d771f7255dab3a0f618b705f2fbdc0bf643ed53f23a03cbc519100d493806b.png)

### Create the GA4 event tag

1. Go to **Tags** > **New** > **Tag Configuration** > **Google Analytics: GA4 Event**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/c25370f7fc1685e425ff67604566acc0b9c667a212021805c47f4649369246a0.png)
2. Set **Measurement ID** to your GA4 property, or select your existing GA4 Configuration tag if you have one. [Find your GA4 measurement ID](#find-your-ga4-measurement-id) has the steps.
3. In **Event Name**, type `engaged_visitors`. This is the name you'll see in GA4.
4. Optional: to send `depth` and `storyId` with the event, add each as an event parameter on the tag, using the Data Layer Variables you created.
5. Under **Triggering**, choose the trigger you created.

   ![](https://storage.googleapis.com/intractive-knowledge-media/a109ba670c32c452378b8af9376db392dbc81633500b27d0bde8fd183bfbc820.png)
6. Click **Save**.

### Preview and publish

1. Open a published story in Intractive.
2. Click **Share** at the top right.
3. Select **Online**.
4. Click **Continue**.
5. Enter a **Campaign name**, which every share entry needs.

   \[screenshot: the Share window of a published story with the Online option selected\]
6. Copy the story URL.
7. In GTM, click **Preview** at the top right.
8. Enter the story URL.
9. Play through the story.

   ![](https://storage.googleapis.com/intractive-knowledge-media/47c3b2e1c0f3dd541a8fa14a4922034c34abed7355fca86a6822fd0704f39d99.png)

   ![](https://storage.googleapis.com/intractive-knowledge-media/99f0ed14093c2b2115ee5be5c9ee7d6b88814d4e66b867d01460e98a811ad03d.png)
10. In the **Tag Assistant** debug panel, check that `intractiveStoryProgress` fires each time you finish a content block, that your tag fires from the third content block on, and that `depth` climbs 1, 2, 3. If a parameter is empty, check the variable name.
11. Back in the container, click **Submit**.
12. Name the version, for example "Add Intractive engaged\_visitors tracking".
13. Click **Publish**.

Events now go to GA4. They show in its realtime report within a minute or two.

\[screenshot: GA4 realtime report listing the engaged\_visitors event\]

## Example: track links out of your story

1. Go to **Variables** > **User-Defined Variables** > **New** > **Variable Configuration** > **Data Layer Variable**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/2146b23909b7bb1f90018f7a1c8782a122794abf871fcd7658779e2178eaff90.png)
2. In **Data Layer Variable Name**, type `url`. It holds the link the visitor followed, with any UTM parameters already added.
3. Name the variable `Page url outbound link`.
4. Go to **Triggers** > **New** > **Trigger Configuration**.
5. Choose **Custom Event**.
6. In **Event name**, type `intractiveOutboundLink` exactly.

   ![](https://storage.googleapis.com/intractive-knowledge-media/23b81e2f9ee187856da729e25f2ceaf6f87ec7bbc1956504eb7e03d1eaf537f6.png)
7. The event name alone identifies the event, so no condition is needed. Optional: to narrow the trigger, select `{{Page url outbound link}}` in the condition dropdown and set a condition, for example that the URL contains a domain.

   ![](https://storage.googleapis.com/intractive-knowledge-media/e1f52fa828d10f3929e9012afb5914d6ae92ac075f9a11eb1bfcd8571c8b4317.png)
8. Go to **Tags** > **New** > **Tag Configuration** > **Google Analytics: GA4 Event**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/c25370f7fc1685e425ff67604566acc0b9c667a212021805c47f4649369246a0.png)
9. Set **Measurement ID** in the same way as in the first example.
10. In **Event Name**, type the name you want to see in GA4.
11. Under **Triggering**, choose the trigger you created.

    ![](https://storage.googleapis.com/intractive-knowledge-media/965fb76d4607fd6aea24e7a9d3fd1c116066ca5fe7ed3a1263d596f5c2a557f3.png)
12. Click **Save**.
13. Click **Preview**.
14. Enter the URL of a published story.
15. Play through the story.

    ![](https://storage.googleapis.com/intractive-knowledge-media/47c3b2e1c0f3dd541a8fa14a4922034c34abed7355fca86a6822fd0704f39d99.png)

    ![](https://storage.googleapis.com/intractive-knowledge-media/99f0ed14093c2b2115ee5be5c9ee7d6b88814d4e66b867d01460e98a811ad03d.png)
16. In the **Tag Assistant** debug panel, check that `intractiveOutboundLink` fires when you follow a link.

    ![](https://storage.googleapis.com/intractive-knowledge-media/1938a00dac6071876bed20ce45d50c9aafa0a5ae30eae83e30430021a9787775.png)
17. Back in the container, click **Submit**.
18. Name the version, for example "Add Intractive outbound link tracking".
19. Click **Publish**.

## Example: send story variables to GA4

1. Go to **Variables** > **User-Defined Variables** > **New** > **Variable Configuration** > **Data Layer Variable**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/2146b23909b7bb1f90018f7a1c8782a122794abf871fcd7658779e2178eaff90.png)
2. In **Data Layer Variable Name**, type `variables.@` followed by the variable name, for example `variables.@score`. Story variables arrive in the `variables` field, and the names are on the story's **Variables** tab.
3. Go to **Triggers** > **New** > **Trigger Configuration**.
4. Choose **Custom Event**.
5. In **Event name**, type `intractiveVariablesUpdated` exactly.
6. The event name alone identifies the event, so no condition is needed. Optional: to narrow the trigger, search for your variable in the condition dropdown and select it.

   ![](https://storage.googleapis.com/intractive-knowledge-media/d896287d416c1f1d636156c3b7912af565bf990b4841c9da63b2ed5e4a379a4d.png)
7. Go to **Tags** > **New** > **Tag Configuration** > **Google Analytics: GA4 Event**.

   ![](https://storage.googleapis.com/intractive-knowledge-media/34216111cbd350fbee047427fa12caaeb42057dda2758ef723bc3ffba02f71d7.png)

   ![](https://storage.googleapis.com/intractive-knowledge-media/9fb7ce799f000a2e74d2ae7d39b4d1f0498067bdefe2600add4309671308e1d6.png)
8. Finish the tag in the same way as in the first example.
9. Preview the tag.
10. Publish the tag.

## Find your GA4 measurement ID

1. In Google Analytics, go to [**Admin**](https://analytics.google.com/analytics/web/provision/#/provision).
2. Under **Data collection and modification**, click **Data streams**.
3. Select the **Web** tab.
4. Click the web data stream.
5. Find the measurement ID in the first row of the stream details.

   ![](https://storage.googleapis.com/intractive-knowledge-media/00975e04be00676d687bacb4f605da94a7f9152dae669753f55cd7d01a176521.png)

## If your story is embedded on your website

When a story runs inside an iframe on your own site, Intractive also sends all four story events to the parent page with [`window.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). Your page can then react to story activity without reading the iframe's `dataLayer`.

Each message has a `type` and a `payload`.

```javascript
{
  type: "intractive.dataLayer",
  payload: { /* the same object that is pushed to dataLayer */ }
}
```

The message origin is the origin of the Intractive page inside the iframe, for example `https://your-subdomain.intractive.app`. Check it against the URL you embedded before you trust the payload.

This listener logs every event on the embedding page.

```javascript
window.addEventListener("message", (event) => {
  // Optional: restrict to the origin you embedded
  // if (event.origin !== "https://your-subdomain.intractive.app") return;
  if (event.data?.type !== "intractive.dataLayer") return;

  const { event: name, ...fields } = event.data.payload;
  // name is "intractiveStoryProgress" | "intractiveStoryMilestone"
  //         | "intractiveVariablesUpdated" | "intractiveOutboundLink"
  console.log(name, fields);
});
```

Intractive sends these messages only when the story runs inside an iframe. When the story opens in a top-level window, only the `dataLayer` push happens.

Messages go only to the embedding page's own origin, which the story reads from the referrer. If your page sends no referrer (`Referrer-Policy: no-referrer`, or a page opened from disk), no messages arrive. The default policy, `strict-origin-when-cross-origin`, is enough.

## Privacy and consent

Anything you load through GTM is your responsibility under GDPR, ePrivacy and similar rules. Intractive doesn't show a cookie banner for third-party tags on your behalf. You set that up in GTM.

If **Remember visitors** is set to **Strict** in **Project settings** > **Privacy & legal**, Intractive's own analytics use session storage only. Tags you load through GTM don't follow that setting. They behave the way you set them up.

## Other ways to add tracking

Without Tag Manager, an Intractive superadmin can add a GA4 measurement ID, a Meta Pixel ID or a LinkedIn partner ID to your project directly. For tools that can't load through GTM, header and footer scripts are available. For either, ask your Customer Success Manager.

## Next

- [UTM code](https://knowledge.intractive.app/en/articles/utm-code): how links out of a story are tagged for campaigns.
- [Story analytics](https://knowledge.intractive.app/en/articles/story-analytics): Intractive's built-in analytics, which work without GTM.
