# WebApp Integration

{% hint style="info" %}
This feature is supported in iOS SDK 2.27.0 and above, and JavaScript SDK 11.25.1 and above.

For information about WebApp, see the [documentation](/en/development-guide/faq/web-app-intergration.md).
{% endhint %}

When rendering your own website via `WKWebView`, you can use the following configuration to use the Hackle JavaScript SDK included in your website with the same functionality as the Hackle iOS SDK, without modifying the website code.

Once the bridge is configured, Hackle events generated in the WebView are collected through the iOS SDK.

{% hint style="info" %}
The WebView bridge only hooks and processes data passed as a bridge from the Hackle JavaScript SDK, and passes the remaining data to the referenced delegate.
{% endhint %}

{% tabs %}
{% tab title="Swift" %}

```swift
...
Hackle.app().setWebViewBridge(webView)
...
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
...
self.webView = ...
HackleApp *hackleApp = [Hackle app];
[hackleApp setWebViewBridge:self.webView :NULL];
...
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
To use this feature, the **JavaScript web page must use the same App SDK Key**.

The Hackle iOS WebView configuration interacts with the Hackle JavaScript SDK via iOS `UIDelegate` and `WKUserScript`. Make sure this configuration is completed before calling `WKWebView::load`.
{% endhint %}

If you already have a `UIDelegate` in use, pass it together with this function as shown below.

* If no `UIDelegate` is configured, the `UIDelegate` of the WebView object is referenced if it exists.
* If a `UIDelegate` is configured, that delegate is referenced.

{% tabs %}
{% tab title="Swift" %}

```swift
...
Hackle.app().setWebViewBridge(webView, myUiDelegate)
...
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
...
self.webView = ...
self.myUIDelegate = ...
HackleApp *hackleApp = [Hackle app];
[hackleApp setWebViewBridge:self.webView :self.myUIDelegate];
...
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
If you have already added various features to the delegate, it is recommended to call `setWebViewBridge` after all delegate configurations are complete.
{% endhint %}

### Integrating Auto-collected Events from WebView

{% hint style="info" %}
This feature is supported in iOS SDK 2.57.0 and above, and JavaScript SDK 11.51.0 and above.
{% endhint %}

`$page_view` and `$engagement` generated on websites within the WebView are disabled by default. You can enable each auto-collected event by configuring `HackleWebViewConfig` when setting up the WebView bridge.

```swift
let webViewConfig = HackleWebViewConfigBuilder()
	.automaticScreenTracking(true)
	.automaticEngagementTracking(true)
	.build()

Hackle.app().setWebViewBridge(webView, myUiDelegate, webViewConfig)
```

#### Configuration Options

<table><thead><tr><th width="258.32421875">Option</th><th width="120">Default</th><th>Description</th></tr></thead><tbody><tr><td><code>automaticScreenTracking</code></td><td>false</td><td>Whether to collect <code>$page_view</code> generated on the website</td></tr><tr><td><code>automaticEngagementTracking</code></td><td>false</td><td>Whether to collect <code>$engagement</code> generated on the website</td></tr><tr><td><code>automaticRouteTracking</code></td><td>true</td><td>Whether to automatically collect page information generated on the website</td></tr></tbody></table>

{% hint style="info" %}
To automatically collect `$page_view` and `$engagement` on page navigation, set `automaticScreenTracking`, `automaticEngagementTracking`, and `automaticRouteTracking` all to `true`.

To [manually collect](/en/development-guide/javascript/event-tracking/js-track-page.md) `$page_view` and `$engagement` on page navigation, set `automaticScreenTracking` and `automaticEngagementTracking` to `true`, and set `automaticRouteTracking` to `false`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/ios/ios-webapp-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
