Skip to content

Commit

Permalink
env variable access fixes for Mixpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaaaryan committed Oct 24, 2024
1 parent f39eb78 commit 14585c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/utils/env/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export const browserEnv = envsafe({
NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN: str({
input: process.env.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN,
}),
NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN: str({
input: process.env.NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN,
}),
});
9 changes: 8 additions & 1 deletion src/utils/mixpanel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import mixpanel from 'mixpanel-browser';
import { browserEnv } from './env/browser';

mixpanel.init(process.env.MIXPANEL_PROJECT_TOKEN, {
const mixpanelToken = browserEnv.NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN;

if (!mixpanelToken) {
throw new Error('NEXT_PUBLIC_MIXPANEL_PROJECT_TOKEN is not defined');
}

mixpanel.init(mixpanelToken, {
debug: process.env.NODE_ENV !== 'production',
track_pageview: true,
persistence: 'localStorage'
Expand Down

0 comments on commit 14585c5

Please sign in to comment.