Kirby
Add OnyxMetric analytics to your Kirby site
Kirby templates are plain PHP files in site/templates/, and shared markup lives in site/snippets/. Put the tag in whichever file owns your <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 Kirby
The Starterkit builds the document head in a shared snippet that every template includes.
- Open
site/snippets/header.php. - Add the tag before
</head>:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $site->title() ?> | <?= $page->title() ?></title>
<?= css(['assets/css/index.css', '@auto']) ?>
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>- Save. Every template that calls
snippet('header')now loads the script.
The Plainkit's default template has no document structure, so add the tag wherever you build your <head>. A shared header snippet is the cleanest place:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?= $page->title() ?></title>
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>
<body><?php snippet('header') ?>
<h1><?= $page->title() ?></h1>
<?php snippet('footer') ?>To keep the ID out of the snippet, add it to site/config/config.php and read it with option().
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
- Page cache: if
cache.pages.activeis on, flushsite/cache/after editing the snippet or cached pages keep the old head. - Other header snippets: templates that include a different header need the tag added there too.
- Panel is not tracked:
/panelis a separate app that does not render your templates.
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.