Skip to content

WebViewTracking

Xavier F. Gouchet edited this page Sep 4, 2024 · 1 revision

object WebViewTracking

An entry point to Datadog WebView Tracking feature.

Types

WebViewTracking._InternalWebViewProxy

Functions

enable

@MainThread

@JvmOverloads

@JvmStatic

fun enable(webView: WebView, allowedHosts: List<String>, @FloatRange(from = 0.0, to = 100.0)logsSampleRate: Float = 100.0f, sdkCore: SdkCore = Datadog.getInstance())

Attach the bridge to track events from the WebView as part of the same session. This method must be called from the Main Thread. Please note that:

  • you need to enable the JavaScript support in the WebView settings for this feature to be functional:
webView.settings.javaScriptEnabled = true
  • by default, navigation will happen outside of your application (in a browser or a different app). To prevent that and ensure Datadog can track the full WebView user journey, attach a android.webkit.WebViewClient to your WebView, as follow:
webView.webViewClient = WebViewClient()

The WebView events will not be tracked unless the web page's URL Host is part of the list of allowed hosts.

Parameters
webView the webView on which to attach the bridge.
allowedHosts a list of all the hosts that you want to track when loaded in the WebView (e.g.: listOf("example.com", "example.net")).
logsSampleRate the sample rate for logs coming from the WebView, in percent. A value of 30 means we'll send 30% of the logs. If value is 0, no logs will be sent to Datadog. Default is 100.0 (ie: all logs are sent).
sdkCore SDK instance on which to attach the bridge. More here.
Clone this wiki locally