Drupal's flexible theme system and custom code capabilities make it easy to add tracking scripts globally across your entire website, ideal for enterprise organizations using Drupal for their web presence.
Add tracking script to your Drupal site
The recommended approach is to add the script to your active theme's template files, ensuring the script loads on all pages consistently.
- Access your Drupal site files via FTP or file manager
- Navigate to your active theme folder (usually
/themes/custom/your-theme/
or/themes/your-theme/
) - Open your main template file (typically
page.html.twig
orhtml.html.twig
) - Add the tracking script in the
<head>
section:
<head>
{{ head }}
<script
async
defer
src="https://affonso.io/js/pixel.min.js"
data-affonso="YOUR_PUBLIC_PROGRAM_ID"
data-cookie_duration="YOUR_COOKIE_DURATION"
></script>
</head>
- Clear Drupal's cache (Admin → Configuration → Performance → Clear all caches)
Alternative: Use a custom module or the "Insert Flickers" module to add the script without modifying theme files.
For more details, see Drupal's theming documentation and template file guide.
Testing
- Clear your Drupal cache after adding the script
- Visit your Drupal site with
?atp=test
- Check browser DevTools → Console → type
window.affonso_referral
- Verify tracking in your Affonso dashboard
Note: Changes to template files require cache clearing to take effect.
Multi-Domain Setup
If you're using Drupal only for your main website (e.g., yourcompany.com
) and your application runs on a subdomain (e.g., app.yourcompany.com
), make sure to install the Affonso tracking script on both domains.
Affonso works seamlessly across subdomains - the same affiliate cookie will be shared between yourcompany.com
and app.yourcompany.com
. See our multi-domain setup guide for more details on cross-domain tracking.
Next Steps
Once installed, you can access affiliate referral data and pass it to your payment provider. Connect your payment provider →