Skip to content

Install Statsdot on Drupal

Updated October 18, 2026

Without code: Asset Injector

  1. Install and enable the Asset Injector module.
  2. Go to Configuration > Development > Asset Injector > JS Injector and add an injector.
  3. The injector takes JavaScript code, not an HTML tag, and Statsdot needs its data-domain attribute. Paste this code, which adds the tag with the attribute:
(function () {
  var s = document.createElement('script');
  s.defer = true;
  s.src = 'https://statsdot.com/js/script.js';
  s.setAttribute('data-domain', 'yoursite.com');
  document.head.appendChild(s);
})();
  1. Under the conditions, leave out administration pages (for example with the theme condition set to your front-end theme), then save.

In your theme

If you maintain your own theme or subtheme, add the tag to templates/html.html.twig (copy it from the base theme if your theme does not have it), inside <head>:

<script defer data-domain="yoursite.com" src="https://statsdot.com/js/script.js"></script>

Clear the cache under Configuration > Development > Performance to see the change.

Track events with data-statsdot-event="Contact" on a link, button or form. See Events and goals.