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
- Open
resources/views/layout.antlers.html. - Add the tag before
</head>:
<!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>- 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.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
- Static caching: with
halforfullstatic caching enabled inconfig/statamic/static_caching.php, runphp please static:clearafter 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
tokenquery 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:
/cpuses Statamic's own views, so the snippet never runs there.
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.