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
- Open
resources/views/layout.antlers.html. - Add the tag before
</head>:
<!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>- 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.jsreturns200and 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
halforfullstatic caching, runphp please static:clearafter editing the layout. - Live Preview counts as visits: the control panel's Live Preview renders the entry at its real URL with a
tokenparameter, so editors' previews are tracked. Skip requests that carry it. - Control panel is not tracked:
/cpuses Statamic's own views.
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.