UniApp Session Replay¶
UniApp Session Replay currently supports Android and iOS, and does not yet support HarmonyOS. Standard uni-app is initialized through the optional GC-UniSessionReplay module; uni mini programs are initialized by the host app through the Native SDK for the corresponding platform.
Prerequisites¶
- Completed UniApp application access, and initialized the Mobile SDK, RUM, and View collection;
- Use
GC-UniPlugin,GC-JSPlugin, andGC-UniSessionReplayversion0.3.0or later, and keep the version numbers of the three modules consistent; - HBuilderX version must be
4.25.0or later; - Android supports a minimum of API 24, and iOS supports a minimum of 12.0.
Installation¶
From the Hbuilder_Example/uni_modules of the corresponding version in the SDK source repository, copy GC-UniSessionReplay to the uni_modules directory of your application project:
Initialization¶
First complete Mobile SDK and RUM initialization, then initialize Session Replay. It is recommended to call GCUniSessionReplay.setConfig() once before starting automatic View collection:
import {
GCUniSessionReplay,
GCSessionReplayTouchPrivacy,
GCSessionReplayTextAndInputPrivacy,
GCSessionReplayImagePrivacy
} from '@/uni_modules/GC-UniSessionReplay';
GCUniSessionReplay.setConfig({
sampleRate: 100,
sessionReplayOnErrorSampleRate: 0,
touchPrivacy: GCSessionReplayTouchPrivacy.SHOW,
textAndInputPrivacy:
GCSessionReplayTextAndInputPrivacy.MASK_SENSITIVE_INPUTS,
imagePrivacy: GCSessionReplayImagePrivacy.MASK_NON_BUNDLED_ONLY,
enableLinkRUMKeys: ['wgt_id', 'wgt_name']
});
Recommended initialization order:
mobileAgent.sdkConfig()
-> rum.setConfig()
-> GCUniSessionReplay.setConfig()
-> gcViewTracking.startTracking()
Collecting uni-app Page Content¶
uni-app pages on Android and iOS run in the app's built-in WebView. After initializing GC-UniSessionReplay, you also need to inject the Web monitoring SDK into uni-app's rendering WebView through gcViewTracking.evalSessionReplayJS() and enable Web Session Replay. Only after this operation can Session Replay display uni-app page content and user actions on the pages.
Configure the following injection script before calling gcViewTracking.startTracking():
import { gcViewTracking } from '@/uni_modules/GC-JSPlugin';
// #ifdef APP-PLUS
const jsCode = `
// Load the Web monitoring SDK in uni-app's rendering WebView
var script = document.createElement('script');
script.src = 'https://static.guance.com/browser-sdk/v3/dataflux-rum.js';
script.onload = function() {
DATAFLUX_RUM.setGlobalContextProperty('wgt_id', 'wgt_id_1');
DATAFLUX_RUM.setGlobalContextProperty('wgt_name', 'wgt_name_1');
window.DATAFLUX_RUM &&
window.DATAFLUX_RUM.init({
// In bridge mode, the data receiving address still needs to be validated, but RUM data will be sent through
// FTWebViewJavascriptBridge and will not request this address
datakitOrigin: window.location.origin,
});
window.DATAFLUX_RUM.startSessionReplayRecording();
};
document.head.appendChild(script);
`;
gcViewTracking.evalSessionReplayJS(jsCode);
// #endif
wgt_id and wgt_name are optional custom fields that can be used to identify data generated by the uni-app rendering layer. If you need to associate these fields with Session Replay data, declare the field names in enableLinkRUMKeys of GCUniSessionReplay.setConfig(), and set actual values for the fields with the same names through DATAFLUX_RUM.setGlobalContextProperty(). If you do not need to use these fields to distinguish data, you can leave enableLinkRUMKeys unconfigured and delete the two setGlobalContextProperty() calls from the injection script.
evalSessionReplayJS() executes this script in the rendering WebView corresponding to the uni-app page, so you do not need to call it repeatedly on each page.
This collects uni-app's own rendered pages. To collect external web pages loaded by the <web-view> component, see WebView Session Replay instructions below.
WebView Session Replay¶
Supported starting from SDK 0.3.0. Applies to Android and iOS, and does not yet support HarmonyOS.
Android only supports offline packaging and the uni mini program host app scenario; cloud packaging is not yet supported. In the Android project, complete the
ft-pluginconfiguration according to Apply Plugin, apply the plugin in the app main module'sbuild.gradle, and then rebuild and install the app. Enabling onlyenableTraceWebViewor callingstartSessionReplayRecording()cannot replace this step.
When recording web pages loaded by the <web-view> component, first complete Mobile SDK, RUM, and Session Replay initialization on this page and enable View monitoring collection. For uni mini programs, the host app completes SDK, RUM, and Session Replay initialization for the corresponding platform. Load the target WebView only after initialization is complete.
Complete the app-side configuration according to WebView Data Monitoring, confirm that enableTraceWebView in rum.setConfig() is true (the default value), and that allowWebViewHost allows collection of the target page. Then complete WebView page initialization and enable recording in the page loaded by <web-view>:
For privacy configuration of web page content, use the privacy configuration of the Web SDK.
Parameters¶
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| sampleRate | number | No | Sampling rate, range [0,100]; 0 means no collection, 100 means full collection, default 100 |
| sessionReplayOnErrorSampleRate | number | No | Error collection rate, range [0,100]; when an error occurs in a session that was not sampled by sampleRate, collect data from the 1 minute before the error at this rate, default 0 |
| touchPrivacy | string | No | Touch privacy level: show, hide, default hide |
| textAndInputPrivacy | string | No | Text and input privacy level: maskSensitiveInputs, maskAllInputs, maskAll, default maskAll |
| imagePrivacy | string | No | Image privacy level: maskNonBundledOnly, maskAll, maskNone, default maskAll; on Android, maskNonBundledOnly is mapped to masking only large images |
| enableSwiftUI | boolean | No | iOS only; whether to record SwiftUI pages, default false |
| enableLinkRUMKeys | array |
No | Associate the specified RUM Context fields with Session Replay data |
Viewing Session Replay¶
Mobile Session Replay is viewed in the same way as Web Session Replay. For details, see Web Session Replay Access.