OnyxMetric
Integration Guides

Statamic

Add OnyxMetric analytics to your Statamic site

Statamic wraps every template in a layout. A fresh install uses resources/views/layout.antlers.html. Put the tag in that layout's <head>.

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 Statamic

  1. Open resources/views/layout.antlers.html.
  2. Add the tag before </head>:
resources/views/layout.antlers.html
<!doctype html>
<html lang="{{ site:short_locale }}">
<head>
    <meta charset="utf-8">
    <title>{{ title }} | {{ site:name }}</title>
    <script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>
<body>
    {{ template_content }}
</body>
</html>
  1. Save. Every template rendered through this layout now includes the script.

If an entry or collection sets a different layout, add the tag to that file too, or move it into a partial and include it from each layout.

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.

Troubleshooting

  • Static caching: with half or full static caching, run php please static:clear after editing the layout.
  • Live Preview counts as visits: the control panel's Live Preview renders the entry at its real URL with a token parameter, so editors' previews are tracked. Skip requests that carry it.
  • Control panel is not tracked: /cp uses Statamic's own views.

Next steps

On this page