Integration Guides

Statamic

Add Rybbit analytics to your Statamic site

Statamic wraps every template in a layout, and a fresh install uses resources/views/layout.antlers.html by default. The snippet goes in that layout's <head>, so it loads on every page without touching individual templates.

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 Statamic

  1. Open resources/views/layout.antlers.html.
  2. Add the tag before </head>:
resources/views/layout.antlers.html
<!doctype html>
<html lang="{{ site:short_locale }}">
<head>
    <meta charset="utf-8">
    <title>{{ title }} | {{ site:name }}</title>
    <script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
    {{ template_content }}
</body>
</html>
  1. Save. Templates rendered through this layout ({{ template_content }}) now include the script.

If an entry or collection sets a different layout field, add the tag to that layout file too, or move it into a partial such as resources/views/partials/rybbit.antlers.html and {{ partial:rybbit }} it from each layout. If your views use Blade (layout.blade.php), the same tag goes in the same place.

To keep the site ID out of version control, put it in .env as RYBBIT_SITE_ID and use {{ config:services:rybbit:site_id }} after adding a rybbit entry to config/services.php.

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

  • Static caching: with half or full static caching enabled in config/statamic/static_caching.php, run php please static:clear after editing the layout, otherwise cached pages keep the old head.
  • Live Preview counts as visits: the control panel's Live Preview renders your entry in an iframe at its real URL with a token query parameter. Editors' previews are tracked like any other visit, so check analytics from the live site rather than the control panel.
  • Control panel is not tracked: /cp uses Statamic's own views, so the snippet never runs there.

Next steps

On this page