WebApp Integration
When rendering your own website through WebView, you can use the settings below to use the Hackle JavaScript SDK included in the website identically to the Hackle React Native SDK functions without modifying the website code.
When WebApp Integration is configured, all events that occur within the WebView are collected through the React Native SDK.
After completing the React Native SDK integration, follow the steps below.
Add Plugin
# React Native SDK 4.x
npm install --save @hackler/react-native-webview-plugin@^2.0.0
# React Native SDK 3.x
npm install --save @hackler/react-native-webview-plugin@^1.2.0# React Native SDK 4.x
yarn add @hackler/react-native-webview-plugin@^2.0.0
# React Native SDK 3.x
yarn add @hackler/react-native-webview-plugin@^1.2.0iOS
cd ios
pod installInject WebView Bridge
Wrap WebView with HackleWebViewBridge. HackleWebViewBridge installs the bridge into the WebView and forwards requests sent by the website's Hackle JavaScript SDK to the React Native SDK.
import { WebView } from 'react-native-webview';
import { createInstance, HackleProvider } from "@hackler/react-native-sdk";
import { HackleWebViewBridge } from '@hackler/react-native-webview-plugin';
// Hackle SDK initialization must be complete before injecting the WebApp bridge.
const hackleClient = createInstance("YOUR_APP_SDK_KEY");
function MyWebView() {
return (
<HackleProvider hackleClient={hackleClient}>
<HackleWebViewBridge>
// Use only a single react-native-webview object as the child element.
<WebView source={{ uri: currentUrl }} />
</HackleWebViewBridge>
</HackleProvider>
);
}Add HackleWebViewConfig to the nativeConfig props of the react native webview.
You can create a config using the createHackleWebViewConfig() function.
import { WebView } from 'react-native-webview';
import { createInstance, HackleProvider } from "@hackler/react-native-sdk";
import { createHackleWebViewConfig } from '@hackler/react-native-webview-plugin';
// Hackle SDK initialization must be complete before injecting the WebApp bridge.
const hackleClient = createInstance("YOUR_APP_SDK_KEY");
function MyWebView() {
const hackleConfig = createHackleWebViewConfig();
return (
<HackleProvider hackleClient={hackleClient}>
<WebView
nativeConfig={hackleConfig}
source={{ uri: currentUrl }}
/>
</HackleProvider>
);
}Integrating Auto-collected Events from WebView
The $page_view and $engagement that occur in the website inside the WebView are disabled.
You can enable each auto-collected event when configuring the WebView bridge.
Configure it by passing props to HackleWebViewBridge.
import { WebView } from 'react-native-webview';
import { createInstance, HackleProvider } from "@hackler/react-native-sdk";
import { HackleWebViewBridge } from '@hackler/react-native-webview-plugin';
// Hackle SDK initialization must be complete before injecting the WebApp bridge.
const hackleClient = createInstance("YOUR_APP_SDK_KEY");
function MyWebView() {
return (
<HackleProvider hackleClient={hackleClient}>
<HackleWebViewBridge
automaticScreenTracking
automaticEngagementTracking
automaticRouteTracking
>
<WebView source={{ uri: currentUrl }} />
</HackleWebViewBridge>
</HackleProvider>
);
}To set a value to false, specify it explicitly, like automaticRouteTracking={false}.
Configure it by passing HackleWebViewConfig to createHackleWebViewConfig().
Configuration Options
The option names and default values are the same for plugin 1.x and 2.x.
automaticScreenTracking
Whether to collect $page_view
false
1.0.0 +
automaticEngagementTracking
Whether to collect $engagement
false
1.0.0 +
automaticRouteTracking
Whether to automatically collect page information
true
1.1.0 +
Last updated