Read Netlify env variables from a Gatsby project

Hey! I’m trying to set up split testing and I did it successfully, I’m having an issue while trying to track my user’s interaction cause I’m attempting to use the BRANCH variable from the read-only environment variables.

I realized that If I print console.log(process.env.BRANCH) in my deployed website, the value is undefined. I’m trying to read this variable client side

I’m using Gatsby, does anyone may know how I can get this variable?

Greetings! Gatsby only allows env vars prefixed with GATSBY_ through to the React code by default. This plugin will allow you to specify other ENV vars (by name) to be passed through to your code. That ought to do it!


Jon

1 Like

This worked! Thanks @jonsully

1 Like