The Real User Monitoring (RUM) SDK for web and HTML5 provides configuration options for data collection, session management, event filtering, and white screen detection. This reference covers common SDK configurations, runtime APIs, and usage examples.
Initialization parameters
Pass these parameters to ArmsRum.init() to configure the SDK at startup.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| pid | String | Yes | - | Application ID |
| endpoint | String | Yes | - | Data reporting endpoint |
| env | String | No | prod | Application environment. Valid values: prod, gray, pre, daily, local |
| version | String | No | - | Application version |
| user | Object | No | - | User settings. See User parameters |
| spaMode | String | No | false | Single-page application (SPA) route tracking mode. Valid values: hash, history, auto, false |
| beforeReport | Function | No | - | Callback invoked before each report is sent to modify or block the reported data |
| reportConfig | Object | No | - | Data reporting settings. See reportConfig parameters |
| sessionConfig | Object | No | - | Session sampling and storage settings. See sessionConfig parameters |
| collectors | Object | No | - | Data collector toggles. See collectors parameters |
| parseViewName | Function | No | - | Custom parser for the view name (view.name). Receives the page URL as input |
| parseResourceName | Function | No | - | Custom parser for the resource name (resource.name). Receives the resource URL as input |
| evaluateApi | Function | No | - | Custom parser for API events. See evaluateApi parameters |
| filters | Object | No | - | Event filter rules. See filters parameters |
| whiteScreen | Object | No | - | White screen detection settings. See whiteScreen parameters |
| properties | Object | No | - | Global custom properties attached to all events. See properties parameters |
| remoteConfig | Object | No | - | Dynamic configuration delivery. See Dynamic configuration |
CDN initialization
When loading the SDK through Alibaba Cloud Content Delivery Network (CDN), access it from the RumSDK.default global namespace:
const ArmsRum = window.RumSDK.default;
// Initialize the SDK after it has loaded.
// Skip this step if you defined window.__rum before the SDK script tag.
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
});
// Update configuration at runtime
ArmsRum.setConfig('env', 'pre');npm initialization
import ArmsRum from '@arms/rum-browser';
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
});User parameters
Associate RUM sessions with your business accounts through the user object.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| id | String | No | - | User ID. Auto-generated by the SDK and cannot be modified |
| name | String | No | - | Username |
| tags | String | No | - | User tags |
Do not overwrite user.id. The SDK auto-generates this value, and overwriting it affects unique visitor (UV) calculations. To link sessions to your account system, use user.name or user.tags instead.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
user: {
name: 'your user.name',
tags: 'your user.tags',
},
});reportConfig parameters
Control the reporting interval and batch size.
| Parameter | Type | Required | Default | Valid range | Description |
|---|---|---|---|---|---|
| flushTime | Number | No | 3000 | 0 -- 10000 | Reporting interval in milliseconds. Set to 0 for immediate reporting |
| maxEventCount | Number | No | 20 | 1 -- 100 | Maximum number of events per batch |
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
reportConfig: {
flushTime: 0, // Report immediately
maxEventCount: 50, // Up to 50 events per batch
},
});sessionConfig parameters
Configure session sampling, duration limits, and storage.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| sampleRate | Number | No | 1 | Sampling rate from 0 to 1. For example, 0.5 samples 50% of sessions |
| maxDuration | Number | No | 86400000 | Maximum session duration in milliseconds (default: 24 hours) |
| overtime | Number | No | 3600000 | Session inactivity timeout in milliseconds (default: 1 hour) |
| storage | String | No | localStorage | Where to store session data. Valid values: cookie, localStorage |
Storage details
The storage parameter determines where the SDK persists the following data:
_arms_uid-- the unique user ID (user.id)_arms_session-- session metadata in the format${sessionId}-${sampled}-${startTime}-${lastTime}:sessionId-- unique session identifiersampled-- whether this session was selected by samplingstartTime-- session start timestamplastTime-- last activity timestamp
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
sessionConfig: {
sampleRate: 0.5, // Sample 50% of sessions
maxDuration: 86400000, // 24-hour maximum
overtime: 3600000, // 1-hour inactivity timeout
storage: 'cookie', // Use cookie instead of localStorage
},
});collectors parameters
Toggle individual data collectors. All collectors are enabled by default.
| Parameter | Type | Required | Default | Description | |
|---|---|---|---|---|---|
| perf | Boolean \ | Object | No | true | Page performance data |
| webvitals | Boolean \ | Object | No | true | Web Vitals metrics |
| api | Boolean \ | Object | No | true | API requests (XMLHttpRequest, fetch) |
| staticResource | Boolean \ | Object | No | true | Static resource requests |
| consoleError | Boolean \ | Object | No | true | Console errors |
| jsError | Boolean \ | Object | No | true | JavaScript errors |
| action | Boolean \ | Object | No | true | User behavior |
Example
Disable user interaction tracking:
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
collectors: {
action: false,
},
});evaluateApi parameters
The evaluateApi function customizes how XMLHttpRequest and fetch events are parsed. It receives three arguments and returns a Promise<IApiBaseAttr>.
Input arguments
| Parameter | Type | Description |
|---|---|---|
| options | Object | Request parameters: url, headers, and data. Exact fields depend on the request method |
| response | Object | Response body |
| error | Error | Error object. Present only when the request fails |
Return type (IApiBaseAttr)
Returned fields override the SDK defaults. Omitted fields keep their default values.
| Field | Type | Required | Description | |
|---|---|---|---|---|
| name | String | No | API name, typically a converged URL (max 1,000 characters). For example, /list/$id for /list/123. Takes precedence over parseResourceName | |
| message | String | No | Brief description of the API call (max 1,000 characters) | |
| success | Number | No | Request result: 1 = success, 0 = failed, -1 = unknown | |
| duration | Number | No | Total API duration | |
| status_code | Number \ | String | No | Status code |
| snapshots | String | No | Diagnostic snapshot (max 5,000 characters). Stores reqHeaders, params, and resHeaders. Not indexed and cannot be used for querying or aggregation |
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
evaluateApi: async (options, response, error) => {
let respText = '';
if (response && response.text) {
respText = await response.text();
}
return {
name: 'my-custom-api',
success: error ? 0 : 1,
snapshots: JSON.stringify({
params: 'page=1&size=10',
response: respText.substring(0, 2000),
reqHeaders: '',
resHeaders: '',
}),
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
};
},
});filters parameters
Exclude specific resource or exception events from reporting.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
| resource | MatchOption \ | MatchOption[] | No | Exclude static resource and API events (XMLHttpRequest, fetch) that match |
| exception | MatchOption \ | MatchOption[] | No | Exclude exception events that match |
MatchOption type
type MatchOption = string | RegExp | ((value: string) => boolean);String -- matches any URL or message that starts with the specified value. For example,
'https://api.aliyun.com'matches'https://api.aliyun.com/v1/resource'.RegExp -- matches URLs or messages against a regular expression.
Function -- receives the URL or message as input. Return
trueto exclude the event.
When you pass an array of MatchOption values, conditions are evaluated in order. An event is excluded if any condition matches.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
filters: {
exception: [
'Test error', // Messages starting with 'Test error'
/^Script error\.?$/, // Messages matching this regex
(msg) => msg.includes('example-error'), // Custom match function
],
resource: [
'https://example.com/', // URLs starting with 'https://example.com/'
/localhost/i, // URLs containing 'localhost'
(url) => url.includes('example-resource'),
],
},
});whiteScreen parameters
Detect blank or white screen states in your application. Supported in Chrome 40 and IE 9+.
| Parameter | Type | Description |
|---|---|---|
| detectionRules | Array<DetectionRule> | One or more detection rules. Rules run in the configured order |
DetectionRule
| Parameter | Type | Required | Default | Description | |
|---|---|---|---|---|---|
| target | String | Yes | - | CSS selector for the element to monitor | |
| test_when | Array | Yes | - | Events that trigger detection. Valid values: LOAD, ERROR, ROUTE_CHANGE, LEAVE | |
| delay | Number | No | 0 | Delay in milliseconds before detection starts after a trigger event (except ERROR and LEAVE) | |
| tester | String \ | Function | Yes | - | Detection method. Valid values: HAS_CONTENT, SAMPLE, SCREENSHOT, or a custom function |
| ignoreUrlList | Array<String> | No | [] | Page URLs to skip | |
| configOptions | ConfigOptions | No | - | Tester-specific options. See ConfigOptions |
Trigger events
| Event | Description |
|---|---|
LOAD | Page loading completes |
ERROR | A global JavaScript error occurs |
ROUTE_CHANGE | The route (history or hash) changes |
LEAVE | The page is about to close |
Detection methods
| Method | How it works |
|---|---|
HAS_CONTENT | Checks whether nodes exist and contain textContent |
SAMPLE | Sets sampling points across the target area and checks whether the topmost DOM element at each point belongs to an allowed element set |
SCREENSHOT | Takes a canvas screenshot and compares pixel blocks to calculate the white screen rate |
| Custom function | Receives the target element as input. Return a CustomTesterResult or Promise<CustomTesterResult> |
CustomTesterResult type:
type CustomTesterResult = {
hasContent: boolean; // true = content exists; false = white screen detected
message?: string; // Error message
snapshot?: Record<string, any>; // Diagnostic data
}ConfigOptions
Options specific to the SCREENSHOT and SAMPLE detection methods.
SCREENSHOT options:
| Parameter | Type | Default | Description |
|---|---|---|---|
| colorRange | Array<String> | ['rgb(255, 255, 255)'] | Colors treated as "white." Format: rgb(r, g, b) |
| fillColor | String | 'rgba(0, 100, 200, 255)' | Fill color applied to images, videos, canvases, SVGs, and iframes during screenshotting. Must not overlap with colorRange |
| horizontalOffset | Number | 0 | Horizontal offset (px) from the target element's left edge. Use this to exclude a left sidebar |
| verticalOffset | Number | 0 | Vertical offset (px) from the target element's top edge. Use this to exclude a top navbar |
| pixels | Number | 10 | Pixel block size (pixels x pixels) for comparison |
| threshold | Number | 0.8 | White screen rate threshold. A rate above this value triggers a white screen event |
| dpr | Number | 0.3 | Scaling ratio for the screenshot image |
| ignoreElements | Array<String> | [] | CSS selectors for elements to exclude from screenshots |
SAMPLE options:
| Parameter | Type | Default | Description | ||
|---|---|---|---|---|---|
| sampleMethod | `1 \ | 2 \ | 3` | 2 | Sampling pattern: 1 = cross, 2 = intersecting cross, 3 = rice |
| checkPoints | Number | 10 | Number of radial sampling points. Total points: cross/intersecting cross = 4 * checkPoints + 1; rice = 8 * checkPoints + 1 | ||
| threshold | Number | 0.8 | White screen rate threshold | ||
| whiteBoxElements | Array<String> | [] | CSS selectors for elements considered "white." When the topmost element at a sampling point matches any selector, the white screen count increments |
Shared option:
Both SCREENSHOT and SAMPLE support the debug option (Boolean, default: false). When enabled, detection details are printed to the browser developer tools console.
Examples
Screenshot-based detection:
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
whiteScreen: {
detectionRules: [{
target: '#root',
test_when: ['LOAD', 'ERROR', 'ROUTE_CHANGE', 'LEAVE'],
delay: 5000,
tester: 'SCREENSHOT',
configOptions: {
colorRange: ['rgb(255, 255, 255)', 'rgb(0, 0, 0)'],
threshold: 0.9,
pixels: 10,
horizontalOffset: 210,
verticalOffset: 50,
},
}],
},
});Sampling-based detection:
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
whiteScreen: {
detectionRules: [{
target: '#root',
test_when: ['LOAD', 'ERROR', 'ROUTE_CHANGE', 'LEAVE'],
delay: 5000,
tester: 'SAMPLE',
configOptions: {
sampleMethod: 2,
checkPoints: 10,
threshold: 0.9,
whiteBoxElements: ['.el-skeleton'],
},
}],
},
});Custom detection function:
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
whiteScreen: {
detectionRules: [{
target: '#root',
test_when: ['LOAD', 'ERROR', 'ROUTE_CHANGE', 'LEAVE'],
delay: 5000,
tester: async (element) => {
return {
hasContent: false,
message: 'Custom error message',
snapshot: {
checkPoints: 100,
rate: 0.99,
checkdata: '......',
},
};
},
}],
},
});properties parameters
Attach global custom properties to all reported events.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
| [key: string] | String \ | Number | No | Custom key-value pair. The key must be a string that conforms to the JSON specification, with a maximum of 50 characters (truncated if longer). String value: max 2,000 characters. Non-string and non-number values are dropped |
Merge behavior
Global properties (set in
init()) and event-level properties (set throughevaluateApi,sendCustom,sendException, orsendResource) are merged at storage time.Event-level properties take precedence. If the same key exists in both, the event-level value wins.
After merging, a maximum of 20 key-value pairs are kept. Excess pairs are sorted by key and removed.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
properties: {
prop_string: 'xx',
prop_number: 2,
// Keys longer than 50 characters are truncated
more_than_50_key_limit_012345678901234567890123456789: 'yy',
// String values longer than 2,000 characters are truncated
more_than_2000_value_limit: new Array(2003).join('1'),
// Invalid types -- these pairs are removed
prop_null: null,
prop_undefined: undefined,
prop_bool: true,
},
});Dynamic configuration
The SDK supports remote delivery of configuration settings. During initial load, the SDK fetches remote settings that override the static values from init() and updates features such as instrumentation and data reporting accordingly.
Step 1: Configure in the ARMS console
Go to Application List and open your application.
Go to Application Settings > SDK config.
Set the desired configuration values.
Click Confirm Update Dynamic Configuration to push the settings to the remote Object Storage Service (OSS) server.
Step 2: Enable in the SDK
Add the remoteConfig field to your initialization code with the region where your application is hosted.
CDN:
window.__rum = {
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
remoteConfig: {
region: "cn-hangzhou" // Example: "ap-southeast-1" for Singapore
}
};<script async src="https://xxid-sdk.rum.aliyuncs.com/v2/browser-sdk.js"></script>npm:
import ArmsRum from '@arms/rum-browser';
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
remoteConfig: {
region: "cn-hangzhou" // Example: "ap-southeast-1" for Singapore
}
});Caching behavior
After retrieving the remote configuration, the SDK caches the settings locally. On subsequent initializations, the SDK prioritizes the cached configuration.
Dynamic configuration requires SDK version 0.0.37 or later when importing through CDN with a pinned version.Auto-resolved parameters
The SDK auto-resolves these properties from IP addresses and User-Agent headers. Explicitly set values take precedence over auto-resolved values.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device | Object | No | Device information |
| os | Object | No | Operating system and container information |
| geo | Object | No | Geolocation |
| isp | Object | No | ISP/carrier information |
| net | Object | No | Network connection information |
For field details, see the Common properties section in the Log data topic.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
geo: {
country: 'your custom country info',
city: 'your custom city info',
},
});SDK APIs
After initialization, use these methods to modify configuration and report custom data.
getConfig
Retrieve the current SDK configuration:
const config = ArmsRum.getConfig();setConfig
Update SDK configuration at runtime. Pass a single key-value pair or a full configuration object:
// Set a single value
ArmsRum.setConfig('env', 'pre');
// Set multiple values
const config = ArmsRum.getConfig();
ArmsRum.setConfig({
...config,
version: '1.0.0',
env: 'pre',
});sendCustom
Report a custom event. The type and name fields are required.
| Parameter | Type | Required | Description |
|---|---|---|---|
| type | String | Yes | Event type |
| name | String | Yes | Event name |
| group | String | No | Event group |
| value | Number | No | Numeric value |
| properties | Object | No | Custom properties |
ArmsRum.sendCustom({
type: 'CustomEventType1',
name: 'customEventName2',
group: 'customEventGroup3',
value: 111.11,
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});sendException
Report a custom exception. The name and message fields are required.
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | String | Yes | Exception name |
| message | String | Yes | Exception message |
| file | String | No | Source file |
| stack | String | No | Stack trace |
| line | Number | No | Line number |
| column | Number | No | Column number |
| properties | Object | No | Custom properties |
ArmsRum.sendException({
name: 'customErrorName',
message: 'custom error message',
file: 'custom exception filename',
stack: 'custom exception error.stack',
line: 1,
column: 2,
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});sendResource
Report a custom resource event. The name, type, and duration fields are required.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
| name | String | Yes | Resource name | |
| type | String | Yes | Resource type (for example, css, javascript, xmlhttprequest, fetch, api, image, font) | |
| duration | String | Yes | Response time | |
| success | Number | No | Result: 1 = success, 0 = failed, -1 = unknown | |
| method | String | No | HTTP method | |
| status_code | Number \ | String | No | Status code |
| message | String | No | Response message | |
| url | String | No | Request URL | |
| trace_id | String | No | Distributed trace ID | |
| properties | Object | No | Custom properties |
ArmsRum.sendResource({
name: 'getListByPage',
message: 'success',
duration: 800,
url: 'https://www.aliyun.com/data/getListByPage',
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});