> ## Documentation Index
> Fetch the complete documentation index at: https://www.pagent.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Tag Manager

> Load pagent through Google Tag Manager, and why pasting the snippet directly is better.

> [!WARNING]
>
> Google Tag Manager loads pagent after your page has started to show. Visitors may briefly see the original before the variant appears. If your platform has a head-code field, paste the snippet there instead: see the [other install guides](https://www.pagent.ai/docs/install.md).

Use Google Tag Manager only if you can't change your site's code at all.

## Copy your client key

In pagent, open the install step, or **Settings → Setup** later on, and copy your client key from the snippet: the value of `data-client-key`.

## Add pagent as a tag

**1. Create a tag**

In your container, go to **Tags → New → Tag Configuration** and choose **Custom HTML**.

**2. Paste the snippet**

Paste this code into the HTML field and replace `YOUR_CLIENT_KEY` with your client key:

```html theme={"dark"}
<script>
  (function () {
    var script = document.createElement("script");
    script.src = "https://cdn.pagent.ai/js/sdk.js";
    script.setAttribute("data-client-key", "YOUR_CLIENT_KEY");
    document.head.appendChild(script);
  })();
</script>
```

Use this instead of the plain snippet. Tag Manager can drop the snippet's `data-` settings, and pagent needs them to start.

**3. Fire it as early as possible**

Under **Triggering**, choose **Initialization - All Pages**. It fires before your other page view tags.

**4. Save and publish**

Save the tag, then click **Submit** and **Publish**.

> [!NOTE]
>
> If your container uses consent settings, the tag may only fire after a visitor accepts your cookie banner. See the [consent guide](https://www.pagent.ai/docs/guides/integration/consent.md) for how pagent handles consent.

## Check it worked

1. Open your site in a private browser window, so no cached version shows.
2. Back in pagent, click **Check connection** in the install step. If you've finished setup already, open **Settings → Setup**: it shows **You are ready** once pagent has received visits from your site.
3. pagent loads your live site and looks for the snippet. When it finds it, you can start your first test.

> [!TIP]
>
> pagent couldn't find the snippet? Make sure you published or saved the change on your live site, then check again. If you installed it through Google Tag Manager, open your site once in a normal browser window first.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.