Javascript 盖茨比GDPR Cookie横幅如何实现多个Cookie+;禁用跟踪?
因此,我在Javascript 盖茨比GDPR Cookie横幅如何实现多个Cookie+;禁用跟踪?,javascript,reactjs,cookies,graphql,gatsby,Javascript,Reactjs,Cookies,Graphql,Gatsby,因此,我在gatsby plugin-gdpr-cookies插件之后设置了一个基本的cookie横幅,我使用了react-cookie-approve,但它只显示了一个简单的我们在网站上使用cookies并带有接受按钮 如何在我的cookieconsent组件中同时传入google analytics和google tag manager?这些文档只显示了一个cookieName,我不知道如何添加google分析以外的内容 另外,我如何检查它是否真的禁用了cookie跟踪 我将插件添加到我
gatsby plugin-gdpr-cookies
插件之后设置了一个基本的cookie横幅,我使用了react-cookie-approve
,但它只显示了一个简单的我们在网站上使用cookies
并带有接受按钮
google analytics
和google tag manager
?这些文档只显示了一个cookieName,我不知道如何添加google分析以外的内容
gatsby config.js
{
resolve: `gatsby-plugin-gdpr-cookies`,
options: {
googleAnalytics: {
trackingId: 'YOUR_GOOGLE_ANALYTICS_TRACKING_ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-google-analytics', // default
anonymize: true, // default
allowAdFeatures: false // default
},
googleTagManager: {
trackingId: 'YOUR_GOOGLE_TAG_MANAGER_TRACKING_ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-google-tagmanager', // default
dataLayerName: 'dataLayer', // default
},
facebookPixel: {
pixelId: 'YOUR_FACEBOOK_PIXEL_ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-facebook-pixel', // default
},
// defines the environments where the tracking should be available - default is ["production"]
environments: ['production', 'development']
},
},
然后我将Cookie横幅添加到layout.js中
<CookieConsent
location="bottom"
buttonText="Accept"
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics"
>
This website uses cookies to enhance the user experience.
</CookieConsent>
本网站使用cookies来增强用户体验。
另外,cookie只跟踪
gatsby-gdpr-google-analytics
,但我需要它跟踪gatsby-gdpr-google-tagmanager
,这两个问题的答案相同:用户单击“接受”按钮后,您必须初始化跟踪。这将取消跟踪所有内容,直到用户接受同意。在用户接受时执行以下操作:
import { useLocation } from "@reach/router" // this helps tracking the location
import { initializeAndTrack } from 'gatsby-plugin-gdpr-cookies'
在accept函数中(onAccept
):
此外,根据软件包的文档,您已经公开了一个onDecline
事件,该事件在用户拒绝GDPR策略时触发。若要允许,必须添加enableDeclineButton
属性
<CookieConsent
enableDeclineButton
onDecline={() => {
alert("nay!");
}}
></CookieConsent>
{
警惕(“不!”);
}}
>
您可以在此处设置参数、本地存储或其他cookie
您的最终代码应该如下所示:
<CookieConsent
enableDeclineButton
onDecline={() => {
alert("nay!"); // your stuff here
}}
onAccept={() => {
initializeAndTrack(location)
}}
location="bottom"
buttonText="Accept"
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics">
This website uses cookies to enhance the user experience.
</CookieConsent>
{
警惕(“不!”;//你的东西在这里
}}
onAccept={()=>{
初始化AndTrack(位置)
}}
位置=“底部”
buttonText=“接受”
declineButtonText=“拒绝”
cookieName=“盖茨比gdpr谷歌分析”>
本网站使用cookies来增强用户体验。
两个问题的答案相同:用户单击“接受”按钮后,您必须初始化跟踪。这将取消跟踪所有内容,直到用户接受同意。在用户接受时执行以下操作:
import { useLocation } from "@reach/router" // this helps tracking the location
import { initializeAndTrack } from 'gatsby-plugin-gdpr-cookies'
在accept函数中(onAccept
):
此外,根据软件包的文档,您已经公开了一个onDecline
事件,该事件在用户拒绝GDPR策略时触发。若要允许,必须添加enableDeclineButton
属性
<CookieConsent
enableDeclineButton
onDecline={() => {
alert("nay!");
}}
></CookieConsent>
{
警惕(“不!”);
}}
>
您可以在此处设置参数、本地存储或其他cookie
您的最终代码应该如下所示:
<CookieConsent
enableDeclineButton
onDecline={() => {
alert("nay!"); // your stuff here
}}
onAccept={() => {
initializeAndTrack(location)
}}
location="bottom"
buttonText="Accept"
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics">
This website uses cookies to enhance the user experience.
</CookieConsent>
{
警惕(“不!”;//你的东西在这里
}}
onAccept={()=>{
初始化AndTrack(位置)
}}
位置=“底部”
buttonText=“接受”
declineButtonText=“拒绝”
cookieName=“盖茨比gdpr谷歌分析”>
本网站使用cookies来增强用户体验。
要回答您的问题,您可以导入cookie(从js cookie)并使用onAccept函数手动设置cookie
像这样的
import CookieConsent, { Cookies } from "react-cookie-consent";
<CookieConsent
location="bottom"
buttonText="Accept"
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics"
onAccept={() => {
Cookies.set("gatsby-gdpr-google-tagmanager", true)
}}
>
This site uses cookies ...
</CookieConsent>
导入CookieConsent,{Cookies}来自“react cookie Approve”;
{
Cookies.set(“盖茨比gdpr谷歌标签管理器”,真)
}}
>
这个网站使用cookies。。。
要回答您的问题,您可以导入cookie(从js cookie)并使用onAccept函数手动设置cookie
像这样的
import CookieConsent, { Cookies } from "react-cookie-consent";
<CookieConsent
location="bottom"
buttonText="Accept"
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics"
onAccept={() => {
Cookies.set("gatsby-gdpr-google-tagmanager", true)
}}
>
This site uses cookies ...
</CookieConsent>
导入CookieConsent,{Cookies}来自“react cookie Approve”;
{
Cookies.set(“盖茨比gdpr谷歌标签管理器”,真)
}}
>
这个网站使用cookies。。。
如何检查它是否实际工作?此外,我的Cookie仅在Cookie中显示google分析,对于cookieName,我不能同时添加google分析和google tag manager?您不应该添加GTM,因为GTM不存储跟踪内容的Cookie。通过GTM商店cookies启用的工具。如何检查它是否实际工作?此外,我的Cookie仅在Cookie中显示google分析,对于cookieName,我不能同时添加google分析和google tag manager?您不应该添加GTM,因为GTM不存储跟踪内容的Cookie。通过GTM存储cookie启用的工具。