andrezimpel / gatsby-plugin-gdpr-cookies

Gatsby plugin to add Google Analytics (V4 is supported), Google Tag Manager, Facebook Pixel, TikTok Pixel and Hotjar in a GDPR form to your site.
Apache License 2.0
101 stars 70 forks source link

This will not work in production #88

Open klyngen opened 2 years ago

klyngen commented 2 years ago

There are some big issues with this plugin and I want to help you guys.

  1. lodash merge that makes it impossible to override environments

    const options = { ...defaultOptions, ...pluginOptions }
  2. Environment-variables that will never exist:

First read this Then understand that the environment variables will not be available in prod. process.env.NODE_ENV and process.env.ENV will not be available. Runtime. During development this will work well but not in production. GATSBY_NODE_ENV will work.

Please make a better solution for seeing if we are in production. My suggestion is that you want tracking unless you are in a development environment. Make an environment-variable that says no-tracking. I will make a PR to your repo and you can use it as inspiration.

Pull request for your repo is here

doublejosh commented 1 year ago

Be aware that any Gatsby build is considered "production" ...only the interactive npm run dev or gatsby develop will be considered "development"

On some hosts you can use process.env.CONTEXT === "production"

klyngen commented 1 year ago

But not all hosts. Please consider my Pull Request https://github.com/andrezimpel/gatsby-plugin-gdpr-cookies/pull/89/files I have survived by forking and applying my changes.

klyngen commented 1 year ago

In the PR, I took the liberty of also do some refactoring :smile: