Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the user hits declined the tracking continues #66

Open
deodat opened this issue Oct 21, 2021 · 6 comments
Open

When the user hits declined the tracking continues #66

deodat opened this issue Oct 21, 2021 · 6 comments

Comments

@deodat
Copy link

deodat commented Oct 21, 2021

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!

@andrezimpel
Copy link
Owner

Hm, could you give me access to a repo to reproduce this?

@deodat
Copy link
Author

deodat commented Nov 8, 2021

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!

@andrezimpel
Copy link
Owner

@deodat yea just use my GitHub email :-)

@madmonkeyworks
Copy link

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.

@andrezimpel
Copy link
Owner

@madmonkeyworks any chance we can schedule a screenshare and see where the problem might come from?

@ansmlc
Copy link

ansmlc commented Jul 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants