The ARMS Browser Monitoring SDK provides configuration items that control data collection and reporting. Use these items to filter URLs, APIs, and JavaScript errors, aggregate pages by normalizing URLs, and reduce data volume through sampling.
How to set configuration items
Two methods are available:
At initialization -- Add parameters to
configwhen installing the Browser Monitoring agent on a page.After initialization -- Call
__bl.setConfig(next)to update configuration at runtime.
Initialization example
This snippet installs the agent with the required pid plus three optional parameters -- enableSPA, sendResource, and release:
<script>
!(function(c,b,d,a){c[a]||(c[a]={});c[a].config={
pid: "<your-pid>",
enableSPA: true,
sendResource: true,
release: "1.0.0"
};
with(b)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("crossorigin","",src=d)
})(window,document,"https://retcode.alicdn.com/retcode/bl.js","__bl");
</script>Runtime updates with setConfig
Call __bl.setConfig(next) to modify configuration after page load.
| Parameter | Type | Required | Description |
|---|---|---|---|
| next | Object | Yes | Key-value pairs of configuration items to update |
__bl.setConfig({
uid: "user-12345",
tag: "checkout-flow"
});The following parameters only take effect at initialization and cannot be changed through setConfig: disableHook and release.
Configuration reference
The following table lists all configuration items grouped by function. Each item is described in detail in the sections that follow.
Identity
| Parameter | Type | Default | Description |
|---|---|---|---|
| pid | String | None | Project ID (required) |
| uid | String | Auto-generated | User identifier |
| setUsername | Function | None | Callback that returns a username for session tracing |
Page and URL
| Parameter | Type | Default | Description | ||||
|---|---|---|---|---|---|---|---|
| page | String | host + pathname | Custom page name | ||||
| tag | String | None | Custom tag attached to every log entry | ||||
| ignoreUrlCase | Boolean | true | Case-insensitive page URL matching | ||||
| urlHelper | String \ | RegExp \ | Object \ | Function \ | Array | See below | Normalize page URLs for aggregation |
| apiHelper | String \ | RegExp \ | Object \ | Function \ | Array | See below | Normalize API URLs for aggregation |
SPA support
| Parameter | Type | Default | Description |
|---|---|---|---|
| enableSPA | Boolean | false | Report PV on each route change |
| parseHash | Function | See below | Convert URL hash to page name |
Data filtering
| Parameter | Type | Default | Description |
|---|---|---|---|
| ignore | Object | See below | Suppress log reporting for matching URLs, APIs, or errors |
| parseResponse | Function | See below | Extract msg and code from API responses |
Sampling
| Parameter | Type | Default | Description |
|---|---|---|---|
| sample | Integer (1--100) | 1 | Sampling rate for performance and successful API logs |
| pvSample | Integer (1--100) | 1 | Sampling rate for PV logs |
Performance and resource tracking
| Parameter | Type | Default | Description |
|---|---|---|---|
| sendResource | Boolean | false | Report static resources loaded on the page |
| useFmp | Boolean | false | Collect First Meaningful Paint (FMP) data |
| autoSendPerf | Boolean | true | Send performance logs automatically |
| disableHook | Boolean | false | Disable AJAX request listeners |
Tracing and diagnostics
| Parameter | Type | Default | Description |
|---|---|---|---|
| enableLinkTrace | Boolean | false | Enable front-to-back tracing |
| behavior | Boolean | Browser: true; Mini program: false | Record user actions before errors |
Application metadata
| Parameter | Type | Default | Description |
|---|---|---|---|
| release | String | undefined | Application version string |
| environment | String | prod | Deployment environment label |
| disabled | Boolean | false | Disable all log reporting |
Custom fields
| Parameter | Type | Default | Description |
|---|---|---|---|
| c1, c2, c3 | String | None | Custom fields attached to every log entry |
Identity
pid
| Property | Value |
|---|---|
| Type | String |
| Required | Yes |
| Default | None |
Unique project ID, generated automatically when ARMS creates a site.
uid
| Property | Value |
|---|---|
| Type | String |
| Required | Yes (Weex); No (other scenarios) |
| Default | Weex: None; Others: auto-generated by the SDK, refreshed every six months |
User identifier for searching and tracking individual users. Specify a custom value, or let the SDK generate one automatically.
__bl.setConfig({
uid: "user-12345"
});In mini program monitoring, setConfig cannot modify uid. Use setUsername instead.
setUsername
| Property | Value |
|---|---|
| Type | Function |
| Required | No |
| Default | None |
A callback that returns a username string. Once set, enables end-to-end session tracing and session lookup by username for troubleshooting.
__bl.setConfig({
setUsername: function () {
return "username_xxx";
}
});Behavior:
If the username is unavailable at page load, return
null-- not a placeholder. The SDK callssetUsernameagain when sending logs. Returning a placeholder means that value is used andsetUsernameis not called again.setUsernameaccepts only one assignment per runtime. Restart the application to reassign it.
Page and URL configuration
page
| Property | Value |
|---|---|
| Type | String |
| Required | No |
| Default | host + pathname of the current URL |
Overrides the automatically detected page name with a custom value.
You can use the ignoreErrors property to filter errors you want to report. For more information, see ignore.
tag
| Property | Value |
|---|---|
| Type | String |
| Required | No |
| Default | None |
A custom tag attached to every log entry. Use tags to categorize or filter logs in the ARMS console.
ignoreUrlCase
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | true |
When set to true, page URL matching is case-insensitive.
urlHelper
| Property | Value | ||||
|---|---|---|---|---|---|
| Type | String \ | RegExp \ | Object\ | Function \ | Array |
| Required | No | ||||
| Default | See below |
Normalizes page URLs by removing dynamic segments so that similar pages aggregate under one entry. Replaces the deprecated ignoreUrlPath parameter.
Why normalize URLs: A URL like example.com/projects/123456 generates a unique page name per project ID. urlHelper strips dynamic segments so all project pages aggregate as example.com/projects/**.
Default value:
[
// Replace digit sequences (2-20 chars) with **
{rule: /\/([a-z\-_]+)?\d{2,20}/g, target: '/$1**'},
// Remove trailing slash
/\/$/
]Supported value types:
| Type | Behavior |
|---|---|
| String or RegExp | Matched substrings are removed |
Object {rule, target} | Works like String.replace(rule, target) |
| Function | Receives the original URL, returns the page name |
| Array | Applies multiple rules in sequence; each element can be any of the above types |
If both
ignoreUrlPathandurlHelperare set,urlHelpertakes precedence.urlHelperonly applies when the page URL is auto-detected. It has no effect whensetPage,setConfig, orenableSPA: trueoverrides the page name. For more information, see SDK methods.
apiHelper
| Property | Value | ||||
|---|---|---|---|---|---|
| Type | String \ | RegExp \ | Object\ | Function \ | Array |
| Required | No | ||||
| Default | {rule: /(\w+)\/\d{2,}/g, target: '$1'} |
Normalizes API URLs by removing dynamic segments, the same way urlHelper normalizes page URLs. Replaces the deprecated ignoreApiPath parameter.
If both ignoreApiPath and apiHelper are set, apiHelper takes precedence.
Reporting query parameters in API data: To include query parameters (for example, pid in https://arms.console.aliyun.com/apm?pid=fr6fbgbeot), disable automatic reporting with the ignore parameter and call api() manually. For details, see api().
SPA support
enableSPA
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No (Web only) |
| Default | false |
Listens for hashchange events and reports a new page view (PV) on each route change. Enable this for single-page applications (SPAs).
parseHash
| Property | Value |
|---|---|
| Type | Function |
| Required | No |
| Default | See below |
Used with enableSPA. When enableSPA is true and a hashchange event fires, parseHash converts the URL hash into a page name for the Page field. For details, see Page data reporting of SPAs.
Default value:
function (hash) {
var page = hash ? hash.replace(/^#/, '').replace(/\?.*$/, '') : '';
return page || '[index]';
}Typically, the default is sufficient. To map hashes to custom page names, override this function:
var PAGE_MAP = {
'/': 'Homepage',
'/contact': 'Contact us',
'/list': 'Data list'
};
window.addEventListener('load', function (e) {
__bl.setConfig({
parseHash: function (hash) {
var key = hash.replace(/\?.*$/, '');
return PAGE_MAP[key] || 'Unknown page';
}
});
});Data filtering
ignore
| Property | Value |
|---|---|
| Type | Object |
| Required | No |
| Default | {ignoreUrls: [], ignoreApis: [], ignoreErrors: [], ignoreResErrors: []} |
Suppresses log reporting for URLs, APIs, JavaScript errors, or resource errors that match specified rules. Contains four sub-properties.
Each sub-property accepts a String, RegExp, Function, or an Array of these types.
ignoreUrls
Suppresses logs from matching page URLs.
__bl.setConfig({
ignore: {
ignoreUrls: [
'http://host1/', // Exact string match
/.+?host2.+/, // Regex match
function(str) { // Custom function
if (str && str.indexOf('host3') >= 0) {
return true; // Suppress
}
return false; // Report
}
]
}
});ignoreApis
Suppresses logs from matching API URLs.
__bl.setConfig({
ignore: {
ignoreApis: [
'api1', 'api2', 'api3', // String matches
/^random/, // Regex match
function(str) { // Custom function
if (str && str.indexOf('api3') >= 0) return true;
return false;
}
]
}
});ignoreErrors
Suppresses matching JavaScript error messages.
__bl.setConfig({
ignore: {
ignoreErrors: [
'test error', // String match
/^Script error\.?$/, // Regex match
function(str) { // Custom function
if (str && str.indexOf('Unknown error') >= 0) return true;
return false;
}
]
}
});ignoreResErrors
Suppresses matching resource loading errors.
__bl.setConfig({
ignore: {
ignoreResErrors: [
'http://xx/picture.jpg', // String match
/jpg$/, // Regex match
function(str) { // Custom function
if (str && str.indexOf('xx.jpg') >= 0) return true;
return false;
}
]
}
});parseResponse
| Property | Value |
|---|---|
| Type | Function |
| Required | No |
| Default | See below |
Parses API response data during automatic reporting. Extracts msg and code from the response object.
Default value:
function (res) {
if (!res || typeof res !== 'object') return {};
var code = res.code;
var msg = res.msg || res.message || res.subMsg || res.errorMsg || res.ret || res.errorResponse || '';
if (typeof msg === 'object') {
code = code || msg.code;
msg = msg.msg || msg.message || msg.info || msg.ret || JSON.stringify(msg);
}
return {msg: msg, code: code, success: true};
}Override this function if your API responses use a different structure.
Sampling
sample
| Property | Value |
|---|---|
| Type | Integer |
| Required | No |
| Default | 1 |
| Range | 1--100 |
Controls the sampling rate for performance logs and successful API logs. Sampling rate = 1 / sample:
| Value | Sampling rate |
|---|---|
1 | 100% (all data) |
10 | 10% |
100 | 1% |
Sampling reduces data volume and collection overhead. To reduce costs, you can also use the ignore parameter to stop reporting data that does not require monitoring. For more information, see ignore.
ARMS compensates for sampling during processing, so aggregate metrics like JS error rate and API failure rate remain accurate. However, individual log details may be lost.
For more information about the affected metrics, see Statistical metrics.
Random sampling on low-traffic sites introduces significant statistical deviation. Use this parameter only for sites with over 1 million daily page views.
pvSample
| Property | Value |
|---|---|
| Type | Integer |
| Required | No |
| Default | 1 |
| Range | 1--100 |
Controls the sampling rate for page view (PV) logs. Same formula as sample: sampling rate = 1 / pvSample.
ARMS compensates for sampling during processing, so aggregate metrics such as JS error rate remain accurate.
Performance and resource tracking
sendResource
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | false |
When set to true, reports all static resources loaded on the page at the load event. Use the Session Traces waterfall chart to identify resources causing slow page loads.
<script>
!(function(c,b,d,a){c[a]||(c[a]={});c[a].config={pid:"<your-pid>",sendResource:true};
with(b)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("crossorigin","",src=d)
})(window,document,"https://retcode.alicdn.com/retcode/bl.js","__bl");
</script>Set sendResource in config at initialization, not through setConfig. Calling setConfig may execute after the load event completes, at which point static resource data is no longer available.
useFmp
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | false |
Enables First Meaningful Paint (FMP) data collection for first-screen rendering analysis.
autoSendPerf
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | true |
Controls whether performance logs are sent automatically.
disableHook
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | false |
Disables AJAX request listeners. By default, the SDK intercepts AJAX calls to report API success rates.
This parameter only takes effect at initialization.
Tracing and diagnostics
enableLinkTrace
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No (Web, Alipay mini programs, WeChat mini programs, and DingTalk mini programs only) |
| Default | false |
Enables front-to-back tracing, correlating browser requests with server-side traces. For details, see Use the front-to-back tracing feature to diagnose API errors.
behavior
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No (Web and mini programs only) |
| Default | Browser: true; Mini program: false |
Records the sequence of user actions leading up to errors, aiding troubleshooting.
Application metadata
release
| Property | Value |
|---|---|
| Type | String |
| Required | No |
| Default | undefined |
Application version string. Set this to compare monitoring data across different releases.
Set release in config at initialization. Do not use setConfig.
environment
| Property | Value |
|---|---|
| Type | String |
| Required | No |
| Default | prod |
Deployment environment label. Valid values:
| Value | Environment |
|---|---|
prod | Production |
gray | Phased release |
pre | Staging |
daily | Daily / Development |
local | Local |
disabled
| Property | Value |
|---|---|
| Type | Boolean |
| Required | No |
| Default | false |
When set to true, disables all log reporting.
Custom fields
c1, c2, c3
| Property | Value |
|---|---|
| Type | String |
| Required | No |
| Default | None |
Three custom fields attached to every log entry. Carry business-specific data such as VIP level of a user, A/B test group, or feature flags.
__bl.setConfig({
c1: "premium",
c2: "experiment-group-B",
c3: "feature-darkmode"
});Values set for c1, c2, and c3 are included in all logs reported from the current page.