Skip to content
Will your site survive Black Friday? Free peak-readiness audit →
ANALYTICS

Google Tag Manager and tracking scripts breaking Magento CSP

Analytics and marketing tags must comply with Content Security Policy. How to add GTM safely so you don’t get blocked scripts or silent tracking loss.

By VISIBI Analytics team·Reviewed by Adnan Khan, Co-founder & CEO·Updated 29 September 2026·6 min read
QUICK ANSWER

Analytics and marketing tags must comply with Content Security Policy. How to add GTM safely so you don’t get blocked scripts or silent tracking loss.

FROM OUR ENGINEERING WORKREAL CASE

Tracking code inserted outside Magento’s CSP rules produced blocked scripts and console errors that went unnoticed until reports looked wrong.

KEY TAKEAWAYS
✓Tags added the wrong way can be blocked by CSP — silently losing data.
✓Whitelist required domains in csp_whitelist.xml.
✓Check the browser console and CSP reports after every tag change.

What goes wrong

  • Inline GTM snippets blocked
  • Custom HTML tags injecting new domains
  • Console errors nobody notices
  • Conversions under-reported
RELATED GUIDEGA4 ecommerce events: the complete setup guide → Is your tracking accurate?We set up GA4, GTM, consent and ad conversions properly.Get a free tracking audit →

Do it properly

Load GTM via a module that respects CSP, whitelist required domains, limit Custom HTML tags and monitor CSP violation reports.

Common mistakes to avoid

✕Trusting GA4 numbers without checking them against real orders
✕Firing purchase events more than once per order
✕Skipping Consent Mode for UK/EEA traffic
✕Having no documentation of what is tracked and why
HOW VISIBI CAN HELP

How we help with analytics

01Health checkWe test your tags against real orders and consent choices.
02Measurement planA documented dataLayer and event spec for your platform.
03Implement & QABuilt on staging, verified with test orders, then released.
04MonitorAlerts when tags break after site changes.
Get a free tracking audit →Free · No obligation · Reply within 24 hours

Frequently asked questions

Will CSP stop my tracking?

Only if tags aren’t whitelisted properly.

Is server-side GTM better?

It reduces client-side scripts and can help with CSP and privacy.

Can you audit our tags?

Yes — see Tracking & Analytics Setup.

AK
Reviewed by Adnan Khan · Co-founder & CEO25 years growing digital businesses across search, AI visibility and ecommerce. Written by the VISIBI Analytics team.Meet the team →
Was this guide helpful?
Share:LinkedInXEmail
RELATED SERVICES

Keep reading

ANALYTICS · 10 MINGA4 ecommerce events: the complete setup guideRead →ANALYTICS · 7 MINMeta Conversions API explained: why your pixel isn’t enoughRead →ANALYTICS · 7 MINGoogle Consent Mode v2: what UK businesses need to doRead →
FREE · NO OBLIGATION

Is your tracking accurate?

We set up GA4, GTM, consent and ad conversions properly.

Get a free tracking audit →Talk to a specialist
✓ Senior specialist, not a bot✓ Reply within 24 hours✓ Clients in 18 countries
TRACKING HEALTH CHECKEXAMPLE
Are your tags telling the truth?
GA4 revenue vs orders−18%
Consent Mode v2Missing
Google Ads conversionsFiring
Your free review shows your real numbers.