Update time: Jan 17, 2025
Some people may encounter gtm.js failed to load and displayed 404, for example:
There are several reasons:
No Released Version
If it is a newly installed GTM, no released version has been released yet, gtm.js will be 404
Solution:just publish a version on GTM.
Browser Plug-in Blocking
There is a browser plugin blocking gtm.js, eg:
Solution : check the plugins on the browser or remove them
Content Security Policy(CSP)
CSP blocks GTM requests.
Check in the browser developer tools and will see a CSP error.
Solution : Add the following code to the header of all pages:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' www.googletagmanager.com www.google-analytics.com; connect-src 'self' www.google-analytics.com; img-src 'self' data: www.googletagmanager.com www.google-analytics.com; style-src 'self'; frame-src 'self' www.googletagmanager.com">
Wrong Container ID
The wrong container ID causes the page to fail to load, so 404 is displayed.
If my GTM container ID is GTM-PHXQ69M, but I installed GTM-PHXQ69M1, 404 will be displayed, such as:
Solution: Check whether the container ID is correct
Browser cache or DNS issues
Browser’s cache or DNS records may be preventing you from accessing the latest or correct GTM scripts.
Solution :Try clearing your browser cache or flushing your DNS.
Container Code Incorrectly Placed
If not placed correctly, it may cause the script to not load as expected.
Solution: GTM Container code must be placed within the <head> tag or at the very top of the <body> tag.