Track WebViews
Enable tracking in WebViews
Section titled Enable tracking in WebViewsInject the Bridge between the CS Tag in WebView mode and the SDK
Section titled Inject the Bridge between the CS Tag in WebView mode and the SDKThis step is threefold:
- It will inject our JavaScript Bridge in order to connect the CS Tag in WebView mode and our SDK.
- It will inject your CS Tag in WebView mode if it was not already injected, allowing us to gather data on all your webviews, even when the user is offline, on pages showing local HTML.
- It will inject a
window.CS_isWebView
variable for you to use in order to detect if the page is loaded from a WebView.
In order to inject this JavaScript, you will use our CSWebView
component to render your WebView, as detailed bellow.
Here is a screen with a react-native-webview
WebView component.
import { WebView } from "react-native-webview";const WebviewWithTagScreen = () => { return ( <> <WebView source={{ uri: "https://www.mywebpage.com" }} /> </> );};export default WebviewWithTagScreen;
Let’s walk through how we can inject it with a custom JavaScript interface.
CSWebView component
Section titled CSWebView componentIn order to inject your WebView with the Contentsquare JavaScript WebView interface you will need to wrap your original WebView with CSWebView
component. CSWebView
component will handle all.
import { WebView } from "react-native-webview";const WebviewWithTagScreen = () => { return ( <> <CSWebView> <WebView source={{ uri: "https://www.mywebpage.com" }} /> </CSWebView> </> );};export default WebviewWithTagScreen;
Inject the CS Tag in WebView mode into your HTML page
Section titled Inject the CS Tag in WebView mode into your HTML pageAfter doing all the above, in order for the implementation to be completed, you will need to make sure our CS Tag in WebView mode is injected on your pages. To do so, refer to 📚 Mobile Apps WebView Tracking Documentation.
Migrating from version 4.X.X to 5.X.X
Section titled Migrating from version 4.X.X to 5.X.XIf you are migrating from a previous version of the Contentsquare React Native SDK, update your CSWebView
implementation:
import React from "react";import { WebView } from "react-native-webview";import { CSWebView } from "@contentsquare/react-native-bridge";
const WebviewWithTagScreen = () => { return ( // This method is deprecated <CSWebView url="https://www.mywebpage.com" renderWebView={(onLayout, webViewUrl) => { return ( <WebView onLayout={onLayout} source={{ uri: webViewUrl }} /> ); }} /> <CSWebView> <WebView source={{ uri: "https://www.mywebpage.com" }} /> </CSWebView> );};
export default WebviewWithTagScreen;