WebView Data Monitoring¶
First complete the host configuration according to the runtime platform and packaging method below, then initialize the web page.
Android supports only the offline packaging and uni mini program scenarios.
Configuration¶
For a standard uni-app, configure during RUM initialization:
import { rum } from '@/uni_modules/GC-UniPlugin';
rum.setConfig({
enableTraceWebView: true,
allowWebViewHost: [
'example.com'
]
});
enableTraceWebView: Whether to enable the WebView RUM bridge; defaults totrue;allowWebViewHost: List of WebView Hosts allowed for tracking; if not set, all Hosts are collected.
For a standard uni-app, complete Mobile SDK and RUM initialization before loading the WebView. For a uni mini program, the host app completes SDK and RUM initialization; do not initialize again.
Platform Notes¶
- Android and iOS use the standard
<web-view>; actual capabilities depend on the Native SDK and packaging method; - For HarmonyOS, choose the corresponding integration method based on whether the business side holds a
WebviewController; see HarmonyOS Integration; - WebView collection capabilities in uni mini programs are provided by the Native SDK integrated into the host app; Android hosts also need to install and apply
ft-plugin.
HarmonyOS Integration¶
The HarmonyOS WebView Bridge must be installed before the target page loads. Choose one of the following methods based on whether the business side holds a WebviewController; do not use both methods on the same WebView.
Business Side Does Not Hold WebviewController¶
When a standard uni-app page does not directly manage a WebviewController, use the native embedding component gcwebview provided by the plugin on the HarmonyOS platform. This component automatically installs the Bridge when the controller is available and automatically releases it when the component is destroyed.
<!-- #ifdef APP-HARMONY -->
<embed
class="harmony-webview"
tag="gcwebview"
:options="{
src: webviewUrl,
viewName: 'order-detail'
}"
></embed>
<!-- #endif -->
<!-- #ifndef APP-HARMONY -->
<web-view :src="webviewUrl" />
<!-- #endif -->
src: Web page URL to load;viewName: Optional Native RUM View name. We recommend setting a meaningful and stable name for each business WebView; if not set,webviewis used by default;- When using
gcwebview, there is no need to callrum.attachWebView()orrum.detachWebView().
Business Side Holds WebviewController¶
In HarmonyOS native pages, UTS native WebViews, or uni mini program host apps, if the business code holds a WebviewController itself, call rum.attachWebView() in the controller's onControllerAttached callback, and ensure that the target page has not yet been loaded at this point:
Web({ src: webviewUrl, controller })
.onControllerAttached(() => {
rum.attachWebView(controller, 'order-detail');
});
Release the corresponding Bridge when the WebView is destroyed:
rum.attachWebView() takes effect only when RUM initialization has completed and enableTraceWebView is true. Therefore, call rum.setConfig() before creating the WebView or binding the controller; if you bind after the page has finished loading, the Web RUM Bridge for the first document will be missed.
Before using this method in a uni mini program host app, you must also complete registration of the host extension's registerNativeModules(context) before opening the uni mini program for the first time.
Initialize the Web Page¶
After completing the host configuration above, proceed to Page Initialization, then check reporting according to WebView Data Verification.
Usage Recommendations¶
- Complete Web SDK integration according to the page initialization instructions above;
- Load the WebView only after Native SDK/RUM initialization is complete;
- Use
allowWebViewHostto restrict the business domains allowed for bridging; - For HarmonyOS, choose either the
gcwebviewmethod or the manualattachWebView()method; - Verify the association between WebView data and the current RUM View on real Android, iOS, and HarmonyOS devices respectively.