Skip to content

Commit 635374f

Browse files
authored
Merge pull request #5747 from segmentio/ashton-huxtable-patch-4
Add section on WebView with RN
2 parents c6f32ec + 2dfa014 commit 635374f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Analytics React Native was built to be as extensible and customizable as possibl
206206
- [Retrieving the anonymousId](#retrieving-anonymousid)
207207
- [Configure iOS deep link tracking](#configure-ios-deep-link-tracking)
208208
- [Device identifiers](#device-identifiers)
209+
- [Using a WebView Component with React Native](#using-a-webview-component-with-react-native)
209210

210211
### Control upload with flush policies
211212

@@ -477,5 +478,21 @@ On Android, Segment's React Native library generates a unique ID by using the DR
477478
478479
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.
479480
481+
### Using a WebView Component with React Native
482+
483+
If you use a webView component in your app that uses Segment's [Analytics.js](/docs/connections/sources/catalog/libraries/website/javascript/){:target="_blank"} library, you can use Segment's [Querystring API](/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.
484+
485+
To retrieve and pass the anonymousId:
486+
487+
1. Retrieve anonymousId from the React Native library using:
488+
```js
489+
const anonymousId = segmentClient.userInfo.get().anonymousId
490+
```
491+
2. Pass this value into the querystring that opens the webview using the `ajs_aid` optional query string parameter noted in the documentation above. For example, the URL that opens your webview might look like:
492+
```text
493+
http://segment.com/?ajs_aid={anonymousId}
494+
```
495+
3. When a user clicks the element that opens the webview, Analytics.js 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.
496+
480497
## Changelog
481498
[View the Analytics React Native changelog on GitHub](https://github.com/segmentio/analytics-react-native/releases){:target="_blank"}.

0 commit comments

Comments
 (0)