我正在尝试建立一个 gatsby 网站,我想在其中设置(至少)谷歌分析 cookie。我已经安装了 react-cookie-consent 以及 gatsby-plugin-gdpr-cookies。我的问题是:
为什么我通过 Cookieconsent 属性配置的 cookie 的生命周期始终保持在“会话”上?当它设置为真。我尝试配置 prop expires = {365} 但它也不起作用。
谢谢!
在我的 Index.js 中:
<CookieConsent
// debug
location='bottom'
style={{ background: 'rgb(13 168 220)' }}
buttonStyle={{ background: 'rgb(148 130 110)', fontSize: '13px' }}
buttonText='Accept'
declineButtonText='decline'
expires={365}
onAccept={() => {
// alert('Accept was triggered by clicking the Accept button');
Cookies.set('gatsby-gdpr-google-analytics', 'true');
}}
enableDeclineButton
setDeclineCookie
cookieName='gatsby-gdpr-google-analytics'
本网站使用 cookie 来增强用户体验。有关更多信息,请参阅我们的隐私政策。
在 gatsby-config.js 文件中:
plugins: [
{
resolve: 'gatsby-plugin-gdpr-cookies',
options: {
googleAnalytics: {
trackingId: 'MY-ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-google-analytics', // here can you change the cookie name
anonymize: true // default
},
googleTagManager: {
trackingId: 'YOUR_GOOGLE_TAG_MANAGER_TRACKING_ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-google-tagmanager', // // here can you change the cookie name
dataLayerName: 'dataLayer' // default
},
facebookPixel: {
pixelId: 'YOUR_FACEBOOK_PIXEL_ID', // leave empty if you want to disable the tracker
cookieName: 'gatsby-gdpr-facebook-pixel' // // here can you change the cookie name
},
// defines the environments where the tracking should be available - default is ["production"]
environments: ['production', 'development']
}
},