Skip to content

Tag managers

Install CrispStats with Google Tag Manager

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.

Updated

Set up CrispStats on Google Tag Manager

  1. 01

    Step 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.

    Replace the highlighted values with your own.

    <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. 02

    Step 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 describes. Paste the snippet into the HTML field. The snippet does not call document.write, so leave Support document.write off.

  3. 03

    Step 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. 04

    Step 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. 05

    Step 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.

    <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. 06

    Step 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.

    <!-- 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 the install check shows once the first events land, on the demo site, Quillbook, on generated traffic.
  • 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 and limits

    • 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 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, set s.src to your path’s d.js and add s.setAttribute("data-api", "/k3x9qe"); with your own path.

The docs page covers the optional steps this guide leaves out.

Setup questions. Straight answers.

What people ask before they connect it.

  • 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.

  • 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.

  • 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.

  • 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.

Not answered here? Write to hello@crispstats.com

Go further

Related

Guides

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.