Skip to content

chore: upgrade Expo app and make it use navigation#1784

Merged
daniel-graham-amplitude merged 6 commits into
mainfrom
SDK-45-react-native-autocapture-hacking
Jun 3, 2026
Merged

chore: upgrade Expo app and make it use navigation#1784
daniel-graham-amplitude merged 6 commits into
mainfrom
SDK-45-react-native-autocapture-hacking

Conversation

@daniel-graham-amplitude
Copy link
Copy Markdown
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude commented Jun 2, 2026

Summary

Screenshot 2026-06-03 at 8 03 49 AM

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

Note

Low Risk
Changes are confined to the Expo example app and its build/config; no production SDK or auth/data-path changes.

Overview
Upgrades the examples/react-native/expo-app sample to React Native 0.71.14, links @amplitude/analytics-react-native via workspace:*, and replaces the single-screen demo with a React Navigation native stack (Home ↔ Settings) for manual screen-transition testing.

Monorepo / tooling: Adds a local .npmrc (hoisted node_modules + hoist patterns for Metro/Gradle), extends metro.config.js to watch linked packages under packages/ and pin react/react-native to the app’s copies, and inlines AMPLITUDE_API_KEY at bundle time via Babel. Amplitude init now reads that env var (fallback placeholder), uses Types.LogLevel.Error, and sends a renamed test event.

Android (RN 0.71): Switches Gradle deps from react-native to react-android, adds react-android substitution and Kotlin classpath, bumps the wrapper to Gradle 7.6.4, and sets pickFirsts for overlapping native .so files.

Reviewed by Cursor Bugbot for commit 3f39d58. Bugbot is set up for automated code reviews on this repo. Configure here.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 2, 2026

SDK-45

@daniel-graham-amplitude daniel-graham-amplitude marked this pull request as draft June 2, 2026 00:46
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 58.38 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 132.01 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 209.43 KB (0%)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Upgrades the examples/react-native/expo-app Expo example to a newer Expo/RN baseline and wires it to the monorepo workspace SDK packages, adding React Navigation to exercise screen changes and updating Metro/Android tooling to support workspace linking.

Changes:

  • Upgrade Expo app dependencies (Expo SDK 48 / React Native 0.71) and switch Amplitude deps to workspace:* packages.
  • Add React Navigation stack (Home/Settings) and update Amplitude initialization/autocapture configuration.
  • Adjust Metro + pnpm + Android Gradle configuration for monorepo/workspace + RN 0.71 (react-android) compatibility.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
examples/react-native/expo-app/tsconfig.json Adds path mapping for workspace packages and updates include/exclude.
examples/react-native/expo-app/react-native.config.js Adds RN CLI Android platform command/config wiring.
examples/react-native/expo-app/pnpm-workspace.yaml Declares a local pnpm workspace including repo packages/*.
examples/react-native/expo-app/package.json Upgrades Expo/RN deps, adds React Navigation, switches Amplitude deps to workspace:*.
examples/react-native/expo-app/metro.config.js Watches specific workspace packages and forces app react/react-native resolution.
examples/react-native/expo-app/babel.config.js Inlines AMPLITUDE_API_KEY at bundle time via Babel plugin.
examples/react-native/expo-app/App.tsx Adds navigation screens and updates Amplitude init + plugin registration.
examples/react-native/expo-app/android/gradle/wrapper/gradle-wrapper.properties Bumps Gradle wrapper version.
examples/react-native/expo-app/android/gradle.properties Adds pickFirsts to resolve overlapping native libs.
examples/react-native/expo-app/android/build.gradle Switches force/substitution to react-android and sets Kotlin plugin version.
examples/react-native/expo-app/android/app/build.gradle Switches dependency from react-native:+ to react-android.
examples/react-native/expo-app/.npmrc Uses hoisted node linker + hoist patterns for Metro/Gradle compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/react-native/expo-app/App.tsx Outdated
Comment thread examples/react-native/expo-app/App.tsx
Comment thread examples/react-native/expo-app/App.tsx Outdated
Comment thread examples/react-native/expo-app/tsconfig.json
@Mercy811
Copy link
Copy Markdown
Contributor

Mercy811 commented Jun 3, 2026

Hi @daniel-graham-amplitude, could you share a screenshot of the app to confirm it can be successfully built? Thanks!

@daniel-graham-amplitude
Copy link
Copy Markdown
Collaborator Author

@Mercy811 added it to the description, thanks for the suggestion!

Copy link
Copy Markdown
Contributor

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

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

Thanks Dan, Lgtm!

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Browser plugin misses navigation
    • Replaced the browser page-view plugin in the Expo app with React Navigation route-change tracking that emits page-view events on native screens.

Create PR

Or push these changes by commenting:

@cursor push e77b402fdb
Preview (e77b402fdb)
diff --git a/examples/react-native/expo-app/App.tsx b/examples/react-native/expo-app/App.tsx
--- a/examples/react-native/expo-app/App.tsx
+++ b/examples/react-native/expo-app/App.tsx
@@ -1,14 +1,25 @@
-import {StatusBar} from 'expo-status-bar';
-import {Button, StyleSheet, Text, View} from 'react-native';
-import {useEffect} from 'react';
-import {identify, Identify, init, track, add, Types} from '@amplitude/analytics-react-native';
-import { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser';
-import { NavigationContainer } from "@react-navigation/native";
-import { createNativeStackNavigator } from "@react-navigation/native-stack";
+import { StatusBar } from 'expo-status-bar';
+import { Button, StyleSheet, Text, View } from 'react-native';
+import { useEffect, useRef } from 'react';
+import { identify, Identify, init, track, Types } from '@amplitude/analytics-react-native';
+import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
+import { createNativeStackNavigator } from '@react-navigation/native-stack';
 
 const Stack = createNativeStackNavigator();
+const PAGE_VIEW_EVENT = '[Amplitude] Page Viewed';
 
-function HomeScreen({ navigation }) {
+const trackPageView = (routeName?: string) => {
+  if (!routeName) {
+    return;
+  }
+
+  track(PAGE_VIEW_EVENT, {
+    '[Amplitude] Page Path': routeName,
+    '[Amplitude] Page Title': routeName,
+  });
+};
+
+function HomeScreen({ navigation }: { navigation: any }) {
   return (
     <View style={styles.container}>
       <Text>Home Screen</Text>
@@ -17,7 +28,7 @@
   );
 }
 
-function SettingsScreen({navigation}: {navigation: any}) {
+function SettingsScreen({ navigation }: { navigation: any }) {
   return (
     <View style={styles.container}>
       <Text>Settings Screen</Text>
@@ -27,23 +38,41 @@
 }
 
 export default function App() {
+  const navigationRef = useNavigationContainerRef();
+  const routeNameRef = useRef<string>();
+
   useEffect(() => {
     (async () => {
-        // AMPLITUDE_API_KEY is inlined at bundle time (see babel.config.js).
-        await init(process.env.AMPLITUDE_API_KEY || 'YOUR_API_KEY', 'react-native-user-id', {
-          logLevel: Types.LogLevel.Error,
-          autocapture: {
-            sessions: true,
-            pageViews: false,
-          },
-        }).promise;
-        add(pageViewTrackingPlugin());
-        track('expo-app/react-native/test-event');
-        await identify(new Identify().set('react-native-test', 'yes')).promise;
+      // AMPLITUDE_API_KEY is inlined at bundle time (see babel.config.js).
+      await init(process.env.AMPLITUDE_API_KEY || 'YOUR_API_KEY', 'react-native-user-id', {
+        logLevel: Types.LogLevel.Error,
+        autocapture: {
+          sessions: true,
+          pageViews: false,
+        },
+      }).promise;
+      track('expo-app/react-native/test-event');
+      await identify(new Identify().set('react-native-test', 'yes')).promise;
     })();
   }, []);
   return (
-    <NavigationContainer>
+    <NavigationContainer
+      ref={navigationRef}
+      onReady={() => {
+        const currentRouteName = navigationRef.getCurrentRoute()?.name;
+        routeNameRef.current = currentRouteName;
+        trackPageView(currentRouteName);
+      }}
+      onStateChange={() => {
+        const previousRouteName = routeNameRef.current;
+        const currentRouteName = navigationRef.getCurrentRoute()?.name;
+
+        if (currentRouteName && currentRouteName !== previousRouteName) {
+          trackPageView(currentRouteName);
+        }
+        routeNameRef.current = currentRouteName;
+      }}
+    >
       <Stack.Navigator>
         <Stack.Screen name="Home" component={HomeScreen} />
         <Stack.Screen name="Settings" component={SettingsScreen} />

diff --git a/examples/react-native/expo-app/package.json b/examples/react-native/expo-app/package.json
--- a/examples/react-native/expo-app/package.json
+++ b/examples/react-native/expo-app/package.json
@@ -10,7 +10,6 @@
   },
   "dependencies": {
     "@amplitude/analytics-react-native": "workspace:*",
-    "@amplitude/plugin-page-view-tracking-browser": "workspace:*",
     "@babel/runtime": "^7.20.0",
     "@react-native-async-storage/async-storage": "~1.17.11",
     "@react-navigation/native": "^6.1.18",

diff --git a/examples/react-native/expo-app/pnpm-lock.yaml b/examples/react-native/expo-app/pnpm-lock.yaml
--- a/examples/react-native/expo-app/pnpm-lock.yaml
+++ b/examples/react-native/expo-app/pnpm-lock.yaml
@@ -11,9 +11,6 @@
       '@amplitude/analytics-react-native':
         specifier: workspace:*
         version: link:../../../packages/analytics-react-native
-      '@amplitude/plugin-page-view-tracking-browser':
-        specifier: workspace:*
-        version: link:../../../packages/plugin-page-view-tracking-browser
       '@babel/runtime':
         specifier: ^7.20.0
         version: 7.28.6

You can send follow-ups to the cloud agent here.

Comment thread examples/react-native/expo-app/App.tsx Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Autocapture sessions option ineffective
    • Replaced the unsupported React Native example autocapture sessions setting with trackingSessionEvents so session lifecycle events are enabled.

Create PR

Or push these changes by commenting:

@cursor push 3c54cde182

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 707600d. Configure here.

Comment thread examples/react-native/expo-app/App.tsx Outdated
@daniel-graham-amplitude daniel-graham-amplitude enabled auto-merge (squash) June 3, 2026 17:29
@daniel-graham-amplitude daniel-graham-amplitude merged commit 8809348 into main Jun 3, 2026
13 checks passed
@daniel-graham-amplitude daniel-graham-amplitude deleted the SDK-45-react-native-autocapture-hacking branch June 3, 2026 17:29
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.

3 participants