-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: introduce amplitude
- Loading branch information
Showing
7 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
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
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,41 @@ | ||
import * as amplitude from "@amplitude/analytics-browser" | ||
|
||
// move to cloudflare env variable | ||
// this value is NOT secret - it is a client API key. | ||
// export const AMPLITUDE_API_KEY = process.env.REACT_APP_AMPLITUDE_API_KEY | ||
export const AMPLITUDE_API_KEY = "cfb5a9de7d2840a3af747c4294b10416" | ||
|
||
// Add hook/detection for users to opt out of tracking | ||
export const DONT_TRACK = false | ||
|
||
// Create generic interface | ||
interface IAmplitudeClient { | ||
trackEvent: (eventLabel: string, eventOptions?: Record<string, any>) => void | ||
} | ||
|
||
// empty tracker | ||
export class NullAmplitudeClient implements IAmplitudeClient { | ||
trackEvent(eventLabel: string, eventOptions?: Record<string, any>): void {} | ||
} | ||
|
||
// live tracker | ||
export class AmplitudeClient implements IAmplitudeClient { | ||
constructor(apiKey: string) { | ||
amplitude.init(apiKey) | ||
} | ||
|
||
trackEvent(eventLabel: string, eventOptions?: Record<string, any>): void { | ||
amplitude.track(eventLabel, eventOptions) | ||
} | ||
} | ||
|
||
// build client | ||
export const createAmplitudeClient = (): IAmplitudeClient => { | ||
// if the key isn't found or if the user has opted out of tracking, return a null client | ||
if (!AMPLITUDE_API_KEY || DONT_TRACK) { | ||
return new NullAmplitudeClient() | ||
} | ||
|
||
// otherwise, return a live client | ||
return new AmplitudeClient(AMPLITUDE_API_KEY) | ||
} |
File renamed without changes.