I’m trying to add Google Tag Manager tracking to my HubSpot website but running into some issues. I followed the standard HubSpot documentation for adding GTM code through the page settings, but Google requires the tracking script to be positioned right after the opening <body> tag for proper functionality.
When I attempted to use a custom module to place the code in the correct location, HubSpot automatically wraps it with <span> elements, which interferes with Google’s tracking requirements and causes validation errors.
Has anyone found a reliable method to properly implement Google Tag Manager on HubSpot pages while maintaining the correct code placement that Google expects? I need a solution that doesn’t involve extra HTML wrapper elements.
I experienced a similar issue with Google Tag Manager on HubSpot. The key is to avoid adding the code on a page-by-page basis. Instead, utilize HubSpot’s global settings by navigating to Settings > Website > Pages, and add your GTM container code in the site header HTML. While this places the code in the header rather than immediately after the body tag, it functions correctly. Additionally, ensure your GTM tags are set to trigger on DOM ready instead of page load. This approach should resolve the span wrapping dilemma.
The Reports > Tracking Code method works for basic stuff, but Content Settings gives you way more control. Go to Content > Content Settings and scroll to the site header section. Add your GTM container code there instead of doing it page by page. This fixes the span wrapper issue and tracks consistently across your whole site. I had the same validation headaches until I switched - it’s been bulletproof for months and Google Analytics validates perfectly now.
theres an easier fix - go to Reports > Tracking Code in HubSpot instead of using page settings. it drops the GTM code in the right place without that annoying span wrapper. fixed the same issue for me last month.
Same exact frustration here with HubSpot’s span tag wrapping! Skip the custom modules - use template-level implementation instead. Go to Design Manager, edit your template file directly, and drop the GTM script right after the opening body tag. This completely bypasses HubSpot’s automatic wrapping. You’ll need template access (or grab a developer), but you’ll get clean code placement without any unwanted HTML. I’ve used this approach for over a year - no tracking issues or validation errors.