-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement EventTracker abstraction and Amplitude implementation #3650
base: main
Are you sure you want to change the base?
Conversation
❌ 37 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
❌ 37 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
❌ 37 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
❌ 37 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|
||
const AMPLITUDE_API_KEY = process.env.REACT_APP_AMPLITUDE_API_KEY | ||
|
||
export interface EventTracker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an abstract class instead of an interface is a little more explicit of this Class's purpose
): void | ||
} | ||
|
||
class StubbedEventTracker implements EventTracker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea of having a stubbed / generic event tracker instance; maybe we can throw some errors in the functions instead for some higher visibility
Additionally, pulling this out into a separate file would help reduce some cognitive load when parsing this file
} | ||
|
||
class StubbedEventTracker implements EventTracker { | ||
identify(_userOwnerId: string | number, _username: string): void {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this be a string | number seems a little smelly, is there a way around this?
|
||
export interface EventTracker { | ||
// Identifies the user this session belongs to. | ||
identify(userOwnerId: number | string, username: string): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I really like having functions utilize an object syntax for input parameters for explicit defining instead of relying on proper placement from developers
so in this case we'd have identify({userOwnerId, username}: {userOwnerId: number | string, username: string})
which would prevent a situation where someone accidentally puts the username as the first param unknowingly (since it also accepts a string)
// Adding event types this way provides type safety for event properties. | ||
// E.g., every 'Button Clicked' event must have the buttonType property. | ||
track( | ||
eventType: 'Button Clicked', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a central const somewhere of "EventTypes" might help with readability
@@ -26,6 +31,11 @@ function InactiveRepo({ | |||
repo: repoName, | |||
}, | |||
}} | |||
onClick={() => | |||
eventTracker(provider, owner, repoName).track('Button Clicked', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to instantiate the event tracker somewhere as a singleton and then call track against that instance? Currently every time we want to call track we need to create a new instance of an AmplitudeEventTracker which seems a little expensive
draft