Google Analytics(分析)跟踪代码给出CORS错误
我使用了(我看起来喜欢的)新的Google Analytics(分析)跟踪代码,这是我昨天从我的帐户中获得的。它使用了一些全球站点标签。我已经将它放在了我的顶部,正如GA所指示的那样,但是当我加载我的页面时出现了交叉原点错误,所以GA没有正确跟踪我的网站。
I'm using (what looks to me like) new Google Analytics tracking code that I got from my account yesterday. It makes use of some "Global site tag". I've placed it at the top of my , as GA instructs, but I'm getting a cross origin error when loading my page, so GA isn't tracking my site correctly.
这是确切的信息:
This is the exact message:
访问' https://www.googletagmanager.com/gtag/js?id= {my-id}'from origin'{my website}'已被CORS策略阻止:Access-Control-Allow-Origin标题的值为' http:// www。 googletagmanager.com '不等于提供的来源。
Access to Script at 'https://www.googletagmanager.com/gtag/js?id={my-id}' from origin '{my website}' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://www.googletagmanager.com' that is not equal to the supplied origin.
导致此错误的脚本包含
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="//www.googletagmanager.com/gtag/js?id={my-id}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{my-id}');
</script>
上述代码与Google Analytics(分析)完全相同,所以我不确定它为什么不是't working ..
That code above is exactly as it comes from Google Analytics, so I'm not sure why it isn't working..
任何人都可以提供帮助吗?
Is anyone able to help?
就这个错误消息而言:
As far as this error message:
在'googletagmanager.com/gtag/js?id={my-id} 'from
origin'{我的网站}'已被CORS政策阻止
Access to Script at 'googletagmanager.com/gtag/js?id={my-id}' from origin '{my website}' has been blocked by CORS policy
...唯一的情况是您应该如果您的脚本
元素具有 crossorigin
属性,则会看到该错误消息;例如 crossorigin =anonymous
。
…the only case when you should be seeing that error message is if your script
element has a crossorigin
attribute; e.g., crossorigin="anonymous"
.
如果您不添加 crossorigin =anonymous
属性在你自己的代码中,你可能正在使用一些注入它的CDN系统。
If you’re not adding that crossorigin="anonymous"
attribute in any of your own code, you may be using some CDN system that’s injecting it.