You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`NODE_ENV` is a reserved environment variable in Gatsby as it is needed by the build system to make key optimizations when compiling React and other modules. For this reason it is advised to make use of a secondary environment variable for additional environment support.
78
+
79
+
For instance. If you would like to add a staging environment with a custom Google Analytics Tracking ID. You can add `.env.staging` at the root of your project with the following modification to your `gatsby-config.js`
80
+
81
+
```shell
82
+
# .env.staging
83
+
GATSBY_GA_TRACKING_ID="UA-1234567890"
84
+
```
85
+
86
+
```javascript
87
+
// gatsby-config.js
88
+
89
+
let activeEnv =process.env.ACTIVE_ENV;
90
+
91
+
if (!activeEnv) {
92
+
activeEnv ='development';
93
+
}
94
+
95
+
require('dotenv').config({
96
+
path:`.env.${activeEnv}`
97
+
});
98
+
99
+
module.exports= {
100
+
siteMetadata: {
101
+
title:'Gatsby Default Starter'
102
+
},
103
+
plugins: [
104
+
{
105
+
resolve:`gatsby-plugin-google-analytics`,
106
+
options: {
107
+
trackingId:process.env.GATSBY_GA_TRACKING_ID,
108
+
// Puts tracking script in the head instead of the body
0 commit comments