OnyxMetric
Integration Guides

Google Tag Manager

Add OnyxMetric analytics through a Google Tag Manager container

Google Tag Manager loads OnyxMetric through a Custom HTML tag that fires on All Pages, so nothing in your site's code changes. Events you already push to the dataLayer can be forwarded to OnyxMetric with one more tag.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Google Tag Manager

  1. Open your GTM container and go to Tags → New.
  2. Under Tag Configuration, choose Custom HTML and paste the snippet.
  3. Under Triggering, choose All Pages (the built-in Page View trigger).
  4. Name the tag, for example OnyxMetric - Loader, and click Save.
  5. Click Submit and publish the container version.

GTM rebuilds Custom HTML tags before injecting them and can drop non-standard attributes. Keep the site ID in the URL (?siteId=) as shown. Attribute-based setups are not reliable here.

Use Preview mode to confirm the tag fires on page load before you publish.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Track custom events

Once the loader tag is published, window.onyx is available to your own JavaScript and to other GTM tags.

Forward dataLayer events

If your site already pushes events like dataLayer.push({ event: "signup" }), one tag can forward them:

  1. Create a Custom Event trigger. Set the event name to a regex such as signup|purchase|add_to_cart and tick Use regex matching.
  2. Create a Custom HTML tag on that trigger:
<script>
  if (window.onyx) {
    window.onyx.event("{{Event}}", {
      page: "{{Page Path}}",
      referrer: "{{Referrer}}"
    });
  }
</script>

{{Event}}, {{Page Path}}, and {{Referrer}} are GTM built-in variables. Add a Data Layer Variable for any custom field you push (for example plan) and reference it the same way.

Use click and form triggers

The same pattern works with GTM's built-in Click and Form Submission triggers:

<script>
  if (window.onyx) {
    window.onyx.event("cta_clicked", {
      text: "{{Click Text}}",
      url: "{{Click URL}}"
    });
  }
</script>

Enable the Click Text and Click URL built-in variables under Variables → Configure.

Troubleshooting

  • Event tag fires before OnyxMetric loads: the loader is async, so an event tag on the same page load can run first and hit the if (window.onyx) guard. Use tag sequencing so the event tag fires after the loader.
  • Consent mode: if your container gates tags on consent, put the loader in the same consent group as your other analytics tags. Otherwise it never fires.
  • Tag works in Preview but not live: the container version was not published. Click Submit and publish.

Next steps

On this page