Hello Team, I'm trying to add segment to capture t...
# troubleshoot
m
Hello Team, I'm trying to add segment to capture the datahub events I'm adding a file called "segment.ts" under folder "datahub/datahub-web-react/src/app/analytics/plugin/segment.ts" content of file:
Copy code
import { AnalyticsBrowser } from '@segment/analytics-next';

const isEnabled = true;
const key: string = process.env.SEGMENT_KEY as string;

let analytics = AnalyticsBrowser.load({ writeKey: key });
analytics = Object.assign(analytics, { name: 'segment', loaded: () => true });

export default { isEnabled, plugin: analytics };
After building the image and running it, the events are not captured in segment it works when I directly put the key, something like this
Copy code
const key: string = 'YDFGDfsdfEW';
I entered the container and ran the command 'printenv' I can see the env variable in the container Can someone tell me why 'process.env.SEGMENT_KEY' is not able to pull the value ?
✅ 1
SEGMENT_KEY - lives inside /datahub/datahub-frontend/env/docker.env
g
when react reads from
process.env.ENV_VAR
, its the value of the ENV_VAR when the react bundle was built, not when the react app is served
so I would check that- how are you building and running your app?
m
Yeah I moved the env variable into .env inside datahub-web-react
it works fine now
Like you said, the ENV variable should be available at the time of the build