OnyxMetric
Integration Guides

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.

  1. Open site/snippets/header.php.
  2. Add the tag before </head>:
site/snippets/header.php
<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>
  1. 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:

site/snippets/header.php
<!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>
site/templates/default.php
<?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.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

  • Page cache: if cache.pages.active is on, flush site/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: /panel is a separate app that does not render your templates.

Next steps

On this page