feat(analytics): add trackScreenView and trackScreenLeave public APIs - #439
Merged
rahul-mixpanel merged 10 commits intoJul 21, 2026
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.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new public Autocapture surface to the Mixpanel React Native SDK for screen view/leave tracking, aligning the JS API with native Android/Swift SDK interfaces and providing a JS-mode fallback for Expo/web usage.
Changes:
- Introduces
mixpanel.autocapture.trackScreenView(...)andmixpanel.autocapture.trackScreenLeave(...)as public APIs (JS + TypeScript types). - Implements the corresponding native bridge methods on Android and iOS, plus a JS-mode fallback that emits
$mp_page_view/$mp_page_leave. - Updates the MixpanelStarter sample to track screen view/leave from React Navigation state changes; adjusts Metro config to resolve SDK-only deps from the parent package.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
index.js |
Adds autocapture lazy getter on Mixpanel and the new Autocapture class wrapper that delegates to the active implementation. |
index.d.ts |
Exposes Autocapture and the Mixpanel.autocapture property in TypeScript typings. |
android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java |
Adds React Native bridge methods for trackScreenView / trackScreenLeave using Android SDK autocapture. |
ios/MixpanelReactNative.swift |
Adds Swift bridge implementations for trackScreenView / trackScreenLeave. |
ios/MixpanelReactNative.m |
Exports the new Swift bridge methods to React Native via RCT_EXTERN_METHOD. |
javascript/mixpanel-main.js |
Adds JS-mode fallback that tracks $mp_page_view / $mp_page_leave with current_page_title and $mp_autocapture. |
Samples/MixpanelStarter/src/App.tsx |
Implements navigation-driven screen view/leave tracking via onReady and onStateChange. |
Samples/MixpanelStarter/metro.config.js |
Tweaks Metro resolution/blockList to allow specific parent node_modules deps and map them via extraNodeModules. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…Leave Log via MixpanelLogger.warn when screenName is blank or non-string, matching the logging pattern used across other SDK methods and aligning with the Flutter SDK's validation logging.
Consolidate validation + warning logging for trackScreenView and trackScreenLeave into index.js (public API) and remove redundant checks from mixpanel-main.js, since the impl is only called after validation has already passed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ketanmixpanel
previously approved these changes
Jul 21, 2026
Restore screenName validation in trackScreenView/trackScreenLeave in mixpanel-main.js for defensive safety, but without the MixpanelLogger.warn calls since logging is now handled at the public API layer in index.js. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ketanmixpanel
approved these changes
Jul 21, 2026
rahul-mixpanel
deleted the
rahulraveendran-sdk-119-add-trackscreenview-and-trackscreenleave-public-apis-to
branch
July 21, 2026 09:17
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