* Disable recording webview click events Introduces a temporary measure to disable the recording of webview click events in PostHog. This is achieved by adding a `temporaryDisabled` flag that, when true, prevents the initialization of PostHog and stops the identification of users. This change is intended to be temporary and should be reverted in a future commit by removing the `temporaryDisabled` flag. * Use separate PostHog config for development environment This commit introduces a separate PostHog project for the development environment. This allows us to track events in the development environment without polluting the production data. The `posthogConfig` now uses `posthogDevEnvConfig` when `process.env.isDev` is true, and `posthogProdConfig` otherwise. * process.env.IS_DEV * Update src/shared/services/config/posthog-config.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix format --------- Co-authored-by: Beatrix Woo <beatrix@cline.bot> Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { useEffect, type ReactNode } from "react"
|
|
import { PostHogProvider } from "posthog-js/react"
|
|
import posthog from "posthog-js"
|
|
import { posthogConfig } from "@shared/services/config/posthog-config"
|
|
import { useExtensionState } from "./context/ExtensionStateContext"
|
|
|
|
export function CustomPostHogProvider({ children }: { children: ReactNode }) {
|
|
const { telemetrySetting, distinctId, version } = useExtensionState()
|
|
const isTelemetryEnabled = telemetrySetting !== "disabled"
|
|
|
|
// NOTE: This is a hack to stop recording webview click events temporarily.
|
|
// Remove this to re-enable.
|
|
const temporaryDisabled = true
|
|
|
|
useEffect(() => {
|
|
if (temporaryDisabled) {
|
|
return
|
|
}
|
|
|
|
posthog.init(posthogConfig.apiKey, {
|
|
api_host: posthogConfig.host,
|
|
ui_host: posthogConfig.uiHost,
|
|
disable_session_recording: true,
|
|
capture_pageview: false,
|
|
capture_dead_clicks: true,
|
|
})
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (temporaryDisabled || distinctId.length === 0 || version.length === 0) {
|
|
return
|
|
}
|
|
|
|
posthog.set_config({
|
|
before_send: (payload: any) => {
|
|
if (payload?.properties) {
|
|
payload.properties.extension_version = version
|
|
payload.properties.distinct_id = distinctId
|
|
}
|
|
return payload
|
|
},
|
|
})
|
|
|
|
const optedIn = posthog.has_opted_in_capturing()
|
|
const optedOut = posthog.has_opted_out_capturing()
|
|
|
|
if (isTelemetryEnabled && !optedIn) {
|
|
posthog.opt_in_capturing()
|
|
posthog.identify(distinctId)
|
|
} else if (!isTelemetryEnabled && !optedOut) {
|
|
posthog.opt_out_capturing()
|
|
}
|
|
}, [isTelemetryEnabled, distinctId, version])
|
|
|
|
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
|
|
}
|