Skip to content

🐛 - Fix PostHog dropping events & bump to 2.6.2#609

Open
guytepper wants to merge 2 commits into
mainfrom
fix/posthog-shared-client-and-bump-2.6.2
Open

🐛 - Fix PostHog dropping events & bump to 2.6.2#609
guytepper wants to merge 2 commits into
mainfrom
fix/posthog-shared-client-and-bump-2.6.2

Conversation

@guytepper
Copy link
Copy Markdown
Member

@guytepper guytepper commented May 5, 2026

  • PostHog stopped receiving events after the v4.9 → v4.39 SDK upgrade because two clients were being instantiated against the same persistence store: a standalone new PostHog(...) in services/analytics and another via <PostHogProvider apiKey=... options=...> in root-navigator. They raced on the shared queue and opt-in/out state.
  • Fix: pass the standalone client directly to the provider (<PostHogProvider client={posthog} ...>) so events, identify, screen tracking, and feature flags all share one instance.
  • Upgrade posthog-react-native to 4.44.1 and posthog-react-native-session-replay to 1.5.6, both pinned (no caret).

Share a single PostHog client between the standalone instance and
PostHogProvider so they no longer race on persistence. Upgrade
posthog-react-native to 4.44.1 and posthog-react-native-session-replay
to 1.5.6 (both pinned). Bump app version to 2.6.2.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the PostHog SDK to version 4.44.1 and refactors its integration by passing a configured client instance to the PostHogProvider. Additionally, the application version is bumped to 2.6.2 across Android and iOS configurations, and dependency versions are pinned in package.json. Feedback suggests externalizing the hardcoded PostHog host URL to environment variables to facilitate configuration across different environments.

Comment on lines +7 to +12
export const posthog = new PostHog(POSTHOG_API_KEY, {
host: "https://eu.i.posthog.com",
persistence: "file" as const,
persistence: "file",
customStorage: AsyncStorage,
enableSessionReplay: true
}

export const posthog = new PostHog(POSTHOG_API_KEY, posthogOptions)
enableSessionReplay: true,
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better configuration management and to avoid hardcoded URLs, consider moving the PostHog host URL to your environment variables file (.env), similar to how POSTHOG_API_KEY is handled. This makes it easier to switch between different PostHog environments (e.g., development, staging, production) or regions if needed in the future.

Here is a potential implementation:

  1. Add POSTHOG_HOST=https://eu.i.posthog.com to your .env file.
  2. Update the import in this file to include POSTHOG_HOST.
  3. Update the posthog initialization to use the new environment variable:
export const posthog = new PostHog(POSTHOG_API_KEY, {
  host: POSTHOG_HOST,
  persistence: "file",
  customStorage: AsyncStorage,
  enableSessionReplay: true,
});

usePostHog() was being called in RootNavigator itself, outside the
PostHogProvider it renders. The hook returned no client, so the
screen() calls in onReady/onStateChange were silent no-ops. Use the
imported singleton directly.
@guytepper
Copy link
Copy Markdown
Member Author

/publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant