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 |
Android platform appId |
| iOSAppId |
string |
Yes |
iOS platform appId |
| samplerate |
number |
No |
Sampling rate, range [0,1], default 1 |
| sessionOnErrorSampleRate |
number |
No |
Error collection rate, range [0,1], default 0, supported in SDK 0.2.2+ |
| enableNativeUserAction |
boolean |
No |
Whether to enable Native Action tracking. Recommended to disable for pure uni-app applications. Not supported for Android cloud packaging. |
| enableNativeUserResource |
boolean |
No |
Whether to enable Native Resource auto-tracking. Not supported for Android cloud packaging. Since uni-app initiates network requests via system APIs on iOS, enabling this will auto-collect iOS requests; please disable manual Resource collection on the iOS side to avoid duplicate collection. |
| enableNativeUserView |
boolean |
No |
Whether to enable Native View auto-tracking. Recommended to disable for pure uni-app applications. |
| errorMonitorType |
string/array |
No |
Error supplementary 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 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,), unit: 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 enable WebView data collection via native SDK, default true, supported in SDK 0.2.6+. |
| allowWebViewHost |
array |
No |
List of WebView hosts allowed for data tracking. Collects all when null. |
RUM User Data Tracking
var rum = uni.requireNativePlugin("GCUniPlugin-RUM");
Action
API - startAction
Start an RUM Action.
RUM will bind Resource, Error, and LongTask events that may be triggered during this Action. Avoid calling multiple times within 0.1s. Only one Action can be associated with a View at the same time; a new Action will be discarded if the previous one hasn't ended. It does not interfere with addAction.
rum.startAction({
actionName: 'action name',
actionType: 'action type'
});
| 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.
rum.addAction({
actionName: 'action name',
actionType: 'action type'
});
| Parameter Name |
Parameter Type |
Required |
Parameter Description |
| actionName |
string |
Yes |
Event name |
| actionType |
string |
Yes |
Event type |
| property |
object |
No |
Event context |
View
Auto-collection
Recommended to import and call the collection method in the project's main.js:
import { gcViewTracking } from '@/uni_modules/GC-JSPlugin';
gcViewTracking.startTracking();
Method 2: App.vue + first page combination configuration. Refer to the SDK package 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>
Method 3: Only collect specified pages. Refer to the SDK package 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('Current Page Name');
rum.stopView();
API - onCreateView
Create a page load duration record.
| Field |
Type |
Required |
Description |
| viewName |
string |
Yes |
Page name |
| loadTime |
number |
Yes |
Page load time, nanosecond timestamp |
API - startView
Enter a page.
| Field |
Type |
Required |
Description |
| viewName |
string |
Yes |
Page name |
| property |
object |
No |
Event context |
API - stopView
Leave a page.
| Field |
Type |
Required |
Description |
| property |
object |
No |
Event context |
Error
Auto-collection
import { gcErrorTracking } from '@/uni_modules/GC-JSPlugin';
gcErrorTracking.startTracking();
Manual Collection
rum.addError({
message: 'Error message',
stack: 'Error stack'
});
API - addError
| Field |
Type |
Required |
Description |
| message |
string |
Yes |
Error message |
| stack |
string |
Yes |
Stack information |
| state |
string |
No |
App running state: unknown, startup, run |
| type |
string |
No |
Error type, default uniapp_crash |
| property |
object |
No |
Event context |
Resource
Auto-collection
The SDK provides gcRequest.request, which inherits from uni.request, allowing you to replace the original request method to collect Resource data.
+ import { gcRequest } from '@/uni_modules/GC-JSPlugin';
- uni.request({
+ gcRequest.request({
// ...
});
import { gcRequest } from '@/uni_modules/GC-JSPlugin';
gcRequest.request({
url: requestUrl,
method: method,
header: header,
filterPlatform: ['ios'],
timeout: 30000,
success(res) {
console.log('success:' + JSON.stringify(res));
},
fail(err) {
console.log('fail:' + JSON.stringify(err));
},
complete() {
console.log('complete');
}
});
| Extra Field |
Type |
Required |
Description |
| filterPlatform |
array |
No |
When enableNativeUserResource is enabled, to avoid duplicate collection between iOS auto-collection and manual collection, set filterPlatform: ["ios"] to disable manual collection on iOS. |
Manual Collection
Manually call startResource, stopResource, addResource to implement. Refer to 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
| prototype |
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 |