Cordova plugin for Segment mobile SDK
This version of the plugin uses versions 3.6.9
(iOS) and 4.3.0
(Android) of the Segment mobile SDK.
You can view Android and iOS SDK sources on Github.
- https://github.com/segmentio/analytics-android
- https://github.com/segmentio/analytics-ios
Prerequisites:
- Segment API keys
You can install the latest version of the plugin directly from git through the Cordova CLI:
cordova plugin add https://github.com/jamesyoon11/segment-cordova-plugin.git
In your 'deviceready' handler, start Segment Analytics :
window.Segment.startWithConfiguration(IOS_OR_ANDROID_KEY);
To track a Screen :
window.Segment.screen({
name: 'Home',
properties: {
'path': '/home'
}
});
To track an Event:
window.Segment.track({
event: 'Order Completed',
properties: {
'revenue': 10
}
});
To track an Identity:
window.Segment.identity({
userId: 'segment_sdk_user',
traits: {
birthday: '2000-01-01'
}
});
You can configure number of options to setup SDK.
Record certain application lifecycle events like Application Opened
, Application Installed
, Application Updated
. (Default: false)
Record screen views automatically. It's not useful for the Cordova PhoneGap app. (Default: false)
Specify which integrations should be enabled or not for all calls. (Default: All)
Record attribution data from enabled providers using the mobile service. (Default: false)
The queue size at which to flush events. (Default: 20, Max: 250 for Android and 100 for iOS)
Record the device id. (Default: true)
The interval at which the client should flush events (Default: 30 seconds)
Key for caching. It's used to share different caches across the instances (Default: "analytics_write_key")
Controls the level of logging (Default: INFO)
Use location services. (Default: false)
Record advertising info. (Default: true)
Record bluetooth information. (Default: false)
Record in-app purchases from the App Store. (Default: false)
Record push notifications. (Default: false)
Example Usage:
window.Segment.startWithConfiguration(IOS_OR_ANDROID_KEY, {
trackApplicationLifecycleEvents: true,
trackAttributionInformation: true,
flushInterval: 60,
trackInAppPurchases: true
});