Integration Guides

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') ?>.

  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.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
  1. 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:

site/snippets/header.php
<!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>
site/templates/default.php
<?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.js returns 200 and that POST requests 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.active is enabled in site/config/config.php, flush site/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: /panel is a separate app that does not render your templates, so editing time never appears in Rybbit.

Next steps

On this page