RUM Configuration¶
RUM Initialization Configuration¶
var rum = uni.requireNativePlugin("GCUniPlugin-RUM");
rum.setConfig({
androidAppId: 'YOUR_ANDROID_APP_ID',
iOSAppId: 'YOUR_IOS_APP_ID',
errorMonitorType: 'all',
deviceMonitorType: ['cpu', 'memory']
});
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| androidAppId | string | Yes | appId for Android platform |
| iOSAppId | string | Yes | appId for iOS platform |
| samplerate | number | No | Sampling rate, range [0,1], default 1 |
| sessionOnErrorSampleRate | number | No | Error sampling rate, range [0,1], default 0, supported since SDK 0.2.2 |
| enableNativeUserAction | boolean | No | Whether to enable Native Action tracking. Recommended to disable for pure uni-app applications. Not supported in Android cloud packaging. |
| enableNativeUserResource | boolean | No | Whether to enable 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 | Whether to enable automatic Native View tracking. Recommended to disable for pure uni-app applications. |
| errorMonitorType | string/array | No | Error supplementary monitoring type: all, battery, memory, cpu |
| deviceMonitorType | string/array | No | Page monitoring type: 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 target domain IP. Only affects default collection when enableNativeUserResource = true |
| enableTrackNativeCrash | boolean | No | Whether to enable Android Java Crash and OC/C/C++ crash monitoring |
| enableTrackNativeAppANR | boolean | No | Whether to enable 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 in local cache, default 100000 |
| enableTraceWebView | boolean | No | Whether to enable WebView data collection through the native SDK, default true, supported since SDK 0.2.6 |
| allowWebViewHost | array | No | List of WebView hosts allowed for data tracking. When null, all hosts are collected. |
RUM User Data Tracking¶
Action¶
API - startAction¶
Start a RUM Action.
RUM binds Resource, Error, and LongTask events that may be triggered during this Action. Avoid calling multiple times within 0.1s; only one Action is associated with a View at a time. If the previous Action has not ended, the new Action will be discarded. It does not affect addAction.
| Parameter Name | Parameter Type | Required | Parameter Description |
|---|---|---|---|
| actionName | string | Yes | Event name |
| actionType | string | Yes | Event type |
| property | object | No | Event context |
API - addAction¶
Add an Action event. This type of data cannot be associated with Error, Resource, or LongTask, and has no discard logic.
| Parameter Name | Parameter Type | Required | Parameter 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 foreground/background events, and automatically calls the native RUM View API.
Call this 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:
- When the page is first displayed,
loading_timeis calculated fromonLoadtoonReady, in nanoseconds. - If the collector starts too late or does not receive the complete page lifecycle, the load time cannot be reliably calculated and defaults to
-1; when the page is shown again or the app returns to the foreground, it defaults to0. - When the page is hidden, unloaded, or the app enters the background, the current View is stopped. Repeated
onShow/resumeevents within the same lifecycle are automatically deduplicated. - Route failures do not generate a View. Multiple page instances with the same route maintain their own states.
Compatibility Collection Method¶
The old mixin method is retained for compatibility. New projects should use gcViewTracking as the priority. Do not enable both automatic collection methods simultaneously, as this may cause duplicate Views.
The combined configuration of App.vue and the first page can be referenced in the SDK example project Hbuilder_Example/App.vue and Hbuilder_Example/pages/index/index.vue:
// step 1. Add GC-JSPlugin to the project uni_modules
// 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 example project 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¶
Create a record of page load duration.
| Field | Type | Required | Description |
|---|---|---|---|
| viewName | string | Yes | Page name |
| loadTime | number | Yes | Page load duration, in nanoseconds |
API - startView¶
Enter the page.
| Field | Type | Required | Description |
|---|---|---|---|
| viewName | string | Yes | Page name |
| property | object | No | Event context |
API - stopView¶
Leave the 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¶
It is recommended to use gcResourceTracking (SDK 0.2.7+). It installs a global interceptor for standard uni.request, automatically generates Resource identifiers, injects request headers matching the Trace configuration, and collects RUM Resource data on request success or failure.
Call startTracking once before making requests, 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 JS interceptor on iOS. Always enabled on Android. When enableNativeUserResource is already enabled on iOS, set this to false to avoid duplicates with native URLSession automatic collection. |
// When native collection is already enabled on iOS via rum.setConfig({ enableNativeUserResource: true }):
gcResourceTracking.startTracking({
enableIOS: false
});
Usage notes:
- Only supported on App Android and App iOS. It should be executed 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 configured, requests matching the Trace allowlist will have Trace headers injected. Explicit request headers set in business code take precedence.
- Original
success,fail, andcompletecallbacks remain unchanged. gcRequest.requestis retained only as a deprecated compatibility API since 0.2.7. Do not replaceuni.requestafter enabling the global collector, and do not use both collection methods in parallel.
The old configuration of gcRequest.request is provided for reference 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 the iOS side. |
Manual Collection¶
You can implement it manually by calling startResource, stopResource, and addResource. See GCRequest.js.
API - startResource¶
| Field | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Unique request identifier |
| property | object | No | Event context |
API - stopResource¶
| Field | Type | Required | Description |
|---|---|---|---|
| key | string | Yes | Unique request identifier |
| property | object | No | Event context |
API - addResource¶
| Parameter Name | Parameter Type | Required | Parameter Description |
|---|---|---|---|
| key | string | Yes | Unique request identifier |
| content | content object | Yes | Request-related data |
content object¶
| Property | Parameter Type | Parameter Description |
|---|---|---|
| url | string | Request URL |
| httpMethod | string | HTTP method |
| requestHeader | object | Request headers |
| responseHeader | object | Response headers |
| responseBody | string | Response body |
| resourceStatus | string | Request result status code |