Skip to content

fix(analytics): keep serverURL set during JavaScript-mode init - #483

Draft
rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-248-react-native-314-initialization
Draft

rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-248-react-native-314-initialization

Conversation

@rahul-mixpanel

@rahul-mixpanel rahul-mixpanel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In JavaScript mode (useNative: false, Expo, React Native Web), MixpanelMain.initialize() applied its serverURL only after awaiting storage. That caused two problems:

  1. If init() isn't awaited, a setServerURL() call made right after it is overwritten by init's default (https://api.mixpanel.com). This is what Mixpanel client initializes twice with default settings and overwrites my settings #314 reports: an EU project's events go to the US host.
  2. With optOutTrackingDefault = true, initialize() returned before setting serverURL, so after optInTracking() events went to the default US host instead of the URL passed to init().

Native mode already applies serverURL at init in both cases: Android MixpanelReactNativeModule.java:79-81 sets it on MixpanelOptions next to optOutTrackingDefault, and iOS MixpanelReactNative.swift:58 does the same.

The fix applies serverURL before the first await. What changes for callers:

  • If init() is awaited, the behaviour is the same as before.
  • setServerURL() called before init() is still overwritten by init's value, as it was before.
  • Behaviour change for one group: JS-mode users with optOutTrackingDefault = true and an EU, IN or proxy serverURL in init() now send to that host after optInTracking(). Before, they sent to the default US host. This matches native mode.

The JS-mode race on super properties registered before an un-awaited init() resolves is out of scope here. It is noted on the Linear ticket.

Tests

  • Two new tests in __tests__/main.test.js. Both fail without the fix.
  • Full suite: 530 passed, 4 skipped.

Related to #314

🤖 Generated with Claude Code

In JavaScript mode, init() applied its serverURL only after awaiting
storage. A setServerURL() call made right after an un-awaited init() was
overwritten by init's default, and with optOutTrackingDefault=true the
serverURL was never applied, so events went to the US host after
optInTracking(). Native mode already applies serverURL at init in both
cases.

Apply serverURL before the first await instead.

Related to #314

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

SDK-248

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (2) · Last reviewed commit: "test(analytics): reword serverURL opt-ou..." · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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