-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from middlewarehq/feat/email-input-flow
feat: mixpanel integration
- Loading branch information
Showing
7 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Mixpanel from 'mixpanel'; | ||
|
||
import { flattenObj } from '@/utils/datatype'; | ||
import { objectEnum } from '@/utils/enum'; | ||
|
||
enum TrackEventEnum { | ||
FOLLOWUP_USER_EMAIL | ||
} | ||
|
||
export const TrackNodeEvents = objectEnum(TrackEventEnum); | ||
|
||
const isDev = process.env.NEXT_PUBLIC_APP_ENVIRONMENT === 'development'; | ||
|
||
const mixpanel = Mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL, { | ||
keepAlive: false, | ||
debug: isDev | ||
}); | ||
|
||
export const nodeTrack = (ev: keyof typeof TrackNodeEvents, props: any = {}) => | ||
mixpanel.track(ev, { | ||
...flattenObj(props), | ||
appBuiltAt: process.env.NEXT_PUBLIC_BUILD_TIME, | ||
environment: process.env.NEXT_PUBLIC_APP_ENVIRONMENT, | ||
nodeEnv: process.env.NODE_ENV | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const isObj = (o: any) => o?.constructor === Object; | ||
|
||
export const flattenObj = (obj: any, parentKey = '', map = {}) => { | ||
if (!isObj(obj)) return obj; | ||
|
||
for (let key in obj) { | ||
if (isObj(obj[key])) flattenObj(obj[key], `${parentKey}${key}__`, map); | ||
// @ts-ignore | ||
else map[`${parentKey}${key}`] = obj[key]; | ||
} | ||
|
||
return map; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const objectEnum = <EnumT>(EnumArg: EnumT) => { | ||
type EnumKeys = keyof typeof EnumArg; | ||
// @ts-ignore | ||
return Object.keys(EnumArg).reduce( | ||
// @ts-ignore | ||
(obj, key) => ({ ...obj, [key]: key }), | ||
{} as { [Property in EnumKeys]: Property } | ||
); | ||
}; | ||
|
||
export const objectEnumFromFn = <EnumT>(enumFn: () => EnumT) => | ||
objectEnum(enumFn()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters