gatsby-plugin-gdpr-cookies
gatsby-plugin-gdpr-cookies copied to clipboard
When the user hits declined the tracking continues
Hello, I'm facing an issue when trying to implement the Decline function: the tracking continues whenever the user hits the "Decline" button (and it begins before the user accepts or declines). Here's my Gatsby configuration:
{
resolve: `gatsby-plugin-gdpr-cookies`,
options: {
googleTagManager: {
trackingId: 'UA-XXXXXX',
cookieName: 'gatsby-gdpr-google-tagmanager',
defaultDataLayer: { platform: 'gatsby' },
},
facebookPixel: {
pixelId: 'XXXXXXXXXXXX',
cookieName: 'gatsby-gdpr-facebook-pixel',
},
environments: ['production'],
},
},
and in my Layout.js component:
import CookieConsent, { Cookies } from 'react-cookie-consent';
import { useLocation } from '@gatsbyjs/reach-router'; // this helps tracking the location
import { initializeAndTrack } from 'gatsby-plugin-gdpr-cookies';
export default function Layout({ children }) {
const location = useLocation();
const slug = location.pathname.replace(/[\/\\]/g, '');
return (
<div>
<LayoutStyles>
<Header />
<div className="content">
{children}
</div>
<Footer footerItems={footerItems} />
<CookieConsent
location="bottom"
buttonText="J'accepte"
declineButtonText="Je refuse"
cookieName="gatsby-gdpr-google-tagmanager"
expires={150}
onAccept={() => {
Cookies.set('gatsby-gdpr-google-tagmanager', true);
Cookies.set('gatsby-gdpr-facebook-pixel', true);
initializeAndTrack(location);
}}
enableDeclineButton
onDecline={() => {
Cookies.set('gatsby-gdpr-google-tagmanager', false);
Cookies.set('gatsby-gdpr-facebook-pixel', false);
}}
>
En continuant à utiliser le site, vous acceptez l’utilisation de
cookies.
</CookieConsent>
</LayoutStyles>
</div>
);
}
I don't know what I'm doing wrong here.
Thanks for any help on this!
Hm, could you give me access to a repo to reproduce this?
Hello @andrezimpel, sorry for the delay, I was on holydays :) My repo is on Gitlab, do you have a profile there or an email address so I can give you access to it? Thanks a lot!
@deodat yea just use my GitHub email :-)
Hi, same issue here. I'm setting the gatsby-gdpr-google-tagmanager and gatsby-gdpr-google-analytics to false on user decline, but still see the ga cookies present, even on route change or reload.
@madmonkeyworks any chance we can schedule a screenshare and see where the problem might come from?
Same issue here.
@madmonkeyworks Have you found a solution perhaps?
For me it happens in production only. (gatsby build / serve) Tracking is initialized and cookies are set regardless of accept/decline action.
However, in development (gatsby develop) it works as expected.