The hassle-free way to add analytics to your React-Native app.
Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.
- Collect analytics data from your app(s).
- The top 200 Segment companies collect data from 5+ source types (web, mobile, server, CRM, etc.).
- Send the data to analytics tools (for example, Google Analytics, Amplitude, Mixpanel).
- Over 250+ Segment companies send data to eight categories of destinations such as analytics tools, warehouses, email marketing and remarketing systems, session recording, and more.
- Explore your data by creating metrics (for example, new signups, retention cohorts, and revenue generation).
- The best Segment companies use retention cohorts to measure product market fit. Netflix has 70% paid retention after 12 months, 30% after 7 years.
Segment collects analytics data and allows you to send it to more than 250 apps (such as Google Analytics, Mixpanel, Optimizely, Facebook Ads, Slack, Sentry) just by flipping a switch. You only need one Segment code snippet, and you can turn integrations on and off at will, with no additional code. Sign up with Segment today.
-
Power all your analytics apps with the same data. Instead of writing code to integrate all of your tools individually, send data to Segment, once.
-
Install tracking for the last time. We're the last integration you'll ever need to write. You only need to instrument Segment once. Reduce all of your tracking code and advertising tags into a single set of API calls.
-
Send data from anywhere. Send Segment data from any device, and we'll transform and send it on to any tool.
-
Query your data in SQL. Slice, dice, and analyze your data in detail with Segment SQL. We'll transform and load your customer behavioral data directly from your apps into Amazon Redshift, Google BigQuery, or Postgres. Save weeks of engineering time by not having to invent your own data warehouse and ETL pipeline.
For example, you can capture data on any app:
analytics.track('Order Completed', { price: 99.84 })
Then, query the resulting data in SQL:
select * from app.order_completed order by price desc
- CocoaPods (recommended)
- Don't have CocoaPods setup? Follow these instructions.
- or manually install
Analytics
$ yarn add @segment/analytics-react-native
$ yarn react-native link
See the API docs for more details.
import analytics from '@segment/analytics-react-native'
import Mixpanel from '@segment/analytics-react-native-mixpanel'
import GoogleAnalytics from '@segment/analytics-react-native-google-analytics'
analytics
.setup('writeKey', {
using: [Mixpanel, GoogleAnalytics],
recordScreenViews: true,
trackAppLifecycleEvents: true,
trackAttributionData: true,
android: {
flushInterval: 60,
collectDeviceId: true
},
ios: {
trackAdvertising: true,
trackDeepLinks: true
}
})
.then(() =>
console.log('Analytics is ready')
)
.catch(err =>
console.error('Something went wrong', err)
)
analytics.track('Pizza Eaten')
analytics.screen('Home')
There are two ways to send data to your analytics services through this library:
Note: Refer to the specific destinationβs docs to see if your tool must be bundled in the app or sent server-side.
When an destinationβs SDK is not packaged, but it is enabled via your dashboard, the request goes through the Segment REST API, and is routed to the serviceβs server-side API as described here.
By default, our @segment/analytics-react-native
packages does not contain any device-based destinations.
We recommend using device-based destinations on a need-to-use basis to reduce the size of your application, and avoid running into the dreaded 65k method limit on Android.
If you would like to package device-based destinations, first search for the dependency you need using the list below.
You'll need to run react-native link
and add it in the .using()
configuration method. Example using Google Analytics :
$ yarn add @segment/analytics-react-native-google-analytics
$ yarn react-native link
In your code :
import analytics from '@segment/analytics-react-native'
import GoogleAnalytics from '@segment/analytics-react-native-google-analytics'
await analytics.setup('writeKey', {
using: [GoogleAnalytics]
})
All integrations have the same version as
@segment/analytics-react-native
Name | iOS | Android | npm package |
---|---|---|---|
Adjust | β | β | @segment/analytics-react-native-adjust |
Amplitude | β | β | @segment/analytics-react-native-amplitude |
Appboy | β | β | @segment/analytics-react-native-appboy |
AppsFlyer | β | β | @segment/analytics-react-native-appsflyer |
Branch | β | β | @segment/analytics-react-native-branch |
Bugsnag | β | β | @segment/analytics-react-native-bugsnag |
ComScore | β | β | @segment/analytics-react-native-comscore-ios |
Countly | β | β | @segment/analytics-react-native-countly |
Crittercism | β | β | @segment/analytics-react-native-crittercism |
Facebook App Events | β | β | @segment/analytics-react-native-facebook-app-events-ios |
Firebase | β | β | @segment/analytics-react-native-firebase |
Flurry | β | β | @segment/analytics-react-native-flurry |
Google Analytics | β | β | @segment/analytics-react-native-google-analytics |
Intercom | β | β | @segment/analytics-react-native-intercom |
Localytics | β | β | @segment/analytics-react-native-localytics |
Mixpanel | β | β | @segment/analytics-react-native-mixpanel |
Quantcast | β | β | @segment/analytics-react-native-quantcast-android |
Taplytics | β | β | @segment/analytics-react-native-taplytics-ios |
Tapstream | β | β | @segment/analytics-react-native-tapstream-android |
We highly recommend using Cocoapods.
However, if you cannot use Cocoapods, you can manually install our dynamic framework allowing you to send data to Segment and on to enabled cloud-mode destinations. We do not support sending data to bundled, device-mode integrations outside of Cocoapods.
Here are the steps for installing manually:
- Add
analytics-ios
as a npm dependency:yarn add @segment/analytics-ios@github:segmentio/analytics-ios#3.6.10
- In the
General
tab for your project, search forEmbedded Binaries
and add theAnalytics.framework
Please note, if you are choosing to not use a dependency manager, you must keep files up-to-date with regularly scheduled, manual updates.
If you're getting a Failed to load [...] native module
error, it means that some native code hasn't been injected to your native project.
If you're using Cocoapods, check that your ios/Podfile
file contains the right pods :
Failed to load Analytics native module
, look for the core native module:pod 'RNAnalytics', :path => '../node_modules/@segment/analytics-react-native'
Failed to load [...] integration native module
, look for the integration native module, example with Google Analytics:pod 'RNAnalyticsIntegration-Google-Analytics', :path => '../node_modules/@segment/analytics-react-native-google-analytics'
Also check that your Podfile
is synchronized with your workspace, run pod install
in your ios
folder.
If you're not using Cocoapods please check that you followed the iOS support without CocoaPods instructions carefully.
Check that android/app/src/main/.../MainApplication.java
contains a reference to the native module:
-
Failed to load Analytics native module
, look for the core native module:import com.segment.analytics.reactnative.core.RNAnalyticsPackage; // ... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), // ... new RNAnalyticsPackage() ); }
-
Failed to load [...] integration native module
, look for the integration native module, example with Google Analytics:import com.segment.analytics.reactnative.integration.google.analytics.RNAnalyticsIntegration_Google_AnalyticsPackage; // ... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), // ... new RNAnalyticsIntegration_Google_AnalyticsPackage() ); }