For the complete documentation index, see llms.txt. This page is also available as Markdown.

WebApp Integration

This feature is supported in React Native SDK version 3.28.0 and above, and JavaScript SDK version 11.51.0 and above.

For information about WebApp, refer to the documentation.

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.

1

Add Plugin

Requirements by Plugin Version
Plugin Version
React Native SDK
react-native-webview
React Native

2.0.0 and above

4.0.0 and above, below 5.0.0

13.13.0 and above

0.74.0 and above

1.2.0

3.30.0 and above, below 4.0.0

13.13.0 and above

No restriction

1.1.0 and above, below 1.2.0

3.30.0 and above, below 4.0.0

11.0.0 and above

No restriction

1.0.0 and above, below 1.1.0

3.28.0 and above, below 4.0.0

11.0.0 and above

No restriction

Plugin version 2.0.0 and above requires Android API 24 and above, and iOS 13 and above.

If you are using React Native 0.81 or later but need to stay on plugin 1.x, use plugin version 1.1.1 or later.

# 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.0

iOS

cd ios
pod install
2

Inject 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>
  );
}

When you upgrade the React Native SDK to 4.x, you must also upgrade the plugin to 2.x. Refer to the migration guide.

To use this feature, the JavaScript web page must use the same App SDK Key.

3

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.

Option
Description
Default
Supported Version

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 +

Choose the collection method for page navigation.

  • Automatic collection: Set automaticScreenTracking, automaticEngagementTracking, and automaticRouteTracking all to true.

  • Manual collection: Set automaticScreenTracking and automaticEngagementTracking to true. Set automaticRouteTracking to false.

Last updated