Package Exports
- @segment/analytics-react-native
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@segment/analytics-react-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@segment/analytics-react-native
The hassle-free way to add analytics to your React-Native app.
Prerequisite
Android
- Gradle 4+
- Run
./gradlew wrapper --gradle-version=4.4
in yourandroid
folder
- Run
- Build Tools 3+
- Upgrade
com.android.tools.build:gradle
to3.1.4
in yourandroid/build.gradle
file
- Upgrade
iOS
- CocoaPods (recommended)
- or manually install
Analytics
Installation
$ yarn add @segment/analytics-react-native
$ yarn react-native link
Usage
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
.configure()
.using(Mixpanel, GoogleAnalytics)
.recordScreenViews()
.trackAppLifecycleEvents()
.trackAttributionData()
.ios()
.trackAdvertising()
.trackDeepLinks()
.android()
.disableDevicedId()
.setup("writeKey")
.then(() =>
console.log('Analytics is ready')
)
.catch(err =>
console.error('Something went wrong', err)
)
analytics.track('Pizza Eaten')
analytics.screen('Home')
Sending data to destinations
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.
Cloud-based Connection Modes
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.
Packaging Device-based destination SDKs
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
.configure()
.using(GoogleAnalytics)
// ...
.setup('writeKey')
Integrations
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 |
Troubleshooting
iOS support without CocoaPods
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:
- Download the latest built SDK, and unzip the zip file.
- Drag the unzipped Analytics.framework folder into your Xcode project.
Make sure to check
Copy items if needed
. - 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.
Setup CocoaPods in an existing project
Check that
ios/Podfile
doesn't existcd ios
pod init
Open
Podfile
Edit your app
target
to have thesepod
declarations and theAdd new pods below this line
comment :target 'MyReactNativeApp' do pod 'React', :path => '../node_modules/react-native' pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' # Add new pods below this line end
pod install