Skip to content

Commit

Permalink
Use env variable for mixpanel token
Browse files Browse the repository at this point in the history
  • Loading branch information
ClydeDz committed Jul 28, 2024
1 parent 542c056 commit f970ae3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
website/.env.production
1 change: 1 addition & 0 deletions website/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_MIXPANEL_TOKEN=6c905af7861c30571d76bbc6d67696ef
14 changes: 6 additions & 8 deletions website/src/api/Analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
sendNavigationClickedEvent,
sendPageViewEvent,
} from "./Analytics";
import {
AnalyticsLinkType,
MIXPANEL_DEV_PROJECT_ID,
MIXPANEL_PROD_PROJECT_ID,
} from "./IAnalytics";
import { AnalyticsLinkType, MIXPANEL_DEV_PROJECT_ID } from "./IAnalytics";

const mixpanelTrackMock = jest.spyOn(mixpanel, "track");
const mixpanelInitMock = jest.spyOn(mixpanel, "init");
Expand Down Expand Up @@ -126,16 +122,18 @@ describe("Analytics", () => {

describe("given initAnalyticsWithSuperProperties is called", () => {
describe.each([
{ environment: "production", projectId: MIXPANEL_PROD_PROJECT_ID },
{ environment: "test", projectId: MIXPANEL_DEV_PROJECT_ID },
{
environment: "production",
projectId: "XXf70ae3a52dd646aea4025dc1f30aXX",
},
{ environment: "development", projectId: MIXPANEL_DEV_PROJECT_ID },
])(
"given node environment is $environment",
({ environment, projectId }) => {
it(`should initialize analytics with ${projectId} and super properties`, () => {
process.env = {
...processEnvironment,
NODE_ENV: environment as "test" | "production" | "development",
NEXT_PUBLIC_MIXPANEL_TOKEN: projectId,
};

initAnalyticsWithSuperProperties();
Expand Down
12 changes: 3 additions & 9 deletions website/src/api/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import mixpanel from "mixpanel-browser";
import { PageTypes } from "../blocks/Navigation/PageTypes";
import {
ILinkClickedProps,
MIXPANEL_DEV_PROJECT_ID,
MIXPANEL_PROD_PROJECT_ID,
} from "./IAnalytics";
import { ILinkClickedProps, MIXPANEL_DEV_PROJECT_ID } from "./IAnalytics";

export const initAnalyticsWithSuperProperties = () => {
const mixpanelProjectId =
process.env.NODE_ENV === "production"
? MIXPANEL_PROD_PROJECT_ID
: MIXPANEL_DEV_PROJECT_ID;

process.env.NEXT_PUBLIC_MIXPANEL_TOKEN ?? MIXPANEL_DEV_PROJECT_ID;
console.log("************", process.env.NEXT_PUBLIC_MIXPANEL_TOKEN);
try {
mixpanel.init(mixpanelProjectId, {
debug: true,
Expand Down
19 changes: 9 additions & 10 deletions website/src/api/IAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
export const MIXPANEL_DEV_PROJECT_ID = '6c905af7861c30571d76bbc6d67696ef'
export const MIXPANEL_PROD_PROJECT_ID = '50f70ae3a52dd646aea4025dc1f30a06'
export const MIXPANEL_DEV_PROJECT_ID = "6c905af7861c30571d76bbc6d67696ef";

export enum AnalyticsLinkType {
Cta = 'Cta',
SocialIcons = 'Social icons',
CardGitHub = 'GitHub',
CardWebsite = 'Website',
GeneralWebsite = 'External website',
Cta = "Cta",
SocialIcons = "Social icons",
CardGitHub = "GitHub",
CardWebsite = "Website",
GeneralWebsite = "External website",
}

export interface ILinkClickedProps {
link?: string
type?: AnalyticsLinkType
location?: string
link?: string;
type?: AnalyticsLinkType;
location?: string;
}

0 comments on commit f970ae3

Please sign in to comment.