Skip to content

Commit 16a125c

Browse files
Add section on WebView with RN
1 parent 0f17c0b commit 16a125c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Analytics React Native was built to be as extensible and customizable as possibl
205205
- [Native AnonymousId](#native-anonymousid)
206206
- [Configure iOS deep link tracking](#configure-ios-deep-link-tracking)
207207
- [Device identifiers](#device-identifiers)
208+
- [Using a WebView Component with React Native](#using-a-webview-component-with-react-native)
208209

209210
### Control upload with flush policies
210211

@@ -467,5 +468,24 @@ On Android, Segment's React Native library generates a unique ID by using the DR
467468
468469
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.
469470
471+
### Using a WebView Component with React Native
472+
473+
If you use a webView component in your app that utilizes our [Analytics.js](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/){:target="_blank"} library, you can utilize our [Querystring API](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/querystring/){:target="_blank"} to pass the anonymousId from your React Native app to Analytics.js to ensure activity from anonymous users can be linked across these two sources.
474+
475+
To retrieve and pass the anonymousId:
476+
477+
1. Retrieve anonymousId from the React Native library using:
478+
```js
479+
const anonymousId = segmentClient.userInfo.get().anonymousId
480+
```
481+
2. Pass this value into the querystring that opens the webview using the ```ajs_aid``` optional query string parameter noted in the above linked documentation. For example, your WebView component might look like:
482+
```js
483+
<WebView
484+
ref={webViewRef}
485+
source={{uri: `http://segment.com/?ajs_aid={anonymousId}`}}
486+
/>
487+
```
488+
3. When a user clicks the element that opens the webview, AJS will read that parameter and automatically set the anonymousId to whatever value is passed in, linking your events across both libraries to the same user.
489+
470490
## Changelog
471491
[View the Analytics React Native changelog on GitHub](https://github.com/segmentio/analytics-react-native/releases){:target="_blank"}.

0 commit comments

Comments
 (0)