-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,530 additions
and
308 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
import * as amplitude from "@amplitude/analytics-browser"; | ||
|
||
let amplitudeInitialized = false; | ||
let amplitudeUserIdentified = false; | ||
|
||
export const initAmplitude = () => { | ||
if (amplitudeInitialized) { | ||
return; | ||
} | ||
amplitude.init("b61f581fe0775f56038a6264af879aa9", { | ||
logLevel: | ||
isTestEnv() || isDev() | ||
? amplitude.Types.LogLevel.Debug | ||
: amplitude.Types.LogLevel.None, | ||
autocapture: { | ||
attribution: true, | ||
pageViews: true, | ||
sessions: true, | ||
formInteractions: true, | ||
fileDownloads: true, | ||
elementInteractions: true, | ||
}, | ||
}); | ||
amplitudeInitialized = true; | ||
}; | ||
|
||
export const trackEvent = (event: string, properties: Record<string, any>) => { | ||
if (!amplitudeInitialized) { | ||
initAmplitude(); | ||
} | ||
amplitude.track(event, properties); | ||
}; | ||
|
||
const identifyEvent = new amplitude.Identify(); | ||
|
||
export const identifyUser = ( | ||
properties: Record<string, amplitude.Types.ValidPropertyType>, | ||
) => { | ||
if (!amplitudeInitialized) { | ||
initAmplitude(); | ||
} | ||
if (amplitudeUserIdentified) { | ||
return; | ||
} | ||
for (const [key, value] of Object.entries(properties)) { | ||
identifyEvent.set(key, value); | ||
} | ||
|
||
amplitude.identify(identifyEvent); | ||
amplitudeUserIdentified = true; | ||
}; | ||
|
||
function isDev() { | ||
return window.location.host.startsWith("localhost"); | ||
} | ||
function isTestEnv() { | ||
return window.location.host === "test.supertokens.com"; | ||
} |
Oops, something went wrong.