-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
event-tracking: Add event-tracking with PostHog
For now, the following are tracked: - App start - Session time - Video recording start/stop - Video recording time - Vehicle arming/disarming
- Loading branch information
1 parent
2e12e06
commit 19f8986
Showing
5 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import posthog from 'posthog-js' | ||
|
||
/** | ||
* PostHog client | ||
*/ | ||
class PostHog { | ||
static posthog: ReturnType<typeof posthog.init> | undefined = undefined | ||
|
||
/** | ||
* Initialize the PostHog client if not already initialized | ||
*/ | ||
constructor() { | ||
if (!PostHog.posthog) { | ||
PostHog.posthog = posthog.init('phc_SfqVeZcpYHmhUn9NRizThxFxiI9fKqvjRjmBDB8ToRs', { | ||
api_host: 'https://us.i.posthog.com', | ||
person_profiles: 'always', // Create profiles for anonymous users as well | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Capture an event | ||
* @param {string} eventName - The name of the event | ||
* @param {Record<string, unknown>} properties - The properties of the event | ||
*/ | ||
capture(eventName: string, properties?: Record<string, unknown>): void { | ||
if (!PostHog.posthog) { | ||
throw new Error('PostHog client not initialized.') | ||
} | ||
PostHog.posthog.capture(eventName, properties) | ||
} | ||
} | ||
|
||
const eventTracker = new PostHog() | ||
export default eventTracker |
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