@segment/analytics-react-native
    TypeScript icon, indicating that this package has built-in type declarations

    1.5.0 • Public • Published

    @segment/analytics-react-native

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

    CircleCI codecov npm

    You can't fix what you can't measure

    Analytics helps you measure your users, product, and business. It unlocks insights into your app's funnel, core business metrics, and whether you have product-market fit.

    How to get started

    1. Collect analytics data from your app(s).
      • The top 200 Segment companies collect data from 5+ source types (web, mobile, server, CRM, etc.).
    2. Send the data to analytics tools (for example, Google Analytics, Amplitude, Mixpanel).
      • Over 250+ Segment companies send data to eight categories of destinations such as analytics tools, warehouses, email marketing and remarketing systems, session recording, and more.
    3. Explore your data by creating metrics (for example, new signups, retention cohorts, and revenue generation).
      • The best Segment companies use retention cohorts to measure product market fit. Netflix has 70% paid retention after 12 months, 30% after 7 years.

    Segment collects analytics data and allows you to send it to more than 250 apps (such as Google Analytics, Mixpanel, Optimizely, Facebook Ads, Slack, Sentry) just by flipping a switch. You only need one Segment code snippet, and you can turn destinations on and off from the Segment web UI, with no additional code. Sign up with Segment today.

    Why?

    1. Power all your analytics apps with the same data. Instead of writing code to integrate all of your tools individually, send data to Segment, once.

    2. Install tracking for the last time. We're the last integration you'll ever need to write. You only need to instrument Segment once. Reduce all of your tracking code and advertising tags into a single set of API calls.

    3. Send data from anywhere. Send Segment data from any device, and we'll transform and send it on to any tool.

    4. Query your data in SQL. Slice, dice, and analyze your data in detail with Segment SQL. We'll transform and load your customer behavioral data directly from your apps into Amazon Redshift, Google BigQuery, or Postgres. Save weeks of engineering time by not having to invent your own data warehouse and ETL pipeline.

      For example, you can capture data on any app:

      analytics.track('Order Completed', { price: 99.84 })

      Then, query the resulting data in SQL:

      select * from app.order_completed
      order by price desc

    🚀 Startup Program

    If you are part of a new startup (<$5M raised, <2 years since founding), we just launched a new startup program for you. You can get a Segment Team plan (up to $25,000 value in Segment credits) for free up to 2 years — apply here!

    Prerequisite

    React-Native

    • Version 0.62 or greater.

    iOS

    Installation

    $ yarn add @segment/analytics-react-native
    $ cd ios && pod install && cd .. # CocoaPods on iOS needs this extra step

    Usage

    See the API docs for more details.

    Additional examples of common usage patterns and how-to's can found at Analytics for React-Native.

    import analytics from '@segment/analytics-react-native'
    import mixpanel from '@segment/analytics-react-native-mixpanel'
    import firebase from '@segment/analytics-react-native-firebase'
    
    analytics
        .setup('writeKey', {
            using: [mixpanel, firebase],
            recordScreenViews: true,
            trackAppLifecycleEvents: true,
    
            android: {
                flushInterval: 60000, // 60 seconds
                collectDeviceId: true
            },
            ios: {
                trackAdvertising: true,
                trackDeepLinks: true
            }
        })
        .then(() =>
            console.log('Analytics is ready')
        )
        .catch(err =>
            console.error('Something went wrong', err)
        )
    
    analytics.track('Pizza Eaten')
    analytics.screen('Home')

    Sending data to destinations

    There are two ways to send data to your analytics services through this library:

    1. Through the Segment servers
    2. Directly from the device using bundled SDK’s

    Note: Refer to the specific destination’s docs to see if your tool must be bundled in the app or sent server-side.

    Cloud-based Connection Modes

    When an destination’s SDK is not packaged, but it is enabled using the Segment web UI, the request goes through the Segment REST API, and is routed to the service’s server-side API as described here.

    Packaging Device-mode Destination SDKs

    By default, our @segment/analytics-react-native package does not contain any device-based destinations.

    We recommend only using device-based destinations on a need-to-use basis to reduce the size of your application, and to avoid running into the dreaded 65k method limit on Android.

    If you would like to package device-based destinations, first search for the dependency you need using the list below. Then run pod install in your ios/ folder and add it in the .using() configuration method. Example using Firebase :

    $ yarn add @segment/analytics-react-native-firebase
    $ cd ios && pod install && cd ..

    In your code :

    import analytics from '@segment/analytics-react-native'
    import firebase from '@segment/analytics-react-native-firebase'
    
    await analytics.setup('writeKey', {
      using: [firebase]
    })

    For IOS you must add the GoogleService-info.plist to your iOS folder. This file can be downloaded from your Firebase instance. Firebase takes up to 24 hours to show events. However, you can utilize the Firebase debug method to confirm your setup is sending data correctly. To do this add -FIRDebugEnabled in Xcode’s Scheme Settings.

    In Xcode: Project -> Scheme -> Edit Scheme -> Arguments Passed On Launch

    Supported Device-Mode Destinations

    All destinations have the same version as @segment/analytics-react-native

    Note: Each device-mode destination has a different native setup procedure due to differences between the underlying SDK vendors. Please refer to the vendor documentation for configuring the native iOS and Android portions of a given destination. More information and links to vendor specific instructions and details can be found at Connection Mode Comparisons.

    Name iOS Android npm package
    Adjust @segment/analytics-react-native-adjust
    Amplitude @segment/analytics-react-native-amplitude
    Appboy @segment/analytics-react-native-appboy
    AppsFlyer @segment/analytics-react-native-appsflyer
    Branch @segment/analytics-react-native-branch
    Bugsnag @segment/analytics-react-native-bugsnag
    CleverTap @segment/analytics-react-native-clevertap
    ComScore @segment/analytics-react-native-comscore-ios
    Countly @segment/analytics-react-native-countly
    Crittercism @segment/analytics-react-native-crittercism
    Facebook App Events @segment/analytics-react-native-facebook-app-events-ios
    Firebase @segment/analytics-react-native-firebase
    Flurry @segment/analytics-react-native-flurry
    Intercom @segment/analytics-react-native-intercom
    Localytics @segment/analytics-react-native-localytics
    Mixpanel @segment/analytics-react-native-mixpanel
    Quantcast @segment/analytics-react-native-quantcast-android
    Taplytics @segment/analytics-react-native-taplytics-ios
    Tapstream @segment/analytics-react-native-tapstream-android

    Troubleshooting

    iOS support without CocoaPods

    We highly recommend using Cocoapods.

    However, if you cannot use Cocoapods, you can manually install our dynamic framework allowing you to send data to Segment and on to enabled cloud-mode destinations. We do not support sending data to bundled, device-mode destinations outside of Cocoapods.

    Here are the steps for installing manually:

    1. Add analytics-ios as a npm dependency: yarn add @segment/analytics-ios@github:segmentio/analytics-ios#3.6.10
    2. In the General tab for your project, search for Embedded Binaries and add the Analytics.framework Embed Analytics.framework

    Please note, if you are choosing to not use a dependency manager, you must keep files up-to-date with regularly scheduled, manual updates.

    "Failed to load [...] native module"

    If you're getting a Failed to load [...] native module error, it means that some native code hasn't been injected to your native project.

    iOS

    If you're using Cocoapods, check that your ios/Podfile file contains the right pods :

    • Failed to load Analytics native module, look for the core native module:
      pod 'RNAnalytics', :path => '../node_modules/@segment/analytics-react-native'
    • Failed to load [...] integration native module, look for the destination native module, example with Google Analytics:
      pod 'RNAnalyticsIntegration-Google-Analytics', :path => '../node_modules/@segment/analytics-react-native-google-analytics'

    Also check that your Podfile is synchronized with your workspace, run pod install in your ios folder.

    If you're not using Cocoapods please check that you followed the iOS support without CocoaPods instructions carefully.

    Android

    Check that android/app/src/main/.../MainApplication.java contains a reference to the native module:

    • Failed to load Analytics native module, look for the core native module:

      import com.segment.analytics.reactnative.core.RNAnalyticsPackage;
      
      // ...
      
      @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              // ...
              new RNAnalyticsPackage()
          );
      }
    • Failed to load [...] integration native module, look for the destination native module, example with Google Analytics:

      import com.segment.analytics.reactnative.integration.google.analytics.RNAnalyticsIntegration_Google_AnalyticsPackage;
      
      // ...
      
      @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              // ...
              new RNAnalyticsIntegration_Google_AnalyticsPackage()
          );
      }

    Keywords

    none

    Install

    npm i @segment/analytics-react-native

    DownloadsWeekly Downloads

    39,037

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    280 kB

    Total Files

    106

    Last publish

    Collaborators

    • song4you
    • peterdemartini
    • emmy.byrne
    • ashkon
    • vincen7tran
    • ariel.silvestri
    • xinghaohuang
    • dean-huynh
    • cdignam-segment
    • bkambo
    • abhinavsureka
    • rikezatsegment
    • arunlalam-segment
    • cjradek
    • neeharikakondipati
    • simpixelated
    • chihchun-twilio
    • sangeeta.singh
    • acharles14
    • jyim008
    • seghungtran
    • alayvora
    • tv0
    • pchen-twilio
    • hema-segment
    • sudojatin
    • mkhan-twilio
    • mayberex
    • anandjha
    • pmunin
    • oscb
    • krousseau
    • brandongregoryscott
    • knksmith57
    • sachinwathore
    • fhalim-segment
    • cfree
    • mettledrum
    • 5t0k4st1k
    • maerf0x0
    • gnijor
    • ifonseka1
    • aniket.gupta
    • hjoonpm
    • lauramunozjimenez
    • celine-segment
    • parsa-segment
    • hmorgan94
    • pmcanseco-segment
    • ynguyen
    • mshwery
    • debajitr
    • masira
    • gpsamson
    • amillet89
    • cholt002
    • av-segment
    • aghotikar
    • vikrant-segment
    • ankur.agarwal
    • larryatsegment
    • lbrink
    • shivpoojan-segment
    • ariel_segment
    • zkuzmic-segment
    • scruwys1
    • sowjanyaedara
    • chrischalstrom
    • rossedfort
    • eesegment
    • lew-gordon
    • kyliepedersen
    • jinapark
    • skntwilio
    • segmentio
    • segment-admin
    • dominicbarnes
    • shobhita-agarwal
    • deanhuynh
    • jlineaweaver
    • ladanazita
    • anoonan
    • peripheral
    • achille-roussel
    • rajulvadera
    • nettofarah
    • dalchandc
    • lpediredla
    • albert.segment
    • segment-danielstjules
    • n2parko
    • segment-andy-yeo
    • sahilp
    • psankaranarayana
    • vdemedes
    • emilio-gomez-lavin
    • andreiko_ru
    • xagos
    • leifdreizler
    • alan-segment
    • tyson_segment
    • bgamwell
    • jfabre-segment
    • uditmehta
    • hellooimkat
    • brienne.mcnally
    • sanscontext
    • eculver
    • aultimus
    • salolivares
    • erikdw
    • chenxiangzhang
    • fauzyy
    • jaimal
    • davidbirdsong
    • ktrinh
    • calthomson
    • yunqiaohuang
    • dk1027
    • nielssegment
    • cdrycroft
    • yabrira
    • julee05
    • kamebkj
    • ryan_segment
    • laurenmreeder
    • tidothegreat
    • mericsson
    • prayansh-segmentt
    • stargaesser
    • andyguwc
    • jeremylarkin
    • bsneed
    • danieljackins
    • tomeliaz
    • segment-seth
    • bihl
    • shamil.ataev
    • james9446
    • priscilla.giatti
    • kellylu
    • smokeybears
    • jmbuckner
    • benhorowitz
    • yolken-segment
    • nlsun
    • thomas-pelletier-segment
    • brian-segment
    • segment-michael
    • cohara87
    • drew-thompson
    • segment-jsingh
    • vanesng
    • cvillela
    • pauljaeinyoo
    • mniehe
    • stephment
    • sharadbhadouria
    • emilyc
    • maggieyu
    • anoonan16
    • durgani
    • julio.farah
    • hblanks-segment
    • rsata
    • shyaan
    • juhaelee
    • akleiner2
    • kathryn-taylor
    • andrius-segment
    • pooyaj
    • llbsgmt
    • lab176
    • valerieernst
    • ucarion
    • solon.aguiar
    • rjenkinsseg
    • segment-ulysse
    • khinkalilover
    • maloneya
    • zackurey
    • kelcook
    • arta.razavi
    • odoren
    • alistairbarrell
    • anna.choi
    • whamo12
    • amaloney
    • gilomer
    • kiara.daswani
    • marcelopv
    • yannieyip
    • eric.rogner
    • marinhero
    • lcamposg
    • corey.ching
    • steve_at_segment
    • tepahk
    • sorrel.j
    • cjo2
    • fc-segment
    • kdharaiya
    • warrengreen
    • jon.anderson-at-segment.com
    • markzegarelli
    • stysegment
    • ajhenry
    • stacy.song
    • niveda.balananthan
    • collinvandyck
    • krlv
    • rexatsegment
    • nickaguilar
    • tri.truong
    • csayuso
    • joyce-shi
    • bradenbecker
    • neha.sanghrajka
    • reneewang
    • dan.lasky
    • sam.tapia
    • gbbastos
    • vikramkumar19
    • mpriyad25
    • peter.walker
    • jeremy.parker
    • khamidou-segment
    • smidges
    • daltonscharff