feat(analytics): add trackScreenView and trackScreenLeave public APIs#439
Open
rahul-mixpanel wants to merge 4 commits into
Open
Conversation
…ccessor Add new Autocapture class exposing trackScreenView and trackScreenLeave methods, matching the native Android/Swift SDK pattern (mixpanel.autocapture.trackScreenView/trackScreenLeave). - JS API: new Autocapture class with lazy getter on Mixpanel - TypeScript definitions for Autocapture class - Android bridge: delegates to instance.getAutocapture() - iOS bridge: delegates to instance.autocapture - JS-mode fallback: pure JS implementation - Sample app: NavigationContainer onStateChange tracking Ref: SDK-119
The autocapture getter was incorrectly placed between the flush() JSDoc comment and the flush() method. Moved it next to the flags getter for proper code organization.
…layer These properties are already set by the native SDK in getAutocapture().trackScreenView/trackScreenLeave. Only the JS-mode fallback (mixpanel-main.js) needs to set them since it bypasses native.
…ew race condition Add defensive null checks around getAutocapture() in Android bridge to prevent potential NPE. Fix sample app to handle the case where Mixpanel initializes after the navigation container mounts, ensuring the initial screen view event is always tracked. Also fix Metro config to allow SDK dependencies (json-logic-js, base-64) through the parent blockList.
rahul-mixpanel
marked this pull request as ready for review
July 17, 2026 10:48
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
mixpanel.autocapture.trackScreenView(screenName, properties?)andmixpanel.autocapture.trackScreenLeave(screenName, properties?)public APIs, mirroring the native Android/Swift SDK interfacesgetAutocapture().trackScreenView/trackScreenLeave) and iOS (autocapture.trackScreenView/trackScreenLeave)mixpanel-main.jsfor Expo/web environments (tracks$mp_page_view/$mp_page_leavewithcurrent_page_titleand$mp_autocaptureproperties)MixpanelStarter) with navigation-based screen tracking usingonReadyandonStateChangeChanges
index.js— NewAutocaptureclass with lazy getter onMixpanelindex.d.ts— TypeScript definitions forAutocaptureclassandroid/.../MixpanelReactNativeModule.java—trackScreenViewandtrackScreenLeavebridge methodsios/MixpanelReactNative.swift— Swift bridge implementationsios/MixpanelReactNative.m— ObjC extern method declarationsjavascript/mixpanel-main.js— JS-mode fallback implementationSamples/MixpanelStarter/src/App.tsx— Sample app screen trackingTest plan
$mp_page_viewand$mp_page_leaveevents fire on tab navigationcurrent_page_titleand$mp_autocaptureproperties are set by native SDK (not duplicated in JS layer)Closes SDK-119