Google 即使定义了 CORS 映射,跟踪代码管理器的每个请求也会出现 403
Google Tag Manager 403's every request even if CORS mapping is defined
当我转移到 AMP 时,Google 跟踪代码管理器停止工作。
每次打开 AMPed 页面时都会出现此问题,我可以在浏览器控制台中看到一些错误,例如
第一个错误:
https://www.googletagmanager.com/amp.json?id=MY_GTM_TAG>m.url=MY_HTTP_URL
(403)
第二个错误:
请求的资源上不存在 'Access-Control-Allow-Origin' header。 Origin '' 因此不允许访问。响应的 HTTP 状态代码为 403。如果不透明的响应满足您的需求,请将请求的模式设置为 'no-cors' 以获取禁用 CORS 的资源。
在扩展 WebMvcConfigurerAdapter
的 class 中,我像这样覆盖了方法 addCorsMappings
:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders("*")
.allowCredentials(true);
};
但是还是不行(这个方法是开机执行的,我查过了)。你有什么想法/提示吗?
编辑 1(2016 年 12 月 22 日):
问: 你是如何加载标签管理器的?您使用的是 AMP 版本的脚本吗? (@吉姆杰弗里斯)
A: 是的,在 <head>
中我包含了以下代码:
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
在<body>
中有:
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=${googleTagId}>m.url=SOURCE_URL" data-credentials="include"></amp-analytics>
基于此thread, maybe you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. A tutorial about how to achieve that is Using CORS.
*当您使用邮递员时,他们不受此政策的限制。引自Cross-Origin XMLHttpRequest:*
Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.
同样基于此 forum,应用程序必须以完全管理员身份进行身份验证,并且 POST 所需的 CORS 配置 /rest/system/config
。
我遇到了同样的问题,结果 你不能使用你的旧 GTM "Web" 容器 所以你必须创建一个特定的AMP 容器。
根据 Google 的说明发现 here:
Create an AMP container
Tag Manager features an AMP container type. Create a new AMP container for your project:
- On the Accounts screen, click More Actions (More) for the account
you'd like to use. Select Create Container.
- Name the container. Use a descriptive name, e.g. "example.com - news - AMP".
- Under "Where to Use Container", select AMP.
- Click "Create".
当我转移到 AMP 时,Google 跟踪代码管理器停止工作。 每次打开 AMPed 页面时都会出现此问题,我可以在浏览器控制台中看到一些错误,例如
第一个错误:
https://www.googletagmanager.com/amp.json?id=MY_GTM_TAG>m.url=MY_HTTP_URL
(403)
第二个错误:
请求的资源上不存在 'Access-Control-Allow-Origin' header。 Origin '' 因此不允许访问。响应的 HTTP 状态代码为 403。如果不透明的响应满足您的需求,请将请求的模式设置为 'no-cors' 以获取禁用 CORS 的资源。
在扩展 WebMvcConfigurerAdapter
的 class 中,我像这样覆盖了方法 addCorsMappings
:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders("*")
.allowCredentials(true);
};
但是还是不行(这个方法是开机执行的,我查过了)。你有什么想法/提示吗?
编辑 1(2016 年 12 月 22 日):
问: 你是如何加载标签管理器的?您使用的是 AMP 版本的脚本吗? (@吉姆杰弗里斯)
A: 是的,在 <head>
中我包含了以下代码:
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
在<body>
中有:
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=${googleTagId}>m.url=SOURCE_URL" data-credentials="include"></amp-analytics>
基于此thread, maybe you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. A tutorial about how to achieve that is Using CORS.
*当您使用邮递员时,他们不受此政策的限制。引自Cross-Origin XMLHttpRequest:*
Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.
同样基于此 forum,应用程序必须以完全管理员身份进行身份验证,并且 POST 所需的 CORS 配置 /rest/system/config
。
我遇到了同样的问题,结果 你不能使用你的旧 GTM "Web" 容器 所以你必须创建一个特定的AMP 容器。
根据 Google 的说明发现 here:
Create an AMP container
Tag Manager features an AMP container type. Create a new AMP container for your project:
- On the Accounts screen, click More Actions (More) for the account you'd like to use. Select Create Container.
- Name the container. Use a descriptive name, e.g. "example.com - news - AMP".
- Under "Where to Use Container", select AMP.
- Click "Create".