-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate PostHog session replay (#6176)
* Add PostHog API Key to GitHub Action workflows * Add `posthog-js` * Setup PostHog for Rill Developer * Setup PostHog for Rill Cloud * Hand-off sessions from Rill Developer to Rill Cloud * Don't send analytics in `e2e` and `dev` environments * Fix lint * Fix lint * Properly include "Rill version" as a contextual property * Review
- Loading branch information
1 parent
8115ec5
commit 7226141
Showing
11 changed files
with
178 additions
and
19 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
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
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,43 @@ | ||
import posthog, { type Properties } from "posthog-js"; | ||
|
||
const POSTHOG_API_KEY = import.meta.env.RILL_UI_PUBLIC_POSTHOG_API_KEY; | ||
|
||
export function initPosthog(rillVersion: string, sessionId?: string | null) { | ||
// No need to proceed if PostHog is already initialized | ||
if (posthog.__loaded) return; | ||
|
||
if (!POSTHOG_API_KEY) { | ||
console.warn("PostHog API Key not found"); | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access | ||
posthog.init(POSTHOG_API_KEY, { | ||
api_host: "https://us.i.posthog.com", // TODO: use a reverse proxy https://posthog.com/docs/advanced/proxy | ||
session_recording: { | ||
maskAllInputs: true, | ||
maskTextSelector: "*", | ||
recordHeaders: true, | ||
recordBody: false, | ||
}, | ||
autocapture: true, | ||
enable_heatmaps: true, | ||
bootstrap: { | ||
sessionID: sessionId ?? undefined, | ||
}, | ||
loaded: (posthog) => { | ||
posthog.register_for_session({ | ||
"Rill version": rillVersion, | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
export function posthogIdentify(userID: string, userProperties?: Properties) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access | ||
posthog.identify(userID, userProperties); | ||
} | ||
|
||
export function addPosthogSessionIdToUrl(url: string) { | ||
return url + "?ph_session_id=" + posthog.get_session_id(); | ||
} |
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 @@ | ||
// This file lets Typescript know about our custom environment variables | ||
// See: https://vite.dev/guide/env-and-mode#intellisense-for-typescript | ||
|
||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly RILL_UI_PUBLIC_POSTHOG_API_KEY: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
Oops, something went wrong.
7226141
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.
🎉 Published on https://ui.rilldata.in as production
🚀 Deployed on https://67517ab1cde5700857d5b6c5--rill-ui-dev.netlify.app