Drupal
Add Rybbit analytics to your Drupal site
The Rybbit module on Drupal.org adds the tracking script to every page and can pass logged-in user details to Rybbit, so you enter a Site ID instead of editing your theme. It requires Drupal 10.3 or later.
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 Drupal
-
Install and enable the module:
composer require drupal/rybbit drush en rybbit -
Go to Configuration → Web services → Rybbit analytics (
/admin/config/services/rybbit). Your account needs the administer rybbit permission. -
Enter your Site ID and save.
Optional settings on the same page:
- Script URL: defaults to Rybbit cloud. Point it at your own instance if you self-host Rybbit.
- Visibility: restrict tracking by role or by page path, each in include or exclude mode.
- Identify logged-in users: calls
identify()with the user's UUID by default, and sends traits you define as key/value pairs.username,nameandemailare recognised trait names. - The module also exposes hooks for altering the sitewide and per-user tracking data from your own module.
If you cannot install contributed modules, copy core/modules/system/templates/html.html.twig into your theme's templates folder and add the snippet just before </head>:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>Clear caches afterwards so Drupal picks up the new template.
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
- Script missing after saving settings: pages are served from Drupal's page cache. Clear caches with
drush cror Configuration → Development → Performance → Clear all caches. - Visitors are tracked but you are not: check the role and path visibility settings on the module page. Excluding the administrator role is a common setup.
- Logged-in users appear anonymous: enable Identify logged-in users in the module settings; without it Drupal accounts are tracked like any other visitor.
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.