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

0.3.0 • Public • Published

Signals Plugins for Analytics

Plugins that enables Auto-Instrumentation for Analytics

Getting Started

To get started:

  1. follow the set up instructions for Analytics Swift here to integrate Segment's Analytics SDK into your app.
  2. add the dependency:

You need to install the @segment/analytics-react-native-plugin-live and @segment/analytics-react-native-plugin-signals.

Using NPM:

npm install --save @segment/analytics-react-native-plugin-live @segment/analytics-react-native-plugin-signals

Using Yarn:

yarn add @segment/analytics-react-native-plugin-live @segment/analytics-react-native-plugin-signals

Run pod install after the installation to autolink the Live Plugin and Signals Plugin.

Setup

Turn off Hermes

The current implementation does not support Hermes as the default JS Engine. We will support it in the future. For now, follow the below instructions to turn off Hermes to force React Native to use JavaScript Core as the engine:

for iOS, in Podfile, search for hermes_enabled and change the value to false:

:hermes_enabled => false

for Android, in gradle.properties, search for hermesEnabled and change the value to false:

hermesEnabled=false

After making these changes, make sure to run pod install and to clean and rebuild your project.

Setup Network and UI Tracking

Follow the instructions for adding plugins on the main Analytics client:

In your code where you initialize the analytics client call the .add(plugin) method to add the Signals related plugins.

import { LivePlugins } from '@segment/analytics-react-native-plugin-live';
import { SegmentBroadcaster, Signals, SignalsNetworkTracking, signalsScreenTracking, SignalsUITracking } from '@segment/analytics-react-native-plugin-signals';


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

// add LivePlugins to analytics client
segmentClient.add({ plugin: new LivePlugins() });
// config Signals
Signals.config = {
  maximumBufferSize: 1,
  broadcastInterval: 5,
  broadcasters: [new SegmentBroadcaster(segmentClient)]
};
// add Signals object to analytics client
segmentClient.add({plugin: Signals});
// add SignalsNetworkTracking to capture network activities
segmentClient.add({plugin: new SignalsNetworkTracking()});
// add SignalsUITracking to capture UI interactions
segmentClient.add({plugin: new SignalsUITracking()});

Setup Screen Tracking

Tracking screens/navigations needs some extra setups depending on the navigation package used. The following is an example that uses React Navigation:

First, add the following imports and function

import {
  NavigationContainer,
  NavigationState,
  PartialState,
  useNavigationContainerRef,
} from '@react-navigation/native';
import {useState} from 'react';

// get current route
const getActiveRouteName = (
  state: NavigationState | PartialState<NavigationState> | undefined,
): string => {
  if (!state || typeof state.index !== 'number') {
    return 'Unknown';
  }

  const route = state.routes[state.index];

  if (route.state) {
    return getActiveRouteName(route.state);
  }

  return route.name;
};

Then, create a ref to store the navigation object

  const navigationRef = useNavigationContainerRef();

Next, pass the ref to NavigationContainer and a function in the onReady prop to track the initial route name. Finally, pass a function in the onStateChange prop to track screen changes

<NavigationContainer
        ref={navigationRef}
        onReady={() => {
          signalsScreenTracking.onScreenChange(navigationRef.current?.getCurrentRoute()?.name);
        }}
        onStateChange={state => {
          const newRouteName = getActiveRouteName(state);
          signalsScreenTracking.onScreenChange(newRouteName);
        }}
      >    

You can follow the same logic (i.e. use signalsScreenTracking.onScreenChange(newScreen)) to capture screen changes if you are using a different library.

Package Sidebar

Install

npm i @segment/analytics-react-native-plugin-live

Weekly Downloads

2

Version

0.3.0

License

SEE LICENSE IN LICENSE

Unpacked Size

147 kB

Total Files

55

Last publish

Collaborators

  • harksingh
  • fhalim-segment
  • cfree
  • ldelossantos
  • hjoonpm
  • celine-segment
  • pmcanseco-segment
  • masira
  • amillet89
  • cholt002
  • av-segment
  • aghotikar
  • vikrant-segment
  • larryatsegment
  • scruwys1
  • kyliepedersen
  • jinapark
  • cdignam-segment
  • segmentio
  • jrupasinghe
  • lateefat
  • rajulvadera
  • yash-twilio
  • sowjanyasegment
  • ebru.odok
  • ryanligon
  • lpediredla
  • brookstaylorjr
  • nithan-twilio
  • dean-huynh
  • wdbetts
  • n2parko
  • jayakrishnannair
  • rhall-twilio
  • karimkeshwani
  • tyson_segment
  • jgabe13
  • bgamwell
  • poojasegment
  • maryam.sharif
  • wally.tg
  • salolivares
  • erikdw
  • chenxiangzhang
  • justeen
  • mericsson
  • prayansh-segmentt
  • jeremylarkin
  • bsneed
  • danieljackins
  • segment-seth
  • sayan-das-in
  • james9446
  • priscilla.giatti
  • nlsun
  • drew-thompson
  • segment-jsingh
  • mcoulibali
  • andrius-segment
  • valerieernst
  • nithin-benny
  • ainatancinco
  • skondamuri
  • clintz.seg
  • replatero
  • slenin-twilio
  • csayuso
  • seanhan-segment
  • nevermore2022
  • gilomer
  • marcelopv
  • eric.rogner
  • kdharaiya
  • jon.anderson-at-segment.com
  • stacy.song
  • rexatsegment
  • nickaguilar
  • bradenbecker
  • reneewang
  • dan.lasky
  • sam.tapia
  • lnamba
  • vikramkumar19
  • mpriyad25
  • jeremy.parker
  • smidges
  • nageshgolem
  • sudojatin
  • pmaid
  • sethsegment
  • jair.aviles
  • manali-bhosale
  • elmoselyee
  • chtoombs
  • peterdemartini
  • vincen7tran
  • mayur-pitale
  • lfdelossantos
  • emmy.byrne
  • felttrip
  • sa-jsooter
  • lluque-twilio
  • kevinburkesegment
  • afsha-nazim-seg
  • song4you
  • david.anusontarangkul.segment
  • jyim008
  • michaelghseg
  • acharles14
  • aishikawaki
  • twjosiah
  • tanya.gupta.segment
  • sindhusegment
  • prabhnoor1997
  • chihchun-twilio
  • pmiller-twilio
  • vbatanov
  • simpixelated
  • mcullenmeyer
  • neeharikakondipati
  • eric-hyde
  • arunlalam-segment
  • mschaszberger
  • shuvrajit9904
  • abhinavsureka
  • varadarajan-tw
  • immanoj
  • blangtwilio
  • jsh-wu
  • jahood-twilio
  • sethnutetwilio
  • rrivera-segment
  • segment-admin
  • bgillan
  • tcgilbert
  • mckern_segment
  • maneesh.dharma29
  • joetessy
  • gkochar123
  • dominicbarnes
  • mugelstad
  • jalexy12
  • lerahulram
  • pmunin
  • whaider_twilio
  • ariel.silvestri
  • shraddha-twilio
  • michelr
  • brandon.scott-segment
  • jfehrman.segment
  • prayansh-twilio
  • dangmai-segment
  • aaronklish
  • brianhumphreystwilio
  • rmukundan
  • ashwitha.bg
  • ryanrouleau-segment
  • funlu
  • tdibacco
  • fauzy.yy
  • nlubchenco
  • arubiochavez
  • phillip.thomas
  • jkusa_segment
  • rollcode
  • meg1000
  • nainy.agrawal
  • seg-rustybailey
  • jbandi-twilio
  • saisagarkappaganthula
  • forgetfulfellow
  • dbaik-twilio-segment
  • pooja.patil
  • joe.ayoub.segment
  • hmohanram_seg
  • brian.aguirre
  • enyi.asonye
  • farhan0581
  • tbrennanj
  • parag.panda
  • cherylj-segment
  • harsh.vardhan
  • sshaikh_segment
  • xinghao.huang
  • shupadhyay
  • john.lee1100
  • kx-segment
  • segment_fan
  • dazu70
  • sai-patanjali
  • emilyjia
  • y.yu
  • ea_segment
  • yli119
  • pooyaj
  • sungju.jin
  • conniechen
  • bharath.boregowda
  • igracheva-twilio
  • benattwilio
  • marinhero
  • ankit.gupta.unthinkable
  • dobrin.ganev
  • alfrimpong
  • brandonheyer-segment
  • alecjacobs-segment
  • cjo2
  • yashnit-segment
  • dltnbrks-segment
  • achandrashekaran
  • himanshuph
  • pragupta
  • tw-dgarcia
  • alayvora
  • aparna.singhal
  • ynguyen
  • timmyzsearcy
  • lweimersegment
  • anton-vylushchak
  • azhaotwilio
  • rokatyal
  • kjoerres
  • msaraf
  • vikakumar
  • aditi.raveesh
  • chenchensegmentcom
  • sanket.mishra
  • odoren_segment
  • jxin_twilio
  • rcheedhalla
  • jbasiglio-segment
  • viveksainaneesegment
  • priyanshis
  • preetyp
  • akash.gautam07
  • nanotimm
  • yshkpr
  • srivig21
  • ssuneja
  • bala.singareddy
  • moyara2
  • arjunbhandage
  • akodankiry
  • rodhilton_twilio
  • cdelaomartinez
  • gbatra
  • spencerattick
  • segmentsean
  • sundareswar.jayakumar
  • vaibhavnanda
  • bannapple
  • srishti-nema
  • ar7dev
  • gsolis_segment
  • itsarijitray
  • bhavanki-segment
  • nikumarsegment
  • nanette.ranes
  • amigandhi
  • guthriesegment
  • miguelpdiaz8
  • mansari
  • sandhya16
  • hema-bahirwani-segment
  • bnakkina
  • praveenugiri
  • ighorela
  • nemery-segment
  • wlumsegment
  • nat-grid
  • needcaffeine
  • kbhargavaram-sg
  • irfan.ali.segment
  • harsh-joshi99
  • ed-twilion-npm
  • aubreysine
  • light-bringer-blr
  • sethgrid_segment
  • jibrang
  • seg-leonelsanches
  • smccoy-twilio
  • devthale
  • andwivedi
  • poojapatilseg
  • gaprabhu
  • apacker
  • monusegment
  • ehydesegment
  • psandquist
  • dcp-twilio
  • agerbas-segment
  • amitsinglaatseg