Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

analytics-react-native

> 编程语言
Open source

The hassle-free way to add analytics to your React-Native app.

384 stars0 likes0 views
WebsiteGitHub

About

The hassle-free way to add analytics to your React-Native app.

@segment/analytics-react-native

Flagship

This library is one of Segment’s most popular Flagship libraries. It is actively maintained by Segment, benefitting from new feature releases and ongoing support.

The hassle-free way to add Segment analytics to your React-Native app.

⚠️ This readme covers analytics-react-native 2.0.0 and greater. The code and readme for analytics-react-native versions below 2.0.0 can be found on the analytics-react-native-v1 branch. On May 15, 2023, Segment will end support for Analytics React Native Classic, which includes versions 1.5.1 and older. Upgrade to Analytics React Native 2.0.

Table of Contents

  • Installation
  • Migrating
  • Usage
  • Client methods
  • Automatic screen tracking
  • Consent Management
  • Plugins + Timeline architecture
  • Controlling Upload With Flush Policies
  • Handling errors
  • Contributing
  • License

Installation

Install @segment/analytics-react-native, @segment/sovran-react-native and react-native-get-random-values:

bash
yarn add @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values @react-native-async-storage/async-storage
# or
npm install --save @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values @react-native-async-storage/async-storage

Note: @react-native-async-storage/async-storage is an optional dependency. If you wish to use your own persistence layer you can use the storePersistor option when initializing the client. Make sure you always have a persistor (either by having AsyncStorage package installed or by explicitly passing a value), else you might get unexpected side-effects like multiple 'Application Installed' events. Read more Client Options

For iOS, install native modules with:

bash
npx pod-install

⚠️ For Android, you will have to add some extra permissions to your AndroidManifest.xml.

Expo

@segment/analytics-react-native 2.0 is compatible with Expo's Custom Dev Client and EAS builds without any additional configuration. Destination Plugins that require native modules may require custom Expo Config Plugins.

⚠️ @segment/analytics-react-native 2.0 is not compatible with Expo Go.

Permissions

Android In your app's AndroidManifest.xml add the below line between the `` tags.

xml

Migrating

See the Migration Guide for a detailed walkthrough of the changes you will need to make when upgrading to analytics-react-native 2.0

Usage

Setting up the client

The package exposes a method called createClient which we can use to create the Segment Analytics client. This central client manages all our tracking events.

javascript
import { createClient } from '@segment/analytics-react-native';

const segmentClient = createClient({
  writeKey: 'SEGMENT_API_KEY',
});

You must pass at least the writeKey. Additional configuration options are listed below:

Client Options

Name Default Description
writeKey (REQUIRED) '' Your Segment API key.
collectDeviceId false Set to true to automatically collect the device Id from the DRM API on Android devices.
debug true* When set to false, it will not generate any logs.
logger undefined Custom logger instance to expose internal Segment client logging.
flushAt 20 How many events to accumulate before sending events to the backend.
flushInterval 30 In seconds, how often to send events to the backend.
flushPolicies undefined Add more granular control for when to flush, see Adding or removing policies. Mutually exclusive with flushAt/flushInterval
maxBatchSize 1000 How many events to send to the API at once
trackAppLifecycleEvents false Enable automatic tracking for app lifecycle events: application installed, opened, updated, backgrounded.
trackDeepLinks false Enable automatic tracking for when the user opens the app via a deep link (Note: Requires additional setup on iOS, see instructions).
defaultSettings undefined Settings that will be used if the request to get the settings from Segment fails. Type: SegmentAPISettings
autoAddSegmentDestination true Set to false to skip adding the SegmentDestination plugin.
storePersistor undefined A custom persistor for the store that analytics-react-native leverages. Must match Persistor interface exported from sovran-react-native.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言