OnyxMetric
Integration Guides

Drupal

Step-by-step guide to add OnyxMetric cookieless analytics to your Drupal site and start tracking visitors

On Drupal you add the tag by editing a theme template. Drupal's page cache serves stored HTML, so clear caches after any change.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Drupal

Copy core/modules/system/templates/html.html.twig into your theme's templates folder if it is not there yet. Add the tag just before </head>:

themes/custom/mytheme/templates/html.html.twig
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>

Clear caches afterwards so Drupal picks up the new template:

drush cr

You can also use Configuration → Development → Performance → Clear all caches.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Tag missing after the change: pages are served from Drupal's page cache. Clear all caches and reload.
  • Tracked on some pages only: a content type or region may use a different template. Check which html.html.twig variant renders those pages.
  • Admin pages: if your admin theme has its own html.html.twig, it does not load the tag unless you add it there. That is usually what you want.

Next steps

On this page