我已在 react-gtm-module 的帮助下将 Google 标记管理器添加到我的 React 项目中 -
成功添加后,我在控制台中看到一些警告,如下所示
Cookie“_ga”很快就会被拒绝,因为它具有“SameSite”
属性设置为“无”或无效值,没有“安全”
属性。
Cookie“_gid”很快就会被拒绝,因为它具有“SameSite”
属性设置为“无”或无效值,没有“安全”
属性。
Cookie“_gat_UA-xxxxxxxx”将很快被拒绝,因为它具有
“SameSite”属性设置为“None”或无效值,没有
“安全”属性。
我发现我必须使用 SameSite 属性来确保安全,但是如何使用我正在使用的给定库来实现这一点?
I have added Google Tag manager to my react project, with the help of react-gtm-module
After successfully adding it, I see some warning in consoles which are below like -
Cookie “_ga” will be soon rejected because it has the “SameSite”
attribute set to “None” or an invalid value, without the “secure”
attribute.
Cookie “_gid” will be soon rejected because it has the “SameSite”
attribute set to “None” or an invalid value, without the “secure”
attribute.
Cookie “_gat_UA-xxxxxxxx” will be soon rejected because it has the
“SameSite” attribute set to “None” or an invalid value, without the
“secure” attribute.
I see that I have to use sameSite attribute to secure, but how do I implement this with the given library I am using?
发布评论
评论(2)
这不是
react-gtm-module
或其代码配置的问题,而是 Google 跟踪代码管理器中的问题。 GTM 提供的 Google Analytics 跟踪 Cookie 没有有效的SameSite
属性。请注意,这些警告仅显示在某些浏览器(例如 Firefox)中。从更新 80 开始,Google Chrome 将任何没有正确
SameSite
值的 cookie 默认为SameSite=Lax
(这可能会导致它们无法正常工作)。理想情况下,Google 跟踪代码管理器团队将更新其代码以自动设置 Cookie 的
SameSite
属性。不过,您可以自行设置:在 Google 跟踪代码管理器中,转到变量
找到您的 GA 跟踪 ID 变量,然后点击进行编辑
在“更多设置”下进行编辑 -> 要设置的字段
cookieFlags
samesite=none;secure
保存并发布 GTM 配置的新版本。
如果操作正确,这应该可以解决您看到的浏览器警告。
This isn't an issue with
react-gtm-module
or it's configuration in your code, it's an issue within Google Tag Manager. Google Analytics tracking cookies provided by GTM don't have a validSameSite
attribute.Note that those warnings only show in certain browsers (e.g. Firefox). As of Update 80, Google Chrome defaults any cookies without a correct
SameSite
value to toSameSite=Lax
(which might result in them not working properly).Ideally, the Google Tag Manager team would update their code to automatically set the
SameSite
attributes for cookies. However, you can set this yourself:In Google Tag Manager, go to Variables
Find your GA Tracking ID variable, and click to edit
Under More Settings -> Fields to set
cookieFlags
samesite=none;secure
Save and publish a new version of your GTM configuration.
If done correctly this should resolve the browser warnings you are seeing.
如果您不使用Google Tag Manager,并且想添加cookie标志,则可以这样做:
或
https://developers.google.com/analytics/devguides/collection/collection/ga4/reference/config#cookie_flags
If you're not using Google Tag Manager, and would like to add cookie flags, you can do so with:
or
https://developers.google.com/analytics/devguides/collection/ga4/reference/config#cookie_flags