Bonnie
Bonnie

Reputation: 621

Gatsby.js: gatsby-plugin-google-analytics only firing events in production build

I'm using the gatsby.js plugin gatsby-plugin-google-analytics (version 1.0.31), and it only places my tracking code on my site when I run gatsby build. In that case, my tracking and click events work as expected.

When I run gatsby develop, the tracking code is not put on my page. It would be nice to have this in development mode, as I would love to test my GA click events without having to gatsby build every time.

Is there an option that would always add the analytics code, even in development?

Upvotes: 4

Views: 1522

Answers (1)

Simply007
Simply007

Reputation: 464

I have gone through the source code of gatsby-plugin-google-analytics plugin of version 2.0.10 and analytics are dependent on environment variable NODE_ENV on for server sider rendering and also for browser.

So there is no option to set is via options for this plugin. There is a hacky solution to set the NODE_ENV environment variable to production using i.e. cross-env package.

Upvotes: 1

Related Questions