How set up a Gatsby Cookie consent banner with gatsby-plugin-gdpr-cookies

后端 未结 3 1031
日久生厌
日久生厌 2021-01-02 09:06

My website gathers information for Google Analytics, so I need to include a Cookie consent banner for the users to opt in/out of.

I saw the plugin gatsby-plug

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 09:38

    From the plugin page

    First of all the plugin checks in which environment your site is running. If it’s currently running in one of your defined environments it will add the Facebook Pixel javascript by default to the of your site. It will not be activated or initialized by this.

    By default this plugin will not send any data to Google or Facebook to make it GDPR compliant. The user first needs to accept your cookie policy. By accepting that you need to set two cookies - gatsby-gdpr-google-analytics and gatsby-gdpr-facebook-pixel. Depending on the user input the value of each of the cookies should be true or false.

    If the gatsby-gdpr-google-analytics cookie is set to true, Google Analytics will be initialized onClientEntry. Same is for the Facebook Pixel.

    The page view will then be tracked on onRouteUpdate.

    So you should build a banner component and set the cookies to true or false, it depends on the user choice.

提交回复
热议问题