Deprecated. This module will be removed in SDK 46. There will be no replacement that works with the classic build service (
expo build
) because the classic build service has been superseded by EAS Build. With EAS Build* and development builds, you should use official @segment/analytics-react-native instead.
expo-analytics-segment
provides access to https://segment.com/
mobile analytics. Wraps Segment's iOS and Android sources.
Note: Session tracking may not work correctly when running Experiences in the main Expo app. It will work correctly if you create a standalone app.
Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
-
expo install expo-analytics-segment
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
import * as Segment from 'expo-analytics-segment';
Segment.alias(newId, options)
Name | Type | Description |
---|---|---|
newId | string | Identifier to associate with. |
options (optional) | CommonOptions | An extra dictionary with options for the call, see here for possible configuration options. An example options object would be:
Default: null |
Associate current identity with a new identifier. See Segment Alias docs.
Promise<boolean>
A Promise
which fulfils witch a boolean
indicating whether the method has been
executed on the underlying Segment
instance or not.
Segment.group(groupId)
Name | Type | Description |
---|---|---|
groupId | string | ID of the group. |
Associate the user with a group. See Segment Group docs.
void
Segment.groupWithTraits(groupId, traits, options)
Name | Type | Description |
---|---|---|
groupId | string | ID of the group. |
traits | Record<string, any> | Free-form dictionary of traits of the group. |
options (optional) | CommonOptions | A map that can include any of these common fields.
Defaults to Default: null |
Associate the user with a group with traits. See Segment Group docs.
void
Segment.identify(userId)
Name | Type | Description |
---|---|---|
userId | string | User ID for the current user. |
Associates the current user with a user ID. Call this after calling Segment.initialize()
but before other segment calls. See Segment Identify docs.
void
Segment.identifyWithTraits(userId, traits, options)
Name | Type | Description |
---|---|---|
userId | string | User ID for the current user. |
traits | Record<string, any> | A map of custom properties. |
options (optional) | CommonOptions | Map that can include any of these common fields.
Defaults to Default: null |
void
Segment.initialize(options)
Name | Type | Description |
---|---|---|
options | InitializeOptions | An |
Segment requires separate write keys for iOS and Android. You will need to log in to Segment to receive these keys: https://segment.com/docs/guides/setup/how-do-i-find-my-write-key/
void
Segment.screen(screenName)
Name | Type | Description |
---|---|---|
screenName | string | Name of the screen. |
Record that a user has seen a screen to Segment. See Segment Screen docs.
void
Segment.screenWithProperties(screenName, properties, options)
Name | Type | Description |
---|---|---|
screenName | string | Name of the screen. |
properties | Record<string, any> | A map of custom properties. |
options (optional) | CommonOptions | A map that can include any of these common fields.
Defaults to Default: null |
Record that a user has seen a screen to Segment with custom properties. See Segment Screen docs.
void
Segment.track(event)
Name | Type | Description |
---|---|---|
event | string | The event name. |
Log an event to Segment. See Segment Track docs.
void
Segment.trackWithProperties(event, properties, options)
Name | Type | Description |
---|---|---|
event | string | The event name. |
properties | Record<string, any> | A map of custom properties. |
options (optional) | CommonOptions | A map that can include any of these common fields.
Defaults to Default: null |
Log an event to Segment with custom properties. See Segment Track docs.
void
CommonOptions
Acceptable values are: Record<string, any>
, null
.
InitializeOptions
Name | Type | Description |
---|---|---|
androidWriteKey (optional) | string | Write key for Android source. |
iosWriteKey (optional) | string | Write key for iOS source. |
Depending on the audience for your app (e.g. children) or the countries where you sell your app (e.g. the EU), you may need to offer the ability for users to opt-out of analytics data collection inside your app. You can turn off forwarding to ALL destinations including Segment itself: (Source – Segment docs)
import * as Segment from 'expo-analytics-segment';
Segment.setEnabledAsync(false);
// Or if they opt-back-in, you can re-enable data collection:
Segment.setEnabledAsync(true);
Note: disabling the Segment SDK ensures that all data collection method invocations (eg.
track
,identify
, etc) are ignored.
This method is only supported in standalone and detached apps. In Expo Go the promise will reject.
The setting value will be persisted across restarts, so once you call setEnabledAsync(false)
, Segment won't track the users even when the app restarts. To check whether tracking is enabled, use Segment.getEnabledAsync()
which returns a promise which should resolve to a boolean.