Google同意模式使用Gatsby实施
我正在关注此 nofollow noreferrer“> tutorial”将cookie添加到我的网站上! 通过使用gatsby.js,我不确定如何添加这些代码:
<!-- The initial config of Consent Mode -->
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 1500,
});
gtag('set', 'ads_data_redaction', true);
</script>
<!-- Cookie Information Pop-up Script is required for the SDK -->
<script id="CookieConsent" src="https://policy.app.cookieinformation.com/uc.js" data-culture="EN" type="text/javascript"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TRACKING-ID');
</script>
</head>
<body>
您是否知道如何在盖茨比(Gatsby)实现此代码,是否有任何库或其他有助于实现这些脚本的东西! 谢谢
I am following this tutorial about implementing google consent mode to add cookies to my website !
By using Gatsby.js I am not sure how to add these codes :
<!-- The initial config of Consent Mode -->
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 1500,
});
gtag('set', 'ads_data_redaction', true);
</script>
<!-- Cookie Information Pop-up Script is required for the SDK -->
<script id="CookieConsent" src="https://policy.app.cookieinformation.com/uc.js" data-culture="EN" type="text/javascript"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TRACKING-ID');
</script>
</head>
<body>
Do you have any idea how to implement this code in Gatsby , is there any library or something that will help to implement these scripts !
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该组件用作页面加载时应用的初始屏幕。
下一个组件更多是配置屏幕,它提供有关所应用的cookie的更多信息,如果您注意切换的导入,我们会使用切换来允许用户在任何时候专门关闭或关闭其cookie,您当然,如果您有很多GDPR合规,则可能需要创建单独的功能来处理删除cookie的函数,或者是通过要删除 /应用的cookie名称的可重复使用功能。
编辑
This component is used as the initial screen that applies when the page loads.
The next component is more of a Configuration screen, which provides more information on the cookies being applied, if you take note on the import of Toggle, we use a toggle to allow users to specifically toggle on or off their cookies at any point, you of course if you have many GDPR compliances, may want to either create separate functions that handle the removal of cookies or a reusable function that is passed the name of the cookie to be removed / applied.
EDIT
在Gatsby插件集线器中使用此插件
gatsby-plugin-gdpr-cookies
它将为您提供所需的内容,并且您可以在插件的选项中列出您想要跟踪的cookie +您希望提供的cookiename然后,可以从组件级别上使用cookie工具栏时从组件级别使用:
它消除了必须用react-helmet将脚本注入脚本的用法,因为插件将为您处理脚本注入。
Use this plugin from the Gatsby Plugin Hub
gatsby-plugin-gdpr-cookies
It will provide you what you are looking for and also you can list in the options for the plugin which cookies you are looking to track + a cookieName you wish to provide which you can then work with from a component level when creating a cookie toolbar such as:
It elimites the usage of having to inject a script into the head of the website with React-Helmet as the plugin will handle the script injection for you.