Skip to content

Commit 5d62348

Browse files
committed
Add posthog global types
1 parent 1ff72e2 commit 5d62348

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/types/posthog.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { PostHog } from 'posthog-react-native'
2+
3+
declare global {
4+
// Expose the analytics instance on the global scope for app-wide use
5+
// The PostHog instance is initialized at runtime
6+
// See src/util/tracking.ts for initialization
7+
var posthog: PostHog | undefined
8+
}

src/util/tracking.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ if (ENV.POSTHOG_INIT != null) {
171171

172172
posthogAsync
173173
.then(client => {
174-
// @ts-expect-error Attach PostHog instance to global for analytics access
175174
global.posthog = client
176175
})
177176
.catch((e: unknown) => {
@@ -408,10 +407,8 @@ async function logToPosthog(
408407
event: TrackingEventName,
409408
values: TrackingValues
410409
): Promise<void> {
411-
// @ts-expect-error PostHog is attached to global at runtime
412410
if (global.posthog == null) return
413411

414-
// @ts-expect-error PostHog is attached to global at runtime
415412
global.posthog.capture(event, values)
416413
}
417414

0 commit comments

Comments
 (0)