# Install CrispStats with Google Tag Manager

Updated 2026-11-23

To install CrispStats with Google Tag Manager, create a Custom HTML tag with the snippet from your site settings and fire it on the All Pages trigger. The snippet adds the script to the head with your options set, so it behaves exactly like a tag pasted into your HTML, and single-page navigation needs no extra trigger.

## Steps

### 1. Copy the Google Tag Manager snippet

In the dashboard, open your site's **Settings**, select **Tracking code** and choose the **Google Tag Manager** tab. It has your public key and domain filled in.

```html
<script>
  (function () {
    var s = document.createElement("script");
    s.defer = true;
    s.setAttribute("data-site", "cs_pk_your_site_key");
    s.setAttribute("data-domains", "example.com");
    s.src = "https://in.crispstats.com/d.js";
    document.head.appendChild(s);
  })();
</script>
```

### 2. Create a Custom HTML tag

In your container, open **Tags**, select **New**, then **Tag Configuration** and choose **Custom HTML**, as [Google's help page on custom tags](https://support.google.com/tagmanager/answer/6107167) describes. Paste the snippet into the HTML field. The snippet does not call `document.write`, so leave **Support document.write** off.

### 3. Fire it on All Pages

Set the trigger to **All Pages**. You need only this one trigger: the script follows single-page navigation by itself through the History API. Do not add a history change trigger as well, which would append a second script element that does nothing.

### 4. Publish the container

Submit and publish the container version, then open your live site in a normal browser window. Visits from `localhost` and `file://` are ignored, so preview mode on a local copy of the site does not count.

### 5. Add optional modules

The switches under **Extra events** on the **Tracking code** tab add one `setAttribute` line per module, each with an empty value. This is the snippet with outbound links, downloads, web vitals and errors on. Set every attribute before `appendChild`, because the script reads them once when it starts, and use `setAttribute`, not properties such as `s.site`.

```html
<script>
  (function () {
    var s = document.createElement("script");
    s.defer = true;
    s.setAttribute("data-site", "cs_pk_your_site_key");
    s.setAttribute("data-domains", "example.com");
    s.setAttribute("data-outbound", "");
    s.setAttribute("data-downloads", "");
    s.setAttribute("data-vitals", "");
    s.setAttribute("data-errors", "");
    s.src = "https://in.crispstats.com/d.js";
    document.head.appendChild(s);
  })();
</script>
```

### 6. Send custom events from existing triggers (optional)

For a click you already have a trigger for, add a second Custom HTML tag that fires on it. A call made before the script has loaded is lost unless the queue stub from the docs runs first.

```html
<!-- Tag type: Custom HTML. Trigger: your click trigger. -->
<script>
  if (window.crispstats) window.crispstats("signup click", { place: "header" });
</script>
```

## Check that it works

Open your live site with the developer tools on the **Network** tab: `d.js` loads from `in.crispstats.com` and a `POST` to `/e` answers `202`. In the **Elements** panel, the `d.js` script element in `<head>` should carry `data-site` and your other attributes; if they are missing, the tag set them after `appendChild` or as properties. The dashboard then shows **Receiving events.** and the visit appears on **Realtime**.

## What you get

- The same reports as a tag in your HTML: pageviews, visitors, sources, channels, countries, devices and browsers.
- Single-page navigation counted from the History API, with the same URL twice in a row counted once.
- Visits from AI assistants such as ChatGPT and Perplexity in their own channel.
- Custom events from any GTM trigger you already maintain, or from `data-cs-event` attributes in your page HTML with no tag at all.
- A core script of about 2.2 KB gzipped, with no cookie set by default.

## Notes for Google Tag Manager

- The script reads its options from `document.currentScript`. An element created with `document.createElement` and appended to the page is a classic script, so that still points at it while it runs.
- If the CrispStats tag is also in your page HTML, the copy that runs second does nothing, so a visit is not counted twice. Keep one of the two anyway.
- GTM fires the tag according to the triggers and consent settings you give it. If the tag waits for consent, visitors who decline are not counted. This is not legal advice.
- This tag can only run where your Tag Manager container loads. A [first-party proxy](/docs/tracking/proxy) moves the script and events to your own domain, but the container itself still comes from Google.
- To load the script through a proxy, such as a [Cloudflare Worker](/integrations/cloudflare), set `s.src` to your path's `d.js` and add `s.setAttribute("data-api", "/k3x9qe");` with your own path.

Full reference: [Google Tag Manager in the docs](https://docs.crispstats.com/install/google-tag-manager)

## Frequently asked questions

### Which trigger should the analytics tag use in Google Tag Manager?

All Pages, and nothing else. The script tracks single-page navigation by itself, so a history change trigger would only add a second script element that does nothing.

### Does a consent setting in Tag Manager block it?

It can. Tag Manager fires the tag according to your consent settings. CrispStats sets no cookie by default, so whether to wait for consent is your decision; this is not legal advice.

### Can I use the Tag Manager tag and a script tag in the HTML?

Use one. If both run, the copy that runs second does nothing, so a visit is still counted once, but it is a wasted request.

### Does loading it through Tag Manager change the price?

No. The tag sends the same events a script in your HTML would, and plans are sized by events, not by how the script is loaded. Every account starts with a 14-day free trial with every feature and no card; then Starter is $5 a month for 250,000 events.

## Related

- [Consent mode explained](/glossary/consent-mode)
- [Do you need a cookie banner for analytics?](/blog/do-you-need-a-cookie-banner-for-analytics)
- [CrispStats vs Google Analytics](/vs/google-analytics)
- [Funnels and goals](/features/funnels)
- [Install with a plain script tag](/integrations/html)
