Skip to content

Commit

Permalink
Merge pull request #10179 from hicommonwealth/israel.10064.mixpanel-i…
Browse files Browse the repository at this point in the history
…nitialized-earlier

frontend mixpanel calls now hit dashboard
  • Loading branch information
Israellund authored Dec 9, 2024
2 parents 34bbf77 + 8831e18 commit bb82242
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions libs/adapters/src/mixpanel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export const MixpanelAnalytics = (): Analytics => {
mixpanelNode = MixpanelLib.init(config.ANALYTICS.MIXPANEL_DEV_TOKEN!);
}
} catch (e) {
log.error(
'Unable to initialized the backend mixpanel client: ',
e as Error,
);
log.error('Unable to initialize the backend mixpanel: ', e as Error);
}

return {
Expand All @@ -29,7 +26,10 @@ export const MixpanelAnalytics = (): Analytics => {
try {
mixpanelNode?.track(event, payload);
} catch (e) {
log.error(`Failed to track event, ${event.toString()}:`, e as Error);
log.error(
`Failed to track backend mixpanel event, ${event.toString()}:`,
e as Error,
);
}
},
};
Expand Down
19 changes: 12 additions & 7 deletions packages/commonwealth/shared/analytics/client-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { AnalyticsPayload, BaseMixpanelPayload, providers } from './types';
// WARN: Using process.env to avoid webpack failures
try {
if (process.env.APP_ENV === 'production') {
mixpanel.init(process.env.MIXPANEL_PROD_TOKEN, { debug: true });
} else if (process.env.APP_ENV === 'development') {
// NOTE: Only works if NODE_ENV defined in .env
// Make sure that is set to development if you want to use backend Mixpanel locally.
mixpanel.init(process.env.MIXPANEL_DEV_TOKEN, { debug: true });
mixpanel.init(process.env.MIXPANEL_PROD_TOKEN, {
debug: true,
});
} else if (process.env.APP_ENV === 'local') {
mixpanel.init(process.env.MIXPANEL_DEV_TOKEN, {
debug: true,
});
}
} catch (e) {
console.log('Unable to initialized the backend mixpanel client: ', e);
console.log('Unable to initialize the frontend mixpanel: ', e);
}

// ----- Client Side Mixpanel Library Utils ------ //
Expand All @@ -20,7 +22,10 @@ export function mixpanelBrowserTrack<T extends BaseMixpanelPayload>(data: T) {
try {
mixpanel.track(event, payload);
} catch (e) {
console.log(`Failed to track event, ${event.toString()}:`, e.message);
console.log(
`Failed to track frontend mixpanel event, ${event.toString()}:`,
e.message,
);
}
}

Expand Down

0 comments on commit bb82242

Please sign in to comment.