A Google Tag Manager custom template for comprehensive attribution tracking, including UTM parameters, click IDs, and referrer analysis.
- Tracks UTM parameters (source, medium, campaign, term, content)
- Automatically detects and tracks ad platform click IDs:
- Google (gclid, gclsrc, dclid, wbraid, gbraid, gad_source)
- Facebook (fbclid)
- LinkedIn (li_fat_id)
- TikTok (ttclid)
- Twitter (twclid)
- Bing (msclkid)
- Analyzes referrer information for organic and social traffic sources
- Stores attribution data in a first-party cookie
- Pushes attribution data to the dataLayer for easy integration with other tags
- Debug mode for troubleshooting
- Configurable cookie expiration
- Open Google Tag Manager
- Navigate to Templates
- Click "New" in the Tag Templates section
- Click "Import" from the Gallery
- Search for "Attribution Tracking Template"
- Click "Add to Workspace"
- Cookie Expiry: Number of days before the attribution cookie expires (default: 30)
- Debug Mode: Enable console logging for troubleshooting (default: false)
- Child Origin: Origin URL for embedded content (default: https://embeds.beehiiv.com)
- Create a new tag using the template
- Set your desired configuration options
- Set the trigger to fire on page view or your preferred event
- Test using GTM's preview mode
- Publish your container
The template pushes attribution data to the dataLayer in the following format:
{
event: 'attribution_data',
attribution: {
source: string,
medium: string,
campaign: string,
term: string,
content: string,
last_updated: timestamp,
referrer: string,
landing_page: string
}
}
- Fork the repository
- Create a new branch for your feature
- Submit a pull request with a clear description of your changes
MIT License - See LICENSE file for details
For issues and feature requests, please use the GitHub issues tracker.