我们正在our-site.com
上运行服务。我们的客户可以通过简单地将their-site.com
链接到our-site.com/customer-service
或通过iFrame将我们的服务嵌入their-site.com
中来“独立使用”服务。想象一下直接访问GMap,而不是将其嵌入到IFrame中。
从Chrome 80开始(我想),当该服务在iFrame中运行时,我们的Google Analytics(分析)已停止工作。 Chrome给了我这个(非常清楚的)信息:
设置了与http://our-site.com/处的跨站点资源关联的cookie,但未设置
SameSite
属性。它已被阻止,因为Chrome现在仅在将跨站点请求设置为SameSite=None
和Secure
的情况下才提供cookie。您可以在Application> Storage> Cookies下的开发人员工具中查看Cookie,并在https://www.chromestatus.com/feature/5088147346030592和https://www.chromestatus.com/feature/5633521622188032上查看更多详细信息。
如果我访问their-site.com
并且将our-site.com/customer-service
嵌入到iFrame中,那么我在GA实时概述中什么也看不到。
如果我手动禁用same-site-by-default-cookies
中的两个功能cookies-without-same-site-must-be-secure
和chrome://flags
并使用嵌入在iFrame中的their-site.com
访问our-site.com/customer-service
,我会看到页面访问在GA实时概述中。
直接访问our-site.com/customer-service
时,GA仍然可以正常运行:
Secure
或SameSite
值(全部为“空白”)... 在外部域的iFrame中运行时,是否可以做些什么使GA重新工作?
我刚刚创建了一个非常简单的测试环境,该环境还显示了上述问题:
our-site.com/customer-service
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={tracking-id}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag("js", new Date());
gtag("config", "{tracking-id}");
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>our site service</title>
</head>
<body>our-site.com/customer-service</body>
</html>
their-site.com
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>their-site.com</title>
</head>
<body>
<iframe src="https://www.our-site.com/customer-service" style="width: 500px; height: 500px;"></iframe>
</body>
</html>
即使这个非常简单的示例也显示了上述行为,其中直接打开our-site.com/customer-service
会显示GA实时概述中的数据,而打开their-site.com
却不会...
答案 0 :(得分:3)
Google tag manager support forum的答案:
在第三方上下文(iframe)中访问第一方Cookie(_ga
)时,必须显式添加cookieFlags
,其值为samesite=none;secure
。
有关各种情况的详细说明,请参见this blogpost。