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
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.