Documentation

Hey friend! We are co-hosting a conference with Software Mansion, learn more.

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.

To access the Segment module just import it from Expo:
import { Segment } from 'expo';

Segment requires separate write keys for iOS and Android. You will need to log in to Segment to recieve these https://segment.com/docs/guides/setup/how-do-i-find-my-write-key/

Accepts an object with the following keys:
  • androidWriteKey (string) – Write key for Android source.
  • iosWriteKey (string) – Write key for iOS source.

Associates the current user with a user ID. Call this after calling Segment.initialize() but before other segment calls. See https://segment.com/docs/spec/identify/.

  • userId (string) – User ID for the current user.

<!– Associates the current user with a user ID and some metadata. Call this after calling Segment.initialize() but before other segment calls. See https://segment.com/docs/spec/identify/. –>

  • userId (string) – User ID for the current user.
  • traits (object) – A map of custom properties.

Log an event to Segment. See https://segment.com/docs/spec/track/.

  • event (string) – The event name.

Log an event to Segment with custom properties. See https://segment.com/docs/spec/track/.

  • event (string) – The event name.
  • properties (object) – A map of custom properties.

Associate the user with a group. See https://segment.com/docs/spec/group/.

  • groupId (string) – ID of the group.

Associate the user with a group with traits. See https://segment.com/docs/spec/group/.

  • groupId (string) – ID of the group.
  • traits (object) – free-form dictionary of traits of the group.

Associate current identity with a new identifier. See https://segment.com/docs/spec/alias/.

  • newId (string) – Identifier to associate with.
  • options (object)(optional) extra dictionary with options for the call. You could pass a dictionary of form { [integrationKey]: { enabled: boolean, options: object } } to configure destinations of the call.

  • A Promise resolving to a boolean indicating whether the method has been executed on the underlying Segment instance or not.

Record that a user has seen a screen to Segment. See https://segment.com/docs/spec/screen/.

  • screenName (string) – Name of the screen.

Record that a user has seen a screen to Segment with custom properties. See https://segment.com/docs/spec/screen/.
  • screenName (string) – Name of the screen.
  • properties (object) – A map of custom properties.

Manually flush the event queue. You shouldn't need to call this in most cases.

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 { Segment } from 'expo';

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 Client 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.