Kirby
Add Rybbit analytics to your Kirby site
Kirby templates are plain PHP files in site/templates/, and shared markup lives in site/snippets/. The snippet goes into whichever file owns your <head>: the Starterkit's site/snippets/header.php, or the template itself in a Plainkit project.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Kirby
The Starterkit renders the document head from a shared snippet that every template includes with <?php snippet('header') ?>.
- 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.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>- Save. Every template that calls
snippet('header')now loads the script.
The Plainkit's site/templates/default.php contains only <h1><?= $page->title() ?></h1> and no document structure, so add the tag wherever you build your <head>. The usual pattern is a header snippet included by each template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?= $page->title() ?></title>
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body><?php snippet('header') ?>
<h1><?= $page->title() ?></h1>
<?php snippet('footer') ?>To keep the site ID out of the snippet, add it to site/config/config.php and read it with <?= option('rybbit.siteId') ?>.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Page cache: if
cache.pages.activeis enabled insite/config/config.php, flushsite/cache/after editing the snippet or cached pages keep the old head. - Multiple header snippets: templates that include a different header (for example
snippet('header-landing')) need the tag added there too. - Panel is not tracked:
/panelis a separate app that does not render your templates, so editing time never appears in Rybbit.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.