@futuregerald Sorry if I’m still not clear enough but that’s what I’ve been trying to do in my simple react app without CRA. The app trying to read process.env.BRANCH but it returns undefined which I believe should be assigned during build process.
Let’s take a step back. When is that code running?
//Sends branch name to GTM/GA for Netlify split-testing
window.ab_branch = process.env.BRANCH
It can ONLY run successfully during build. If you try to do it at browse time, yes, it will be undefined. BRANCH is only defined when BUILDING your site, so you have to interpolate at that time.
This is an article going into much more detail about how to use env vars, and it also explains some situations where even during build, your build pipeline “throws away” the environment and you’d have to fix that if it is what’s happening (that would cause “BRANCH” to be undefined even during build):