Skip to content

Commit 2536397

Browse files
committed
feat: add PostHog telemetry provider for cloud builds
- Add posthog-js dependency - Create PostHogTelemetryProvider following MixpanelTelemetryProvider pattern - Register provider in initTelemetry.ts - Add __POSTHOG_API_KEY__ and __POSTHOG_API_HOST__ build-time env vars - Tree-shaken away in OSS builds (verified)
1 parent fe8ab1d commit 2536397

9 files changed

Lines changed: 615 additions & 67 deletions

File tree

global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ declare const __SENTRY_DSN__: string
44
declare const __ALGOLIA_APP_ID__: string
55
declare const __ALGOLIA_API_KEY__: string
66
declare const __USE_PROD_CONFIG__: boolean
7+
declare const __POSTHOG_API_KEY__: string
8+
declare const __POSTHOG_API_HOST__: string
79

810
interface ImpactQueueFunction {
911
(...args: unknown[]): void

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"loglevel": "^1.9.2",
101101
"marked": "^15.0.11",
102102
"pinia": "catalog:",
103+
"posthog-js": "catalog:",
103104
"primeicons": "catalog:",
104105
"primevue": "catalog:",
105106
"reka-ui": "catalog:",

pnpm-lock.yaml

Lines changed: 217 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ catalog:
8686
picocolors: ^1.1.1
8787
pinia: ^3.0.4
8888
postcss-html: ^1.8.0
89+
posthog-js: ^1.358.1
8990
pretty-bytes: ^7.1.0
9091
primeicons: ^7.0.0
9192
primevue: ^4.2.5

scripts/vite-define-shim.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ declare global {
1111
const __ALGOLIA_APP_ID__: string
1212
const __ALGOLIA_API_KEY__: string
1313
const __USE_PROD_CONFIG__: boolean
14+
const __POSTHOG_API_KEY__: string
15+
const __POSTHOG_API_HOST__: string
1416
const __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
1517
const __IS_NIGHTLY__: boolean
1618
}
@@ -22,6 +24,8 @@ type GlobalWithDefines = typeof globalThis & {
2224
__ALGOLIA_APP_ID__: string
2325
__ALGOLIA_API_KEY__: string
2426
__USE_PROD_CONFIG__: boolean
27+
__POSTHOG_API_KEY__: string
28+
__POSTHOG_API_HOST__: string
2529
__DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
2630
__IS_NIGHTLY__: boolean
2731
window?: Record<string, unknown>
@@ -37,6 +41,8 @@ globalWithDefines.__SENTRY_DSN__ = ''
3741
globalWithDefines.__ALGOLIA_APP_ID__ = ''
3842
globalWithDefines.__ALGOLIA_API_KEY__ = ''
3943
globalWithDefines.__USE_PROD_CONFIG__ = false
44+
globalWithDefines.__POSTHOG_API_KEY__ = ''
45+
globalWithDefines.__POSTHOG_API_HOST__ = ''
4046
globalWithDefines.__DISTRIBUTION__ = 'localhost'
4147
globalWithDefines.__IS_NIGHTLY__ = false
4248

src/platform/telemetry/initTelemetry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ export async function initTelemetry(): Promise<void> {
2424
{ TelemetryRegistry },
2525
{ MixpanelTelemetryProvider },
2626
{ GtmTelemetryProvider },
27-
{ ImpactTelemetryProvider }
27+
{ ImpactTelemetryProvider },
28+
{ PostHogTelemetryProvider }
2829
] = await Promise.all([
2930
import('./TelemetryRegistry'),
3031
import('./providers/cloud/MixpanelTelemetryProvider'),
3132
import('./providers/cloud/GtmTelemetryProvider'),
32-
import('./providers/cloud/ImpactTelemetryProvider')
33+
import('./providers/cloud/ImpactTelemetryProvider'),
34+
import('./providers/cloud/PostHogTelemetryProvider')
3335
])
3436

3537
const registry = new TelemetryRegistry()
3638
registry.registerProvider(new MixpanelTelemetryProvider())
3739
registry.registerProvider(new GtmTelemetryProvider())
3840
registry.registerProvider(new ImpactTelemetryProvider())
41+
registry.registerProvider(new PostHogTelemetryProvider())
3942

4043
setTelemetryRegistry(registry)
4144
})()

0 commit comments

Comments
 (0)