Repository navigation
fix(analytics): keep serverURL set during JavaScript-mode init - #483
Draft
rahul-mixpanel wants to merge 2 commits into
Draft
rahul-mixpanel wants to merge 2 commits into
rahul-mixpanel wants to merge 2 commits into
Conversation
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>
[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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In JavaScript mode (
useNative: false, Expo, React Native Web),MixpanelMain.initialize()applied itsserverURLonly after awaiting storage. That caused two problems:init()isn't awaited, asetServerURL()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.optOutTrackingDefault = true,initialize()returned before settingserverURL, so afteroptInTracking()events went to the default US host instead of the URL passed toinit().Native mode already applies
serverURLat init in both cases: AndroidMixpanelReactNativeModule.java:79-81sets it onMixpanelOptionsnext tooptOutTrackingDefault, and iOSMixpanelReactNative.swift:58does the same.The fix applies
serverURLbefore the firstawait. What changes for callers:init()is awaited, the behaviour is the same as before.setServerURL()called beforeinit()is still overwritten by init's value, as it was before.optOutTrackingDefault = trueand an EU, IN or proxyserverURLininit()now send to that host afteroptInTracking(). 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
__tests__/main.test.js. Both fail without the fix.Related to #314
🤖 Generated with Claude Code