# Connect story tracking to Google Tag Manager

Source: https://knowledge.intractive.app/en/articles/meta-story-events-with-google-tag-manager

Google Tag Manager lets you send what happens inside a story (how far someone got, what they answered, whether they clicked through) to Meta, Google Analytics or any other tool. You add the container to your project once, and after that you change what gets sent where in Tag Manager, without changing anything in Intractive.

## What you need first

- A Google Tag Manager container. Data only appears somewhere once a destination such as Google Analytics 4 or a Meta Pixel is set up inside it.
- The admin role in the project.

## Add your Tag Manager ID

The Tag Manager ID is set per project, so every project can point at its own container. All stories in that project use it. The natural model is one client, one project, one container: the client's own Tag Manager, Analytics and pixel, so the data stays theirs. You never proxy anyone else's tracking.

1. In Google Tag Manager, 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 your project and go to **Project settings**.
4. Scroll to the **Tracking & scripts** section.\
   \[screenshot: Project settings with the Tracking & scripts section and the Tools list\]
5. In the **Tools** section of **Tracking & scripts**, click **Add** next to **Google Tag Manager**.
6. Paste your container ID.
7. Click **Save** at the bottom of the **Tools** section.\
   \[screenshot: the Tools section with a Google Tag Manager ID filled in and the Save button\]

The container now loads on every public-facing page of the project. That's the only step in Intractive. Everything else, such as which tags fire, which triggers they use and your consent rules, stays in Tag Manager.

### Remove the container

1. In **Project settings** > **Tracking & scripts**, go to the **Tools** section and click **Edit** next to **Google Tag Manager**.
2. Click **Remove**.
3. Click **Save**.

The container stops loading on the next page render.

## How Tag Manager fits in

UTM tracking tells the destination page where a visitor came from. It says nothing about what happened inside your story. Tag Manager covers that. This article doesn't assume a technical background.

Tag Manager has no reports. You'll never open it to find out how many people finished a story. Its only job is to sit on the story page, watch what happens, and forward that information to the tools that do have reports.

| Tool | ID looks like | What it is |
| --- | --- | --- |
| Google Tag Manager | `GTM-XXXXXXX` | The van. It runs on the story page and decides what gets sent where. It stores nothing and reports nothing. |
| Google Analytics 4 | `G-XXXXXXXXXX` | An address. It stores the data and gives you reports, funnels and audiences. |
| Meta Pixel | `1234567890123456` | Another address. It powers retargeting and campaign optimisation. |

The container and the story events also run on builder previews and for signed-in editors, unlike the tags a superadmin adds directly. A Tag Manager ID on its own does nothing visible. It needs at least one destination before any data appears anywhere.

With Tag Manager in your project, you add Analytics, Meta, LinkedIn, Hotjar or anything else inside Tag Manager afterwards. Any tag you set up there loads on every public-facing page of the project. Adding or removing a tag needs no change in Intractive and no new release.

Without Tag Manager, a superadmin can add a Google Analytics 4 measurement ID, a Meta Pixel ID or a LinkedIn partner ID to the project directly. Ask your Customer Success Manager for that. See Meta: adding a Meta Pixel without Tag Manager for what those tags send.

## Events a story sends

Once a container is running, the story pushes events into the data layer (`window.dataLayer`), a small message queue that Tag Manager listens to. There are four events, and everything you build in Tag Manager is made from these.

| Event name | Information included | When it fires |
| --- | --- | --- |
| `intractiveStoryProgress` | `storyId`, `sessionId`, `progress`, `depth`, `total` | When the story loads, and again whenever the visitor's progress changes, typically each time they finish a content block |
| `intractiveStoryMilestone` | `storyId`, `sessionId`, `milestone`, `progress`, `completed`, `total`, `depth` | When the visitor passes 0, 25%, 50%, 75% and 100%, at most once each per playthrough |
| `intractiveVariablesUpdated` | `variables` | Whenever a story variable changes value. This is how answers and choices reach your analytics. |
| `intractiveOutboundLink` | `storyId`, `sessionId`, `url` | When the visitor follows a link out of the story: a redirect block, an inline link in text or a button URL |

`storyId` is the story's internal ID. `sessionId` is the ID of one playthrough, unique per visit. In `intractiveOutboundLink`, `url` is where the visitor is being sent, including the UTM parameters Intractive adds.

### Measure how far people got

Use `intractiveStoryMilestone` for started, completed and everything in between. Its values only move forward. They survive a visitor leaving and resuming the story, or switching its language. A playthrough sends at most five of these events, so there's nothing to de-duplicate.

- `milestone` is the mark the visitor has passed: `0`, `25`, `50`, `75` or `100`. Use it as your dimension for funnels and completion rate.
- `milestone: 0` fires as the visitor opens the story, before they've answered anything. It's your started signal and the base of your funnel: every later milestone is a share of the visitors who reached this one.
- `milestone: 100` is your completed signal. It fires only once the story is complete. Reaching the last block isn't enough, but a story that ends by redirecting the visitor away counts as complete when they reach that block.
- `progress` is the furthest percentage reached, from 0 to 100, and never lower than in an earlier push. It stays `0` until the visitor answers their first block.
- `completed` is the number of blocks the visitor had answered at that furthest point.
- `total` is the story's potential length at that point: the blocks in it plus the longest branch each remaining block could still open. It falls when the visitor declines a branch or takes a shorter one, so `completed` divided by `total` shows how far through their own story they are.
- `depth` is the furthest block position reached, counting from 1.

A restarted playthrough is a new session and reports its milestones again from the start. A playthrough that's resumed on a later visit reports no `0` and none of the marks it had already passed. It reports only the milestones it crosses from then on.

### Read progress as a live position

`intractiveStoryProgress` describes where the visitor is right now, and its values can move backwards.

- `depth` is the content block the visitor is on, counting from 1. The first message always has `depth: 1`.
- `total` is the number of content blocks currently in scope for this playthrough. It grows when the visitor opens a branch, and shrinks when a block hides itself or a block that completes the story cuts off the rest.
- `progress` is the percentage of blocks completed, from 0 to 100, rounded to a whole number. Because `total` changes, `progress` can fall from one push to the next.

In a menu-style story, where visitors pick a topic and come back to a hub, `progress` says little, so measure something other than progress. See Meta Pixel and campaign tracking strategies for how to pick events that match your story's shape.

### Capture answers and choices

The four events are fixed. `intractiveVariablesUpdated` carries whatever is in your story variables, so you decide what ends up in your analytics. Its `variables` field holds every variable currently in scope with its current value, and the full set is sent again on each change.

If a story has no variables, this event never fires and you'll see progress and outbound clicks only. To know which option someone picked, the story has to write that choice into a variable.

- Use one variable per meaningful decision, not one per interaction. Think of role, intent, timeline and region: the things that separate a serious visitor from a curious one.
- Use short fixed values, not free text. `timeline: 0-3m` works as a filter; a typed sentence doesn't.
- Set the variable at the moment of the tap, not at the end of the story, so the signal still arrives if someone leaves early.
- Use the same names across a client's stories, so you can compare them and build one audience across all of them.

> [!WARNING]
> Never put personal data in a variable that flows into analytics. Names, email addresses and phone numbers must not be sent to Google Analytics: it's against Google's own terms and it creates a privacy problem. When you send variables onward, list the ones you want by name rather than passing everything at once.

## Use the events in Tag Manager

1. In Google Tag Manager, create a **Custom Event** trigger.
2. Set its event name to `intractiveStoryProgress`, `intractiveStoryMilestone`, `intractiveVariablesUpdated` or `intractiveOutboundLink`.
3. Create a **Data Layer Variable** for each field you need, using the field name, such as `storyId`, `milestone` or `progress`. For a story variable, use `variables.@` followed by its name, for example `variables.@timeline`.
4. Use the trigger and the variables in your tags, such as your Meta Pixel or Google Analytics 4 tag.\
   \[screenshot: a Tag Manager Custom Event trigger set to intractiveStoryMilestone\]

## One page view per story

A story is a single page that changes as the visitor moves through it. The web address doesn't change from block to block, so analytics tools record exactly one page view for an entire story.

Every report you build has to be based on events, not pages. Don't expect a useful "most viewed pages" report, and don't build funnels on page paths.

## Stories embedded on your own website

When a story runs inside an iframe on your own site, your Tag Manager container is on the parent page and can't see inside the frame. The story also posts each event to the surrounding page, so your existing container can pick it up. Each message has the type `intractive.dataLayer`, and its payload is the same object the story pushes to its own data layer.

These messages are sent only when the story runs inside an iframe. When it's opened in its own window, only the data layer push happens.

An embedded story runs on your project's address, which is a custom domain or an [intractive.app](http://intractive.app/) address, not on your website. Your website's cookie banner doesn't reach it, and you can't pass consent into the story.

### Code for the parent page

Give this to your developer to add to the page that embeds the story. It listens for the story's events and puts them into the page's own data layer, where your existing Tag Manager setup treats them like any other event.

```javascript
<script>
window.addEventListener('message', function (e) {
  if (e.origin !== 'https://web.intractive.app') return;
  var m = e.data;
  if (!m || m.type !== 'intractive.dataLayer' || !m.payload) return;
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push(m.payload);
});
</script>
```

Keep the origin check on the third line, and replace `https://web.intractive.app` there with the origin of the story you embedded. The origin is your project's custom domain, otherwise its subdomain, otherwise `https://web.intractive.app`. Without the check, the page would accept messages from any embedded frame, which is a security risk. It is the address of the Intractive page inside the iframe, for example `https://your-subdomain.intractive.app`. Check that it matches the address you embedded.

The story sends messages only to the embedding page's own origin, which it 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.

## Header code and footer code

The **Tracking & scripts** section also has **Header code** and **Footer code**. These put code into the published story page directly. You can't fill them in yourself: your Customer Success Manager sets them for you. They aren't self-service because the code goes into your live page as it is, and a bad tag can break the story for every visitor. Your Customer Success Manager also checks whether the tool has a Tag Manager route, and talks with you briefly about privacy and consent.

Use them only for tools that can't run through Tag Manager. A consent banner is the usual example, because it has to load before Tag Manager does.

- **Header code** loads at the end of the page head, before the Tag Manager container. Use them to pre-seed the data layer (consent defaults, user attributes) or for a tool that must start before tags fire.
- **Footer code** loads at the end of the page body, after the story has rendered. Use them for tags that should run last, late-loading analytics or widgets that appear after the page renders.

Both accept only `<script>` and `<noscript>` tags, and apply to every story, QR code and custom domain in the project.

For everything else, Tag Manager is the better place: it's easier to change and test, and you can switch a tag off without changing Intractive.

## Privacy and consent

Anything you load through Tag Manager, **Header code** or **Footer code** 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 Tag Manager, or discuss it with your Customer Success Manager for the header and footer code. The container always loads and the story events are always pushed, so consent requirements are set in Tag Manager or in a consent tool loaded through **Header code**.

If your project uses strict privacy mode, Intractive's own analytics use session storage only. That setting doesn't apply to tags you load through Tag Manager or the header and footer code: they behave the way you've set them up.

## Next

- Meta Pixel and campaign tracking strategies
- Meta: adding a Meta Pixel without Tag Manager
- UTM tracking
