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

WebApp Integration

This feature is supported in Flutter SDK 2.13.0 and above, and JavaScript SDK 11.25.1 and above.

For information about WebApps, refer to the documentation.

When rendering your own website via InAppWebView, you can configure the Hackle JavaScript SDK embedded in the website to work identically to the Hackle Flutter SDK features without modifying the website code by applying the following settings.

In this case, all Hackle events are collected through the Flutter SDK.

import 'dart:collection';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:hackle/hackle.dart';

final keepAlive = InAppWebViewKeepAlive();

InAppWebView(
  initialSettings: InAppWebViewSettings(
    javaScriptEnabled: true,
  ),
  keepAlive = keepAlive,
  initialUserScripts: UnmodifiableListView<UserScript>([
    UserScript(
      source: HackleApp.getWebBridgeScript(),
      injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START,
      forMainFrameOnly: true
    )]),
  onWebViewCreated: (controller) {
    controller.loadUrl(urlRequest: URLRequest(url: WebUri('YOUR_WEB_URL')));
  },
  onJsPrompt: (controller, jsPromptRequest) async {
    if(HackleApp.isInvocableCommandInWebView(jsPromptRequest.message)) {
      var result = await HackleApp.handleWebInterfaceCommand(jsPromptRequest.message);
      return JsPromptResponse(action: JsPromptResponseAction.CONFIRM, handledByClient: true, value: result);
    } else {
      return JsPromptResponse(handledByClient: false);
    }
  },
);

Integrating Auto-collected Events from WebView

This feature is supported in Flutter SDK 2.26.0 and above, and JavaScript SDK 11.51.0 and above.

$page_view events occurring on the website inside the WebView are disabled by default. You can enable auto-collected events by configuring HackleWebViewConfig when setting up the WebView bridge.

Configuration Options

Config
Description
Default
Supported Version

automaticScreenTracking

Whether to collect $page_view events occurring on the website

false

2.26.0+

automaticEngagementTracking

Whether to collect $engagement events occurring on the website

false

2.28.0+

automaticRouteTracking

Whether to automatically collect page information occurring on the website

true

2.28.0+

Last updated