Skip to main content
To install CrispStats with Google Tag Manager, create a Custom HTML tag that fires on All Pages and paste the snippet from your site settings. The snippet creates the CrispStats script element, sets its attributes and appends it to <head>, so the script behaves exactly as if you had pasted the tag into your HTML.

Add the tag

1

Copy the GTM snippet

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

Create a Custom HTML tag

In your GTM container, create a new tag, choose Custom HTML as the tag type and paste the snippet into the HTML field.
3

Fire it on All Pages

Set the trigger to All Pages so the script loads on every page view. You only need one trigger: the script tracks single-page navigation by itself from the History API.
4

Publish the container

Submit and publish the container version, then open your live site. The status row on the Tracking code tab shows Receiving events. once the first event has been stored. Visits from localhost and file:// are ignored, so GTM preview mode on a local site does not count.

Add optional modules

The switches under Extra events on the Tracking code tab add one setAttribute line per module to the GTM snippet. Each attribute is set with an empty value, which turns the module on. With outbound links, downloads, web vitals and errors on, the snippet looks like this:
The same pattern works for any script attribute that takes a value, for example s.setAttribute("data-exclude", "/admin/*");.

Why the attributes still work

The script reads its options from document.currentScript, the <script> element that is running. A script element created with document.createElement and appended to the page is a classic script, so while it runs, document.currentScript points to that element and the script reads the data- attributes you set on it. Two details in the snippet matter:
  • Set the attributes before appendChild. The script reads them once when it starts.
  • Use setAttribute("data-…", …), not a property such as s.site. Only data- attributes are read.
The script also sends events to the origin it was loaded from, https://in.crispstats.com, unless you set data-api.
If the CrispStats tag is also in your page HTML, the copy that runs second does nothing, so the visit is not counted twice.

Check that it works

  • Open your live site with the browser’s developer tools on the Network tab. You should see d.js load from in.crispstats.com and a POST to https://in.crispstats.com/e that gets 202.
  • In the Elements panel, find the <script> element for d.js in <head> and check that it carries data-site and your other attributes. If they are missing, the tag sets them after appendChild, or with properties instead of setAttribute.
  • Open https://in.crispstats.com/check?k=cs_pk_xxxxxxxx with your key. "site": "known" means the key is right. The visit appears in Realtime within seconds.
Previewing your container on the live site loads the real script, so your test visits count unless you exclude your browser.

How page changes are counted

The script counts the first load and then every URL change made through the History API, so single-page navigation is tracked without any extra trigger. Do not fire the CrispStats tag on a history change trigger as well: it would add a second script element, and while that copy does nothing, it is a wasted request. The same URL twice in a row is one pageview.

Send custom events

Once the script has loaded, any tag can call the global. For a click you already have a GTM trigger for, add a second Custom HTML tag that fires on that trigger:
For clicks you can also put data-cs-event attributes in your page’s HTML, with no GTM tag at all. See declarative events. A call made before the script has loaded is lost unless the queue stub runs first.

FAQ

Use one. If both run, the copy that runs second does nothing, so the visit is still counted once.
Yes. Set up a proxy, then set s.src to your path’s d.js and add s.setAttribute("data-api", "/k3x9qe"); with your path.

Next steps

Script attributes

Every option you can set with setAttribute.

Track custom events

Send actions with crispstats() once the script is loaded.

Troubleshooting

What to check when no events arrive.
Last modified on November 23, 2026