Docs · Install

Install Statlark with Google Tag Manager

Load the tracker from a Custom HTML tag that fires once on every page.

Using an AI coding tool?Point it at this page as markdown: google-tag-manager.md

Where it goes

Tags → New → Tag Configuration → Custom HTML, with the Initialization - All Pages trigger.

Steps

  1. In Google Tag Manager, open your container. Go to Tags, then New.
  2. Click Tag Configuration and choose Custom HTML. Paste the code below, with your site ID from Settings → Install.
  3. Under Triggering, choose Initialization - All Pages, so the tag fires once on every page load. Don't add a History Change trigger: the tracker counts client-side page changes itself.
  4. Name and save the tag. Then click Submit, then Publish. Nothing goes live until you publish.

Custom HTML tag

<script>
  (function () {
    var s = document.createElement("script");
    s.src = "https://statlark.com/script.js";
    s.defer = true;
    s.setAttribute("data-website-id", "YOUR_SITE_ID");
    document.head.appendChild(s);
  })();
</script>

The tag sets a first-party analytics cookie as soon as it loads. Where the law asks for consent first, such as for visitors in the EU or UK, install the consent banner in its place: it loads the tracker only after the visitor accepts. Or switch on cookieless mode, which stores nothing on the device.

A GTM trigger doesn't ask anyone for consent. Where consent is needed, put the consent banner in your site's HTML instead of using this tag. For cookieless mode, add s.setAttribute("data-cookieless", "true"); to the tag.

Check it’s working

Before you publish, click Preview in your workspace and connect your site: Tag Assistant shows which tags fired, and the Statlark tag should be one of them. After you publish, open your live site. GTM adds the tag in the browser, so View Source won't show it. Look in your browser's developer tools instead: the Network tab should show script.js loading.

Then open Settings → Install in Statlark and look under Verification. It says “You're live” once the site's first event arrives, usually within seconds. On a site that already had traffic it's green already, so the real test is your own visit: open your live site, then find yourself on the Overview with the Now range. A browser you excluded with ?statlark_ignore=1 won't show up.

Good to know

  • Don't paste the plain script tag. GTM can drop data-* attributes from the HTML in a Custom HTML tag, and without data-website-id the tracker does nothing. The code above sets the attribute in JavaScript, which works either way.
  • Load Statlark once per page. If the snippet is also in your site's HTML, remove one copy: the tracker only starts once, so the second does nothing.

Other platforms

Next.js · WordPress · Shopify · Webflow · npm · anything else

Sources

These steps were checked against the pages below on .

Last reviewed