Documentation
Drupal
Add Measure to your Drupal site in a few lines of code.
Step 1
Add via your theme template
The most common approach is to add the script to your
theme's
html.html.twig
template. Copy the default template into your theme if you haven't already:
cp core/modules/system/templates/html.html.twig \ themes/custom/YOUR_THEME/templates/
Then add the Measure script tag just before the closing
</head> tag:
<script src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script> </head>
Replace YOUR_TRACKING_ID
with the tracking ID from your dashboard.
Step 2
Or use a hook
If you'd rather not edit templates directly, you can attach
the script from your theme's
.theme
file using
hook_page_attachments:
function YOUR_THEME_page_attachments(array &$attachments) {
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => [
'src' => 'https://lets.measure.events/api/script/YOUR_TRACKING_ID',
],
],
'measure_tracking',
];
}
Clear the Drupal cache after adding the hook:
drush cr
Works with every Drupal setup
Measure is a single script tag with no module dependencies. It works across all common Drupal configurations:
- Drupal 10 and 11
- Custom and contrib themes
- Multisite installations
- Managed hosts like Pantheon, Acquia, and Platform.sh
- Decoupled Drupal with any front-end
Next steps
Continue exploring the documentation.
- UTM Parameters — track marketing campaigns automatically
- Data Collection — what we collect and what we don't
- AI Agent Analytics — detect traffic from AI agents