Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Overview

Real User Monitoring allows you to monitor web views and eliminate blind spots in your hybrid mobile applications.

You can perform the following:

  • Track user journeys across web and native components in mobile applications
  • Scope the root cause of latency to web pages or native components in mobile applications
  • Support users that have difficulty loading web pages on mobile devices

Note: When Web View Tracking is enabled, Browser Session Replay will be disabled, no matter how the Browser SDK is configured.

Setup

Prerequisites

Set up the RUM Browser SDK on the web page you want rendered on your mobile application. For more information, see RUM Browser Monitoring.

Declare DatadogWebViewTracking as a dependency (iOS only)

To enable Crash Reporting, make sure to also enable RUM and, or Logs. Then, add the package according to your dependency manager and update your initialization snippet.

You can use CocoaPods to install dd-sdk-ios:

pod 'DatadogWebViewTracking'

To integrate using Apple’s Swift Package Manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/Datadog/dd-sdk-ios.git", .upToNextMajor(from: "2.0.0"))

In your project, link the following libraries:

DatadogCore
DatadogWebViewTracking

You can use Carthage to install dd-sdk-ios:

github "DataDog/dd-sdk-ios"

In Xcode, link the following frameworks:

DatadogWebViewTracking.xcframework

Instrument your web views

  1. If you want to forward RUM events coming from web pages, download the latest version of RUM Android SDK and setup RUM feature following the dedicated guide.

  2. If you want to forward Log events coming from web pages, download the latest version of Logs Android SDK and setup Logs feature following the dedicated guide.

  3. Add the Gradle dependency by declaring the dd-sdk-android-webview library as a dependency in the module-level build.gradle file:

    dependencies {
        implementation "com.datadoghq:dd-sdk-android-webview:x.x.x"
    }
    
  4. Enable tracking for web views with the following code snippet:

      WebViewTracking.enable(webView, allowedHosts)
    

The RUM iOS SDK provides APIs for you to control web view tracking. To enable Web View Tracking, provide the WKWebView instance.

import WebKit
import DatadogWebViewTracking

let webView = WKWebView(...)
WebViewTracking.enable(webView: webView, hosts: ["example.com"])

To disable Web View Tracking:

WebViewTracking.disable(webView: webView)

The RUM Flutter SDK provides APIs for you to control web view tracking when using the webview_flutter package. To add Web View Tracking, call the trackDatadogEvents extension method on WebViewController, providing the list of allowed hosts.

Add the following to your pubspec.yaml with the most recent version of the datadog_webview_tracking plugin:

dependencies:
  datadog_webview_tracking: ^x.x.x

For example:

import 'package:datadog_flutter_plugin/datadog_flutter_plugin.dart';

webViewController = WebViewController()
  ..setJavaScriptMode(JavaScriptMode.unrestricted)
  ..trackDatadogEvents(
    DatadogSdk.instance,
    ['myapp.example'],
  )
  ..loadRequest(Uri.parse('myapp.example'));

Note that JavaScriptMode.unrestricted is required for tracking to work on Android.

  1. Add react-native-webview to your application following the official installation documentation.

  2. Import WebView from @datadog/mobile-react-native-webview instead of react-native-webview:

    import { WebView } from '@datadog/mobile-react-native-webview';
    // or
    import WebView from '@datadog/mobile-react-native-webview';
    
  3. You can use all existing functionalities from react-native-webview as the WebView component from @datadog/mobile-react-native-webview wraps the react-native-webview component.

  4. Provide the list of hosts to be tracked by Datadog inside the web view by using the allowedHosts prop of your WebView component:

    <WebView
        source={{ uri: 'https://www.example.com' }}
        allowedHosts={['example.com']}
    />
    

Access your web views

Your web views appear in the RUM Explorer with associated service and source attributes. The service attribute indicates the web component the web view is generated from, and the source attribute denotes the mobile application’s platform, such as Android.

Filter on your Android and Android TV applications, and click a session. A side panel with a list of events in the session appears.

Webview events captured in a session in the RUM Explorer

Click Open View waterfall to navigate from the session to a resource waterfall visualization in the view’s Performance tab.

Further Reading

Documentation, liens et articles supplémentaires utiles: