RUM Configuration¶
Obtaining RUM¶
Standard uni-app:
uni Mini Program:
In uni Mini Programs, RUM initialization is completed by the host App; do not call rum.setConfig(). The automatic collectors and manual collection APIs on this page can be used after the host initialization is complete.
RUM Initialization Configuration¶
rum.setConfig({
androidAppId: 'YOUR_ANDROID_APP_ID',
iOSAppId: 'YOUR_IOS_APP_ID',
harmonyAppId: 'YOUR_HARMONY_APP_ID',
errorMonitorType: 'all',
deviceMonitorType: ['cpu', 'memory']
});
| Parameter | Type | Required | Description |
|---|---|---|---|
| androidAppId | string | Required when releasing on Android | appId for Android platform |
| iOSAppId | string | Required when releasing on iOS | appId for iOS platform |
| harmonyAppId | string | Required when releasing on HarmonyOS | appId for HarmonyOS platform |
| sampleRate | number | No | Sampling rate, range [0,1], default 1 |
| sessionOnErrorSampleRate | number | No | Sample rate for error sessions, range [0,1], default 0, supported from SDK 0.2.2 |
| enableNativeUserAction | boolean | No | Enables Native Action tracking. Disable for pure uni-app applications; not supported in Android cloud packaging |
| enableNativeUserResource | boolean | No | Enables automatic Native Resource tracking. Not supported in Android cloud packaging. Since uni-app initiates network requests via system APIs on iOS, enabling this will automatically collect iOS requests; in that case, disable manual Resource collection on iOS to avoid duplicates |
| enableNativeUserView | boolean | No | Enables automatic Native View tracking. Disable for pure uni-app applications |
| errorMonitorType | string/array | No | Supplementary error monitoring types: all, battery, memory, cpu |
| deviceMonitorType | string/array | No | Page monitoring types: all, battery (Android only), memory, cpu, fps |
| detectFrequency | string | No | Page monitoring frequency: normal, frequent, rare |
| globalContext | object | No | Custom global parameters; special key: track_id |
| enableResourceHostIP | boolean | No | Whether to collect the target domain IP; only affects the default collection when enableNativeUserResource = true |
| enableTrackNativeCrash | boolean | No | Enables Android Java Crash and OC/C/C++ crash monitoring |
| enableTrackNativeAppANR | boolean | No | Enables Native ANR monitoring |
| enableTrackNativeFreeze | boolean | No | Whether to collect Native Freeze |
| nativeFreezeDurationMs | number | No | Native Freeze threshold, range [100,), in milliseconds |
| rumDiscardStrategy | string | No | Discard strategy: discard, discardOldest |
| rumCacheLimitCount | number | No | Maximum number of RUM entries cached locally, default 100000 |
| enableTraceWebView | boolean | No | Whether to collect WebView data via the native SDK, default true, supported from SDK 0.2.6 |
| allowWebViewHost | array | No | List of WebView hosts allowed for data tracking; collects all hosts when null |
RUM User Data Tracking¶
Action¶
For HarmonyOS, to automatically collect click, tap, long press, and Tab switch actions, you need to explicitly start the JS Action collector:
Native Action automatic collection on Android and iOS is controlled by enableNativeUserAction.
API - startAction¶
Starts a RUM Action.
RUM will bind Resource, Error, and LongTask events that may occur during this Action. Avoid calling it multiple times within 0.1s; only one Action is associated with the same View at a time. If the previous Action has not ended, the new Action will be discarded. It does not affect addAction.
| Parameter | Type | Required | Description |
|---|---|---|---|
| actionName | string | Yes | Event name |
| actionType | string | Yes | Event type |
| property | object | No | Event context |
API - addAction¶
Adds an Action event. This type of data cannot be associated with Error, Resource, or LongTask events, and has no discard logic.
| Parameter | Type | Required | Description |
|---|---|---|---|
| actionName | string | Yes | Event name |
| actionType | string | Yes | Event type |
| property | object | No | Event context |
View¶
Automatic Collection¶
It is recommended to use gcViewTracking. It uniformly listens for page lifecycle events (onLoad, onReady, onShow, onHide, onUnload) and App front/background events, and automatically calls the native RUM View API.
Call it once as early as possible in the project's main.js. For Vue 2, call it before creating the root Vue instance; for Vue 3, pass the app returned by createSSRApp:
Vue 2¶
import App from './App';
import { gcViewTracking } from '@/uni_modules/GC-JSPlugin';
import Vue from 'vue';
gcViewTracking.startTracking();
const app = new Vue({
...App
});
app.$mount();
Vue 3¶
import App from './App';
import { gcViewTracking } from '@/uni_modules/GC-JSPlugin';
import { createSSRApp } from 'vue';
export function createApp() {
const app = createSSRApp(App);
gcViewTracking.startTracking(app);
return { app };
}
Collection rules:
- On the first page display,
loading_timeis calculated fromonLoadtoonReady, in nanoseconds. - If the collector starts too late or does not receive the full page lifecycle, the loading time that cannot be reliably calculated uses
-1; when the page is shown again or the App returns to foreground, it uses0. - The current View is stopped when the page is hidden, unloaded, or the App enters background; repeated
onShow/resumewithin the same lifecycle are automatically deduplicated. - Route failures do not generate a View; multiple page instances of the same route maintain their own states.
Compatible Collection Method¶
The older mixin approach is retained for compatibility. New projects should prefer gcViewTracking and not enable both automatic collection methods simultaneously, as this may produce duplicate Views.
For the combined configuration of App.vue + the first page, refer to the SDK package examples Hbuilder_Example/App.vue and Hbuilder_Example/pages/index/index.vue:
// step 1. Add GC-JSPlugin to the uni_modules of the project
// step 2. Add Router monitoring in App.vue
<script>
import { gcWatchRouter } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcWatchRouter],
}
</script>
// step 3. Add pageMixin to the first page
<script>
import { gcPageMixin } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcPageMixin],
}
</script>
To collect only specific pages, refer to the SDK package example Hbuilder_Example/pages/rum/index.vue:
<script>
import { gcPageViewMixinOnly } from '@/uni_modules/GC-JSPlugin';
export default {
mixins: [gcPageViewMixinOnly],
}
</script>
Manual Collection¶
rum.onCreateView({
viewName: 'Current Page Name',
loadTime: 100000000
});
rum.startView({
viewName: 'Current Page Name'
});
rum.stopView();
API - onCreateView¶
Creates a page load duration record.
| Field | Type | Required | Description |
|---|---|---|---|
| viewName | string | Yes | Page name |
| loadTime | number | Yes | Page load duration, in nanoseconds |
API - startView¶
Enters a page.
| Field | Type | Required | Description |
|---|---|---|---|
| viewName | string | Yes | Page name |
| property | object | No | Event context |
API - stopView¶
Leaves a page.
| Field | Type | Required | Description |
|---|---|---|---|
| property | object | No | Event context |
Error¶
Automatic Collection¶
Manual Collection¶
API - addError¶
| Field | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | Error message |
| stack | string | Yes | Stack trace |
| state | string | No | App running state: unknown, startup, run |
| type | string | No | Error type, default uniapp_crash |
| property | object | No | Event context |
Resource¶
Automatic Collection¶
Starting from 0.3.0, it is recommended to use gcResourceTracking. It intercepts the standard uni.request on Android, iOS, and HarmonyOS, automatically collecting RUM Resources for successful or failed requests. If Trace is already initialized, it will generate a Trace Header based on the configured trace type and add it to the request headers; when enableLinkRUMData is enabled, it can associate the RUM Resource with the Trace. Identical request headers already set by business code are not overwritten.
Call startTracking once before making requests, and then continue using uni.request directly:
uni.request({
url: requestUrl,
method: method,
header: header,
timeout: 30000,
success(res) {
console.log('success:' + JSON.stringify(res));
},
fail(err) {
console.log('fail:' + JSON.stringify(err));
},
complete() {
console.log('complete');
}
});
startTracking configuration:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| enableIOS | boolean | No | true |
Whether to collect uni.request via the JS interceptor on iOS. This parameter does not affect Android or HarmonyOS; set to false when enableNativeUserResource is already enabled on iOS to avoid duplication with native URLSession automatic collection |
// When native collection is already enabled on iOS via rum.setConfig({ enableNativeUserResource: true }):
gcResourceTracking.startTracking({
enableIOS: false
});
Usage notes:
- Supported on App Android, App iOS, and App HarmonyOS; should be called during the application startup phase, before the first
uni.requestcall. startTrackingshould only be called once; repeated calls will not reinstall the interceptor.- If Trace is initialized, the request will automatically have a Trace Header added; business code headers with the same name take precedence.
- The original
success,fail, andcompletecallbacks remain unchanged. gcRequest.requestis retained only as a deprecated compatibility API since 0.2.7. After enabling the global collector, there is no need to replaceuni.request, and do not use both collection methods simultaneously.
The old configuration of gcRequest.request is provided for reference only for projects that have not yet migrated:
| Compatibility Field | Type | Required | Description |
|---|---|---|---|
| filterPlatform | array | No | When enableNativeUserResource is enabled, you can set filterPlatform: ["ios"] to disable the old manual collection on iOS |
Manual Collection¶
Implement manually by calling startResource, stopResource, and addResource. See GCResourceTracking.js.
API - startResource¶
| Field | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Request unique identifier |
| property | object | No | Event context |
API - stopResource¶
| Field | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Request unique identifier |
| property | object | No | Event context |
API - addResource¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Request unique identifier |
| content | content object | Yes | Request-related data |
| property | object | No | Event context |
content object¶
| Property | Type | Description |
|---|---|---|
| url | string | Request URL |
| httpMethod | string | HTTP method |
| requestHeader | object | Request headers |
| responseHeader | object | Response headers |
| responseBody | string | Response body |
| resourceStatus | number | Request result status code |
| errorMessage | string | Request failure message |
| errorStack | string | Request failure stack trace |
| fetchStartTime | number | Request start time, in nanoseconds |
| requestStartTime | number | Time when request transmission started, in nanoseconds |
| responseStartTime | number | Time when response reception started, in nanoseconds |
| responseEndTime | number | Time when response reception completed, in nanoseconds |
| tcpStartTime | number | TCP connection start time, in nanoseconds |
| tcpEndTime | number | TCP connection end time, in nanoseconds |
| dnsStartTime | number | DNS resolution start time, in nanoseconds |
| dnsEndTime | number | DNS resolution end time, in nanoseconds |
| sslStartTime | number | SSL connection start time, in nanoseconds |
| sslEndTime | number | SSL connection end time, in nanoseconds |