Installation

Install SourceTag on Drupal

Add SourceTag’s tracking script to your Drupal site by editing your theme template or using a contributed module for script injection.

Step 1: Copy your script tag

In your SourceTag dashboard, go to your site’s detail page and copy the script tag. It looks like:

<script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js" async></script>

Step 2: Add to Drupal

Option A: Theme template (recommended)

  1. Open your active theme’s html.html.twig template file (typically located at themes/your_theme/templates/html.html.twig)
  2. Paste the script tag just before the closing </head> tag
  3. Clear the Drupal cache

If your theme doesn’t have this template file, copy it from the base theme or from core/modules/system/templates/html.html.twig into your theme’s templates directory and then add the script.

Option B: Using a module

If you prefer not to edit theme files, install a contributed module that supports adding scripts to the <head> section (e.g., Asset Injector):

  1. Install and enable the module
  2. Add a new HTML asset with the SourceTag script tag
  3. Set it to load on all pages
  4. Save and clear the cache

Step 3: Clear cache and test

Clear the Drupal cache (Configuration > Performance > Clear all caches, or run drush cr).

Visit your site with UTM parameters:

https://yoursite.com/?utm_source=test&utm_medium=cpc&utm_campaign=drupal-test

Submit a form on your site and check wherever your form submissions are received. The submission should include hidden fields with attribution data.

Notes

  • The script works with standard HTML forms rendered by Drupal, including Webform module forms and Contact module forms. Hidden fields are added automatically.
  • If you’re using a form module that renders non-standard markup, you can add hidden fields manually. See Add Hidden Fields to HTML Forms for the field names.
  • For longer cookie persistence, consider adding SourceTag’s server-side cookie endpoint if your hosting supports it. Otherwise, browser cookies are limited to 7 days.