I've spent multiple days right now researching and trying different things out to get this running. But nothing of the ways worked out so far for me.
My current setup is:
gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-gtag`,
options: {
trackingId: "G-TRACKING ID",
head: true,
anonymize: true
},
},
{
resolve: `gatsby-plugin-gdpr-cookies`,
options: {
googleAnalytics: {
trackingId: "G-TRACKING ID",
cookieName: "gatsby-gdpr-google-analytics",
anonymize: true,
},
},
environments: ["development", "production"],
},
...
]
}
In src/pages/index.js
import React from "react"
import CookieConsent from "react-cookie-consent"
export default function Home() {
return (
<div>
<CookieConsent
overlay
location="bottom"
buttonText="Accept"
enableDeclineButton
declineButtonText="Decline"
cookieName="gatsby-gdpr-google-analytics"
>
We are using cookies to enhance this site ...
</CookieConsent>
...
</div>
)
}
The result is that the tracking works but when the user hits declined the tracking continues.
Is there a current way to set up google-analytics and a cookie consent that stops the tracking when the user declines it?
Thank you a lot in advance !