Skip to content

Commit e568653

Browse files
Merge pull request #7933 from segmentio/DOC-1181
Reviewed the React Native docs
2 parents dd6eebc + 12fa66f commit e568653

File tree

1 file changed

+36
-19
lines changed
  • src/connections/sources/catalog/libraries/mobile/react-native

1 file changed

+36
-19
lines changed

src/connections/sources/catalog/libraries/mobile/react-native/index.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ To get started with the Analytics for React Native library:
4747
npm install --save @react-native-async-storage/async-storage
4848
```
4949

50-
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
50+
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, or you might get unexpected side effects like multiple 'Application Installed' events.
5151

5252
4. If you're using iOS, install native modules with:
5353
@@ -75,7 +75,7 @@ These are the options you can apply to configure the client:
7575

7676
| Name | Default | Description |
7777
| --------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
78-
| `writeKey` | '' | Your Segment API key (**required**). |
78+
| `writeKey` | '' | Your Segment API key (**required**). |
7979
| `collectDeviceId` | false | Set to `true` to automatically collect the device ID from the DRM API on Android devices. |
8080
| `debug` | true\* | When set to `false`, it will not generate any logs. |
8181
| `logger` | undefined | Custom logger instance to expose internal Segment client logging. |
@@ -275,7 +275,7 @@ alias('user-123');
275275
The Reset method clears the internal state of the library for the current user and group. This is useful for apps where users can log in and out with different identities over time.
276276
277277
> warning ""
278-
> Each time you call Reset, a new AnonymousId is generated automatically.
278+
> **Note:** Each time you call Reset, Segment generates a new AnonymousId.
279279
280280
{% codeexample %}
281281
{% codeexampletab Method signature %}
@@ -333,8 +333,9 @@ If you don't do this, the old client instance would still exist and retain the t
333333
334334
Ideally, you shouldn't have to use this method and the Segment client should be initialized only once in the application lifecycle.
335335

336-
## Control upload with Flush Policies
337-
To granularly control when Segment uploads events, use `FlushPolicies`. A Flush Policy defines the strategy for deciding when to flush. This can be on an interval, time of day, after receiving a certain number of events, or after receiving a particular event. This gives you more flexibility on when to send event to Segment.
336+
## Control upload cadence with flush policies
337+
To granularly control when Segment uploads events you can use `FlushPolicies`.
338+
A Flush Policy defines the strategy for deciding when to flush. This can be on an interval, time of day, after receiving a certain number of events, or after receiving a particular event. This gives you more flexibility on when to send event to Segment.
338339

339340
Set Flush Policies in the configuration of the client:
340341
```ts
@@ -347,12 +348,13 @@ const client = createClient({
347348
],
348349
});
349350
```
350-
You can set several policies at a time. When a flush occurs, it triggers an upload of the events then resets the logic after every flush. As a result, only the first policy to reach `shouldFlush` will trigger a flush. In the example, the event count either reaches 5 or the timer reaches 500 ms - whatever comes first will trigger a flush.
351351

352-
Segment has several standard flush policies:
353-
- `CountFlushPolicy` triggers when you reach a certain number of events.
354-
- `TimerFlushPolicy` triggers on an interval of milliseconds.
355-
- `StartupFlushPolicy` triggers on client startup only.
352+
You can set several policies at a time. When a flush occurs, it triggers an upload of the events, then resets the logic after every flush.
353+
As a result, only the first policy to reach `shouldFlush` triggers a flush. In the example above either the event count reaches 5 or the timer reaches 500ms, whatever comes first, will trigger a flush.
354+
Segment has several standard Flush Policies:
355+
- `CountFlushPolicy` triggers when you reach a certain number of events
356+
- `TimerFlushPolicy` triggers on an interval of milliseconds
357+
- `StartupFlushPolicy` triggers on client startup only
356358

357359
> info ""
358360
> If you implement custom flush policies, they replace Segment's default Count and Timer policies. To incorporate custom policies, add your custom Timer and Count policies to the client's Flush Policies configuration.
@@ -399,7 +401,8 @@ Your policies also have a `shouldFlush` observable boolean value. When this is s
399401
export class FlushOnScreenEventsPolicy extends FlushPolicyBase {
400402
onEvent(event: SegmentEvent): void {
401403
// Only flush when a screen even happens
402-
if (event.type === EventType.ScreenEvent) {
404+
if (event.type \
405+
EventType.ScreenEvent) {
403406
this.shouldFlush.value = true;
404407
}
405408
}
@@ -414,6 +417,7 @@ export class FlushOnScreenEventsPolicy extends FlushPolicyBase {
414417
## Automatic screen tracking
415418
To avoid sending a Screen event with each navigation action, you can track navigation globally. The implementation depends on which navigation library you use. The two main navigation libraries for React Native are [React Navigation](https://reactnavigation.org/){:target="_blank"} and [React Native Navigation](https://wix.github.io/react-native-navigation/docs/before-you-start/){:target="_blank"}.
416419
420+
417421
### React Navigation
418422
When setting up React Navigation, find the root-level navigation container and call `screen()` whenever the user navigates to a new screen. Segment's [example app](https://github.com/segmentio/analytics-react-native/tree/master/example){:target="_blank"} is set up with screen tracking using React Navigation, so you can use it as a guide.
419423

@@ -457,7 +461,7 @@ To set up automatic screen tracking with React Navigation:
457461
}
458462
}}
459463
>
460-
```
464+
```
461465
462466
### React Native Navigation
463467
To set up automatic screen tracking while using [React Native Navigation](https://wix.github.io/react-native-navigation/docs/before-you-start/){:target="_blank"}:
@@ -482,19 +486,21 @@ Segment's plugin architecture lets you modify and augment how the events are pro
482486
| `enrichment` | Executes as the first level of event processing. |
483487
| `destination` | Executes as events begin to pass off to destinations. |
484488
| `after` | Executes after all event processing is completed. You can use this to perform cleanup operations. |
485-
| `utility` | Executes only with manual calls such as Logging. |
489+
| `utility` | Executes only with manual calls like Logging. |
486490
487491
> info ""
488-
> Plugins can have their own native code, such as the iOS-only [`IdfaPlugin`](https://github.com/segmentio/analytics-react-native/blob/829fc80bc8c4f59fa99dadd25083efa422d577f0/packages/plugins/plugin-idfa/README.md){:target="_blank"}, or wrap an underlying library, such as the [`FirebasePlugin`](https://www.npmjs.com/package/@segment/analytics-react-native-plugin-firebase){:target="_blank"} which uses `react-native-firebase`.
492+
> Plugins can have their own native code (like the iOS-only [`IdfaPlugin`](https://github.com/segmentio/analytics-react-native/blob/829fc80bc8c4f59fa99dadd25083efa422d577f0/packages/plugins/plugin-idfa/README.md){:target="_blank"}) or wrap an underlying library (like the [`FirebasePlugin`](https://www.npmjs.com/package/@segment/analytics-react-native-plugin-firebase) which uses `react-native-firebase` under the hood).
489493
490494
### Destination plugins
491-
Segment provides a `DestinationPlugin`. You can add additional destination plugins and upload events and data to them.
495+
Segment is an out-of-the-box `DestinationPlugin`. You can add as many other destination plugins as you like and upload events and data to them.
496+
492497
493498
If you don't want the Segment destination plugin, set `autoAddSegmentDestination = false` in the options when setting up your client. This prevents the `SegmentDestination` plugin from being added automatically.
494499
495500
### Adding plugins
496501
You can add a plugin at any time using `segmentClient.add()`.
497502
503+
498504
```js
499505

500506
import { createClient } from '@segment/analytics-react-native';
@@ -515,6 +521,7 @@ segmentClient.add({ plugin: new IdfaPlugin() });
515521
### Writing your own plugins
516522
Plugins implement as [ES6 classes](https://www.w3schools.com/react/react_es6_classes.asp){:target="_blank"}. To get started, familiarize yourself with the available classes in `/packages/core/src/plugin.ts`.
517523
524+
518525
The available plugin classes are:
519526
- `Plugin`
520527
- `EventPlugin`
@@ -608,11 +615,12 @@ These are the example plugins you can use and alter to meet your tracking needs:
608615
| Firebase | `@segment/analytics-react-native-plugin-consent-firebase` |
609616
| IDFA | `@segment/analytics-react-native-plugin-idfa` |
610617
611-
<!-- ## Destination Filters
618+
## Destination filters
619+
612620
> info ""
613621
> Destination filters are only available to Business Tier customers.
614622
>
615-
> Destination filters on mobile device-mode destinations are in beta and only supports Analytics-React-Native 2.0, [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/) and [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/).
623+
> Destination filters on mobile device-mode destinations are in beta and only support Analytics-React-Native 2.0, [Analytics-Swift](/docs/connections/sources/catalog/libraries/mobile/swift/) and [Analytics-Kotlin](/docs/connections/sources/catalog/libraries/mobile/kotlin-android/).
616624
617625
Use Analytics-React-Native 2.0 to set up [destination filters](/docs/connections/destinations/destination-filters/) on your mobile device-mode destinations.
618626
@@ -649,6 +657,7 @@ To get started with destination filters on mobile device-mode destinations using
649657
650658
## Supported destinations
651659
Segment supports a large number of [cloud-mode](/docs/connections/destinations/#connection-modes) destinations. Segment also supports the following destinations for Analytics React Native 2.0 in device-mode:
660+
652661
- [Adjust](https://www.npmjs.com/package/@segment/analytics-react-native-plugin-adjust){:target="_blank"}
653662
- [Amplitude Session](https://www.npmjs.com/package/@segment/analytics-react-native-plugin-amplitude-session){:target="_blank"}
654663
- [Appsflyer](https://www.npmjs.com/package/@segment/analytics-react-native-plugin-appsflyer){:target="_blank"}
@@ -663,6 +672,8 @@ On Android, Segment's React Native library generates a unique ID by using the DR
663672
To collect the Android Advertising ID provided by Play Services, Segment provides a [plugin](https://github.com/segmentio/analytics-react-native/tree/master/packages/plugins/plugin-advertising-id){:target="_blank"} that can be used to collect that value. This value is set to `context.device.advertisingId`. For iOS, this [plugin](https://github.com/segmentio/analytics-react-native/tree/master/packages/plugins/plugin-idfa){:target="_blank"} can be used to set the IDFA `context.device.advertisingId` property.
664673
665674
## FAQs
675+
Find answers to common Analytics React Native questions.
676+
666677
#### Can I use the catalog of device-mode destinations from Segment's 1.X.X React-Native release?
667678
No, only the plugins [listed](#plugin-types) are supported in device-mode for Analytics React Native 2.0.
668679
#### Will I still see device-mode integrations listed as `false` in the integrations object?
@@ -682,9 +693,11 @@ const segmentClient = createClient({
682693
writeKey: segmentWriteKey
683694
});
684695
```
696+
685697
#### What is the `instanceId` set in context?
686698
The `instanceId` was introduced in [v2.10.1](https://github.com/segmentio/analytics-react-native/releases/tag/%40segment%2Fanalytics-react-native-v2.10.1) and correlates events to a particular instance of the client in a scenario when you might have multiple instances on a single app.
687699
700+
688701
#### How do I interact with the Integrations object?
689702
The Integrations object is no longer part of the Segment events method signature. To access the Integrations object and control what destinations the event reaches, you can use a plugin:
690703
@@ -711,8 +724,10 @@ import {
711724
}
712725
}
713726
```
727+
714728
#### How do I add to the Context object?
715729
You need to use a plugin to access and modify the Context object. For example, to add `context.groupId` to every Track call, create a plugin like this:
730+
716731
```js
717732
//in AddToContextPlugin.js
718733
import {
@@ -740,12 +755,14 @@ import { AddToContextPlugin } from './AddToContextPlugin'
740755
segmentClient.add({ plugin: new AddToContextPlugin() });
741756
```
742757
743-
#### I've upgraded to React Native 2.0, but I'm still getting warnings in the Google Play Store that my app is not compliant. Why is this?
744-
The React Native 2.0 library is compliant with Google Play Store policies. However, Segment recommends that you check to see if there are any old and inactive [tracks on the Google Play Store](https://developers.google.com/android-publisher/tracks){:target="_blank"} that are not updated to the latest build. If this is the case, we recommend updating those tracks to resolve the issue.
758+
### I've upgraded to React Native 2.0, but I am still getting warnings in the Google Play Store that my app is not compliant. Why is this?
759+
The React Native 2.0 library is compliant with Google Play Store policies. However, Segment recommends that you check to see if there are any old and inactive [tracks on the Google Play Store](https://developers.google.com/android-publisher/tracks){:target="_blank"} that are not updated to the latest build. If this is the case, Segment recommends updating those tracks to resolve the issue.
760+
745761
746762
#### Can I set `inlineRequires` to false in my `metro.config.js` file?
747763
Segment requires the `inlineRequires` value in your `metro.config.js` value to be set to `true`. To disable `inlineRequires` for certain modules, you can specify this using a [blockList](https://facebook.github.io/metro/docs/configuration/#:~:text=If%20inlineRequires%20is%20an%20object){:target="_blank"}.
748764
765+
749766
#### Can I clear user traits without calling the Reset method?
750767
The Reset method on `userInfo` can accept a function that receives the current state and returns a modified desired state. Using this method, you can return the current traits, delete any traits you no longer wish to track, and persist the new trait set.
751768

0 commit comments

Comments
 (0)