yarn add react-native-analytics-segment-io
react-native link react-native-analytics-segment-io
Add Analytics
framework to your Podfile.
pod 'Analytics'
To add an integration with a Device-based Connection Mode, you must manually add that integration’s dependencies to the Podfile.
pod 'Segment-Mixpanel'
pod 'Segment-GoogleAnalytics'
The wrapper will automatically register the added components in the configuration when the SDK is initialized.
Supported integrations:
Component | Podfile |
---|---|
Taplytics | pod 'Segment-Taplytics' |
Adjust | pod 'Segment-Adjust' |
Google Analytics | pod 'Segment-GoogleAnalytics' |
ComScore | pod 'Segment-ComScore' |
Amplitude | pod 'Segment-Amplitude' |
Facebook App Events | pod 'Segment-Facebook-App-Events' |
Mixpanel | pod 'Segment-Mixpanel' |
Localytics | pod 'Segment-Localytics' |
Flurry | pod 'Segment-Flurry' |
Quantcast | pod 'Segment-Quantcast' |
Crittercism | pod 'Segment-Crittercism' |
Firebase | pod 'Segment-Firebase' |
Run react-native link react-native-analytics-segment-io
to add the necessary lines to the build files. Alternatively, you can do this manually with the 2 following steps:
- Add a reference to the project in
settings.gradle
:
include ':react-native-analytics-segment-io'
project(':react-native-analytics-segment-io').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-analytics-segment-io/android')
- Add the dependency to the app's
build.gradle
file:
compile project(':react-native-analytics-segment-io')
When the build files are set up to include the library, add a dependency to the Segment SDK in the app's build.gradle
file:
compile 'com.segment.analytics.android:analytics:x.x.x' // We have tested with version 4.2.6
Then sync Gradle, and add the analytics package to your Application
class:
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AnalyticsPackage()
);
}
Your project is now ready to start calling functions on react-native-analytics-segment-io.
The enable()
and disable()
methods are not available in the Segment SDK for Android, so they are not included in the Android version of this library.
The Segment SDK is added to the library as a provided
dependency, meaning that it is not included in the final build. That is why it is necessary to include the Segment SDK in the app's build.gradle
file. This makes it easy to update the Segment SDK from the app, and it makes the app's build configuration the source of truth when it comes to Segment.
It is required to use React Native v0.46.4 or higher. This is because we use a feature in Java on the passed maps (.toHashMap()
) that is introduced in that version.
To add an integration with a Device-based destination, you have to manually add that integration as a dependency to the app's build.gradle
file.
For example:
compile 'com.segment.analytics.android.integrations:firebase:1.1.0'
compile 'com.segment.analytics.android.integrations:mixpanel:1.1.0'
The wrapper will automatically register the added components in the configuration when the SDK is present.
Supported integrations:
Component | Dependency |
---|---|
AppsFlyer | com.appsflyer:segment-android-integration:1.9 |
Adjust | com.segment.analytics.android.integrations:adjust:0.3.1 |
Amplitude | com.segment.analytics.android.integrations:amplitude:1.2.1 |
Bugsnag | com.segment.analytics.android.integrations:bugsnag:1.0.0 |
ComScore | com.segment.analytics.android.integrations:comscore:3.0.0 |
Countly | com.segment.analytics.android.integrations:countly:1.0.0 |
Crittercism | com.segment.analytics.android.integrations:crittercism:1.0.0 |
Firebase | com.segment.analytics.android.integrations:firebase:1.1.0 |
Google Analytics | com.segment.analytics.android.integrations:google-analytics:2.0.0 |
Localytics | com.segment.analytics.android.integrations:Localytics |
Mixpanel | com.segment.analytics.android.integrations:mixpanel:1.1.0 |
NielsenDCR | com.segment.analytics.android.integrations:nielsendcr:1.0.0-Beta |
Quantcast | com.segment.analytics.android.integrations:quantcast:1.0.1 |
Tapstream | com.segment.analytics.android.integrations:tapstream:1.0.0 |
import Analytics from 'react-native-analytics-segment-io'
- Analytics.setup(key, options)
- Analytics.identify(userId, traits)
- Analytics.track(event, properties)
- Analytics.screen(name, properties)
- Analytics.group(groupId, traits)
- Analytics.alias(newId)
- Analytics.reset()
- Analytics.flush()
- Analytics.enable()
- Analytics.disable()
Initial framework setup
Analytics.setup('segment_write_key', { enableAdvertisingTracking: true })
setup()
returns a promise to indicate whether the initialization was successful or not.
Supported options:
Options | Type | Default | Description |
---|---|---|---|
enableAdvertisingTracking | Bool | false |
Whether the analytics client should track advertisting info. |
flushAt | Integer | 20 |
The number of queued events that the analytics client should flush at. Setting this to 1 will not queue any events and will use more battery. |
recordScreenViews | Bool | false |
Whether the analytics client should automatically make a screen call when a view controller is added to a view hierarchy. |
shouldUseBluetooth | Bool | false |
Whether the analytics client should record bluetooth information. |
shouldUseLocationServices | Bool | false |
Whether the analytics client should use location services. |
trackApplicationLifecycleEvents | Bool | false |
Whether the analytics client should automatically make a track call for application lifecycle events, such as "Application Installed", "Application Updated" and "Application Opened". |
trackAttributionData | Bool | false |
Whether the analytics client should automatically track attribution data from enabled providers using the mobile service. |
trackDeepLinks | Bool | false |
Whether the analytics client should automatically track deep links. |
Tie a user to their actions and record traits about them
Analytics.identify('user_id', { email: 'user_email' })
Futher explanation can be found on Segments own page.
Record the actions your users performs
Analytics.track('Weapon Bought', { weapon: 'sword' })
Futher explanation can be found on Segments own page.
Record whenever a user sees a screen
Analytics.track('Photo Screen', { feed: 'private' })
Futher explanation can be found on Segments own page.
Associate an identified user user with a group
Analytics.group('Group123', {name: 'Bob Group', description: 'Accounting Awesome'})
Futher explanation can be found on Segments own page.
Associate one user identity with another
Analytics.alias('new_id')
Futher explanation can be found on Segments own page.
Clears the SDK’s internal stores for the current user and group
Analytics.reset()
Futher explanation can be found on Segments own page.
Manually flush the queue
Analytics.flush()
Futher explanation can be found on Segments own page.
You may need to offer the ability for users to opt-out of analytics
Analytics.enable()
Futher explanation can be found on Segments own page.
You may need to offer the ability for users to opt-out of analytics
Analytics.disable()
Futher explanation can be found on Segments own page.
MIT