The Real User Monitoring (RUM) SDK for minigames of Application Real-Time Monitoring Service (ARMS) provides a wide variety of custom configurations to meet your business requirements. This topic describes the common SDK configurations of minigames for reference purposes.
SDK parameters
Parameter | Type | Description | Required | Default value |
pid | String | The minigame ID. | Yes | - |
endpoint | String | The address to which monitoring data is reported. | Yes | - |
env | String | The environment of the minigame. Valid values:
| No | prod |
version | String | The version of the minigame. | No | - |
user | Object | The user settings. By default, the user ID (user.id) is generated by the SDK. | No | - |
beforeReport | Function | The function that is called before reporting data to modify or block the reported data. | No | - |
reportConfig | Object | The data reporting settings. For more information, see reportConfig parameters. | No | - |
sessionConfig | Object | The session sampling rate and timeout settings. For more information, see sessionConfig parameters. | No | - |
collectors | Object | The collectors settings. For more information, see collectors parameters. | No | - |
parseResourceName | Function | The function used to parse the resource name (resource.name). The input parameter is the URL of the resource. | No | - |
evaluateApi | Function | The function used to parse API events. For more information, see evaluateApi parameters. | No | - |
filters | Object | The event filtering settings. For more information, see filters configuration. | No | - |
properties | Object | The custom properties that take effect for all events. For more information, see properties configuration. | No | - |
User parameters
Parameter | Type | Description | Required | Default value |
id | String | The user ID, which is generated by the SDK and cannot be modified. | No | Generated by the SDK by default |
tags | String | The tags. | No | - |
name | String | The username. | No | - |
Example
If you want to use your own account system, we recommend that you change the username (user.name) or tags (user.tags) instead of the user ID (user.id). Overwriting the user ID affects the unique visitor (UV) data.
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
user: {
name: 'your user.name',
tags: 'your user.tags',
},
});
reportConfig parameters
Parameter | Type | Description | Required | Default value |
flushTime | Number | The interval at which data is reported. Valid values: 0 to 10000. | No | 3000 |
maxEventCount | Number | The maximum number of data entries reported at a time. Valid values: 1 to 100. | No | 20 |
Example
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
reportConfig: {
flushTime: 0, // Specify that data is immediately reported.
maxEventCount: 50, // Specify the maximum number of data entries reported at a time.
},
});
sessionConfig parameters
Parameter | Type | Description | Required | Default value |
sampleRate | Number | The sampling rate. Valid values: 0 to 1. The value 0.5 specifies a 50% sampling rate. | No | 1 |
maxDuration | Number | The maximum duration of a session. Unit: milliseconds. Default value: 86400000 (24 hours). | No | 86400000 |
overtime | Number | The timeout duration of a session. Unit: milliseconds. Default value: 3600000 (1 hour). | No | 3600000 |
Parameter | Type | Description | Required | Default value |
sampleRate | Number | The sampling rate. Valid values: 0 to 1. The value 0.5 specifies a 50% sampling rate. | No | 1 |
maxDuration | Number | The maximum duration of a session. Unit: milliseconds. Default value: 86400000 (24 hours). | No | 86400000 |
overtime | Number | The timeout duration of a session. Unit: milliseconds. Default value: 1800000 (half an hour). | No | 1800000 |
The user ID and session information is stored in the local cache of the minigame:
_arms_uid: the unique user ID (user.id).
_arms_session: the semantic session information.
sessionId: the unique session ID.
sampled: indicates whether sampling was triggered.
startTime: the start timestamp of the session.
lastTime: the timestamp when the session was last active.
`${sessionId}-${sampled}-${startTime}-${lastTime}`
Example
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
sessionConfig: {
sampleRate: 0.5, // Specify a 50% sampling rate.
maxDuration: 86400000,
overtime: 3600000,
},
});
collectors parameters
The SDK uses collectors, such as API and Exception, to collect minigame monitoring data.
Parameter | Type | Description | Required | Default value |
perf | Boolean | object | Tracks the performance data of the minigame. | No | true |
api | Boolean | object | Tracks API requests. | No | true |
staticResource | Boolean | object | Tracks static resource requests. | No | true |
consoleError | Boolean | object | Tracks console errors. | No | true |
jsError | Boolean | object | Tracks JavaScript errors. | No | true |
action | Boolean | object | Tracks user behavior. | No | true |
Example
In the following example, the collection of user interaction data is disabled.
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
collectors: {
api: false,
},
});
evaluateApi parameters
The evaluateApi function provides custom parsing for API request events.
Parameter | Type | Description |
options | Object | The request parameters, including url, headers, and data. The parameters depend on the request method. |
response | Object | The response body of the request. |
error | Error | The error. This parameter is optional and is available only when the request fails. |
This function can be called asynchronously. Promise<IApiBaseAttr> is returned. The following table describes IApiBaseAttr.
Parameter | Type | Description | Required |
name | String | The API name, which is generally a converged URL and can be up to 1,000 characters in length. For example, if the URL is Important This parameter takes precedence over what is returned by the parseResourceName function. | No |
message | String | The API information, which is a brief string to describe the API that contains no more than 1,000 characters. | No |
success | Number | Indicates whether the request was successful. Valid values:
| No |
duration | Number | The total duration of the request. | |
status_code | Number | string | The status code. | No |
snapshots | String | The snapshot. Note A snapshot stores information about request headers, parameters, and response headers. You can customize the fields that a snapshot is composed of. Snapshots are mainly used to troubleshoot exceptions. A snapshot cannot be configured as a filter condition for query or aggregation because it has no index. It can only be a string with up to 5,000 characters. | No |
Example
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
evaluateApi: async (options, response, error) => {
// The returned fields will overwrite the default content. If the fields are not returned, the default content is used.
return {
name: 'my-custom-api',
success: error ? 0 : 1,
// Optional.
snapshots: JSON.stringify({
params: 'page=1&size=10', // The input parameter.
response: '', // The returned value.
reqHeaders: '', // The request header.
resHeaders: '', // The response header.
}),
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
};
},
});
filters parameters
The filters parameters exclude resource and exception events that do not need to be reported.
Parameter | Type | Description | Required |
resource | MatchOption | MatchOption[] | Excludes events related to static resources and API (such as XMLHttpRequest or fetch) that do not need to be reported. | No |
exception | MatchOption | MatchOption[] | Excludes exception events that do not need to be reported. | No |
MatchOption
type MatchOption = string | RegExp | ((value: string, error?: Error) => boolean);
string: matches any URL that starts with the specified value. For example,
https://api.aliyun.com
can matchhttps://api.aliyun.com/v1/resource
.RegExp: specifies a regular expression and URL.
function: uses a function to determine whether a URL is matched. If true is returned, the URL is matched. When filtering exceptions, a second parameter, which is an Error object, is passed in.
When the input is MatchOption[], the preceding conditions are evaluated in order, and it will be excluded if any condition is met.
Example
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
filters: {
// Exclude exception events
exception: [
'Test error', // Filter error messages starting with 'Test error'.
/^Script error\.?$/, // Specify a regular expression.
(msg, error) => {
return msg.includes('example-error');
},
],
// Exclude resource or API events
resource: [
'https://example.com/', // Filter resources starting with 'https://example.com/'.
/localhost/i,
(url) => {
return url.includes('example-resource');
},
],
},
});
properties parameters
Properties provided by RUM can be configured for all events.
Parameter | Type | Description | Required |
[key: string] | String | number |
| No |
You can use evaluateApi, sendCustom, sendException, and sendResource to add properties to an event. The properties take effect only for the event.
Global properties and event properties are merged when they are stored. Event properties have a higher priority than global properties. If the same key is used when merging, the event properties overwrite the global properties. The number of key-value pairs cannot exceed 20 after merging. If the number exceeds 20, the pairs are sorted based on keys and the excess ones are removed.
Example
Globally configured properties are attached to all reported events.
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
properties: {
prop_string: 'xx',
prop_number: 2,
// If the length of the key or value exceeds the limit, the excess part is truncated.
more_than_50_key_limit_012345678901234567890123456789: 'yy',
more_than_2000_value_limit: new Array(2003).join('1'),
// The following invalid key-value pairs will be removed.
prop_null: null,
prop_undefined: undefined,
prop_bool: true,
},
});
Other parameters
The SDK allows you to configure common properties that are resolved based on IP addresses and UserAgent. Proactively configured parameters have a higher priority than automatically resolved parameters.
Parameter | Type | Description | Required |
device | Object | The device information. | No |
os | Object | The system and container information. | No |
geo | Object | The geolocation information. | No |
isp | Object | The ISP information. | No |
net | Object | The network information. | No |
For more information about configuration items about the preceding parameters, see Common attributes.
Example
armsRum.init({
pid: "your app id",
endpoint: "your endpoint",
geo: {
country: 'your custom country info',
city: 'your custom city info',
},
});
SDK API
The SDK provides APIs for modifying and reporting custom data and dynamically modifying SDK configurations.
getConfig
You can use this function to obtain the SDK configurations.
setConfig
You can use this function to modify the SDK configurations.
// Set a specific key
armsRum.setConfig('env', 'pre');
// Overwrite the following settings
const config = armsRum.getConfig();
armsRum.setConfig({
...config,
version: '1.0.0',
env: 'pre',
});
sendCustom
To report custom data, you must specify the type and name parameters. The following table describes the parameters related to data reporting. You need to define the business semantics.
Parameter | Type | Description | Required |
type | String | The type. | Yes |
name | String | The name. | Yes |
group | String | The group. | No |
value | Number | The value. | No |
properties | Object | The custom properties. | No |
armsRum.sendCustom({
// Required.
type: 'CustomEvnetType1',
name: 'customEventName2',
// Optional.
group: 'customEventGroup3',
value: 111.11,
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});
sendException
To report custom exception data, you must specify the name and message parameters.
Parameter | Type | Description | Required |
name | String | The exception name. | Yes |
message | String | The exception message. | Yes |
file | String | The file where the exception occurred. | No |
stack | String | The stack information about the exception. | No |
line | Number | The line where the exception occurred. | No |
column | Number | The column where the exception occurred. | No |
properties | Object | The custom properties. | No |
armsRum.sendException({
// Required.
name: 'customErrorName',
message: 'custom error message',
// Optional.
file: 'custom exception filename',
stack: 'custom exception error.stack',
line: 1,
column: 2,
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});
sendResource
To report custom resource data, you must specify the name, type, and duration parameters.
Parameter | Type | Description | Required |
name | String | The resource name. | Yes |
type | String | The type of the resource. Examples: css, javascript, xmlhttprequest, fetch, api, image, and font. | Yes |
duration | String | The response time. | Yes |
success | Number | Indicates whether the request was successful. Valid values:
| No |
method | String | The request method. | No |
status_code | Number | string | The status code. | No |
message | String | The message returned. | No |
url | String | The request URL. | No |
trace_id | String | The trace ID. | No |
properties | Object | The custom properties. | No |
armsRum.sendResource({
// Required.
name: 'getListByPage',
message: 'success',
duration: 800,
// Optional.
url: 'https://www.aliyun.com/data/getListByPage',
properties: {
prop_msg: 'custom msg',
prop_num: 1,
},
});