Installation
Install SourceTag via Google Tag Manager
If you manage your site’s scripts through Google Tag Manager (GTM), you can add SourceTag as a Custom HTML tag. This keeps all your tracking scripts in one place.
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> [IMAGE: Screenshot of the SourceTag dashboard showing the script tag on the site detail page]
Step 2: Create a new tag
- Open your GTM container at tagmanager.google.com
- Go to Tags in the left sidebar
- Click New
- Name the tag something clear, like “SourceTag Attribution Script”
[IMAGE: Screenshot of the GTM Tags page with the New button highlighted]
Step 3: Configure the tag
- Click Tag Configuration
- Select Custom HTML
- Paste the script tag in the HTML field:
<script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js" async></script> [IMAGE: Screenshot of the GTM Custom HTML tag configuration with the SourceTag script pasted]
Step 4: Set the trigger
- Click Triggering
- Select All Pages (the built-in Page View trigger)
- Click Save
This fires the tag on every page load across your site.
[IMAGE: Screenshot of the GTM trigger selection with All Pages selected]
Step 5: Publish the container
- Click Submit in the top right corner
- Add a version name like “Added SourceTag”
- Click Publish
The tag is now live. GTM injects the SourceTag script on every page where your GTM container is installed.
[IMAGE: Screenshot of the GTM Submit/Publish dialogue]
Step 6: Test
You can test before publishing using GTM’s Preview mode:
- Click Preview in GTM
- Enter your site URL with UTM parameters:
https://yoursite.com/?utm_source=test&utm_medium=cpc&utm_campaign=gtm-test - In the GTM debug panel, confirm the “SourceTag Attribution Script” tag fired on the Page View event
- Open your browser’s developer tools and check Application > Cookies for a
_sourcetagcookie - Submit a form on your site and check the submission for attribution data
[IMAGE: Screenshot of GTM Preview mode showing the SourceTag tag fired successfully]
Important: tag firing order
SourceTag needs to run before any form submission happens. The All Pages trigger fires on DOMContentLoaded, which is early enough for most forms. However, if you have forms that load very early or via AJAX, be aware that:
- SourceTag uses a MutationObserver to detect forms added to the page after initial load, so dynamically loaded forms are handled
- If you’re using GTM’s built-in form submission tracking, SourceTag’s hidden fields will be populated before GTM captures the form data
Notes
- This works with any website that has GTM installed, regardless of platform.
- If you’re also using GTM to manage cookie consent, you can add a consent condition to the SourceTag tag’s trigger. For example, fire only after the visitor has accepted marketing cookies.
- Browser cookies are limited to 7 days when the script is loaded via GTM (since it’s still a JavaScript cookie). For longer persistence, use the WordPress plugin with server-side cookies enabled.
- If you have multiple environments in GTM (staging, production), make sure to publish to the correct environment.