Application Real-Time Monitoring Service (ARMS) provides a series of configuration items for the browser monitoring SDK, meeting your additional requirements, for example, ignoring the reported errors related to the specified URLs, APIs, and JavaScript (JS) scripts, filtering non-key characters in URLs for page clustering, and reducing the number of reported items and load by random sampling.

Use configuration items of the browser monitoring SDK

You can use the configuration items of the browser monitoring SDK in either of the following ways:

  • When installing an ARMS browser monitoring agent in a page, add extra parameters to config.

    For example, in the following sample code, in addition to the default pid parameter, the enableSPA parameter for single page application (SPA) is added to config.

    <script>
    !( function(c,b,d,a){c[a]||(c[a]={});c[a].config={pid:"xxxxxx",enableSPA: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>
    					
  • After page initialization is complete, call the SetConfig method in JS code to modify the configuration item. For the modification method, see Methods user guide.

SDK configuration parameters

Parameter Type Description Required Default value
pid String The unique ID of the project, which is automatically generated when ARMS creates the site. Yes None
tag String The input tag. Each log carries a tag. No None
page String The page name. No The key part of the current page's URL is used by default: host + pathname.
enableSPA Boolean Specifies whether to monitor the hashchange event on the page and report page view (PV) again. It is applicable to SPA scenarios. No false
parseHash Function This parameter is used together with enableSPA. For more information, see parseHash: resolves URL hash into a page. No For more information, see parseHash: resolves URL hash into a page.
disableHook Boolean Specifies whether to disable the monitoring of AJAX requests. No false: Requests are listened to and used for reporting API call success rate.
ignoreUrlCase Boolean Specifies whether the page URL is case insensitive. No true: Case insensitive by default.
urlHelper * A replacement of the old parameter ignoreUrlPath to configure URL filtering rules. For more information, see UrlHelper: performs URL filtering. No For more information, see UrlHelper: performs URL filtering.
apiHelper * A replacement of the old parameter ignoreApiPath to configure API filtering rules. For more information, see apiHelper: performs API filtering. No For more information, seeapiHelper: performs API filtering.
parseResponse Function Parses the data returned when the API data is automatically reported. For more information, see config.parseResponse: parses responses. No For more information, see config.parseResponse: parses responses.
ignore Object Ignores the errors of the specified URL, API, or JS error. Logs that match the rules are ignored and not reported, including sub-items ignoreUrls, ignoreApis, and ignoreErrors. For more information, see ignore: ignores specified URL, API, and JS errors. No For more information, see ignore: ignores specified URL, API, and JS errors.
disabled Boolean Specifies whether to disable the log reporting function. No false
sample Integer The log sampling rate. Valid values: 1, 10, and 100. Performance logs and successful API request logs are sampled in the ratio of 1/sample. For more information, see config.sample: configures sample reporting of logs. No 1
sendResource Boolean Specifies whether to report static resources on the page. For more information, see sendResource: reports static resources. No false
useFmp Boolean Specifies whether to collect the First Meaningful Paint (FMP) data. No false
enableLinkTrace Boolean Specifies whether to enable front-to-back tracing. For more information, see Front-to-back tracing. No false
release String The version of the application. No undefined
environment String The environment for front-to-back tracing analysis. No production
behavior Boolean Performs user behavior backtracking when an error occurs. No true for the browser and false for the applet by default.
c1 String Custom service field. Each log carries the field. No None
c2 String Custom service field. Each log carries the field. No None
c3 String Custom service field. Each log carries the field. No None

parseHash: resolves URL hash into a page

In the SPA scenario (see Advanced browser monitoring scenarios), when enableSPA is set to true and the page triggers a hashchange event, the parseHash parameter is used to resolve the URL hash into Page.

Default value

The default value is obtained by a simple string processing method:

function (hash) {
    var page = hash ? hash.replace(/^#/, '').replace(/\?.*$/, '') : '';
    return page || '[index]';
}
			

Normally this item does not need to be modified. You need to modify this item if a custom page name is required during reporting or if the URL hash is complex. The following shows an example.

// Define the mapping between Hash and Page.
var PAGE_MAP = {
    '/': 'Homepage',
    '/contact': 'Contact us',
    '/list': 'Data list',
    // ...
};
// Call the SDK method after the page is loaded.
window.addEventListener('load', function (e) {
    // Call the setConfig method to modify SDK configuration items.
    __bl.setConfig({
        parseHash: function (hash) {
            key = hash.replace(/\?.*$/, '');
            return PAGE_MAP[key] || 'Unknown page';
        }
    });
});

UrlHelper: performs URL filtering

When a page URL is similar to http://xxx.com/projects/123456 (projects is followed by the project ID) and xxx.com/projects/123456 is reported as a page, the page cannot be clustered during data browsing. To implement page clustering, set the urlHelper parameter to filter non-key characters, for example, the project ID in this example.

Notice The old parameter ignoreUrlPath that configures URL filtering has been replaced by the urlHelper parameter. If you use the old parameter, the configuration will still take effect. If both the old and new parameters are used, the new parameter takes effect.
Note This configuration item is valid only when the page URL is automatically obtained and used as Page. This configuration item will be invalid if you have modified Page by manually calling the setPage or setConfig method (see Methods user guide) or enableSPA has been set to true.

Default value

The array is the default value, which does not need to be modified.

[
    // Replace all numbers in the URL with asterisks (*).
    {rule: /\/([a-z\-_]+)? \d{2,20}/g, target: '/$1**'},
    // Remove the trailing slash (/) of the URL.
    /\/$/
]                    

The default value of this configuration item filters out the numbers in strings such as xxxx/123456. For example, xxxx/00001 and xxxx/00002 change to xxxx/**.

Value type

The value of urlHelper can be any of the following types:

  • String or RegExp (regular expression): removes matched strings.
  • Object<rule, target>: The object contains two keys (rule and target, which are the input parameters of the replace method of the JS string. For more information, see JS related tutorials String::replace method.
  • Function: uses the original string as the input parameter for method execution, and the execution result as Page.
  • Array: sets multiple rules. Each rule can be of the preceding types.

apiHelper: performs API filtering

This configuration item filters out non-key characters in API URLs when API results are automatically reported. The usage and function are the same as those of UrlHelper: performs URL filtering.

Notice The old parameter ignoreApiPath that configures API filtering rules has been replaced by the apiHelper parameter. If you use the old parameter, the configuration will still take effect. If both the old and new parameters are used, the new parameter takes effect.

Default value

The default value is an object, which does not need to be modified.

{rule: /(\w+)\/\d{2,}/g, target: '$1'}                    

The default value of this configuration item filters out the numbers in strings such as xxxx/123456 in the API URL.

config.parseResponse: parses responses

This configuration item parses the data returned when the API results are automatically reported.

Default value

The default value of this configuration item is:

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};
}                    

The preceding code parses the returned data and tries to extract msg and code. For most applications, this configuration item does not need to be modified. If the default value cannot meet service requirements, you can reset it.

ignore: ignores specified URL, API, and JS errors

The value of ignore is an object, which contains three attributes: ignoreUrls, ignoreApis, and ignoreErrors. You can set one or more attributes.

Default value

The default value of this configuration item is:

ignore: {
        ignoreUrls: [],
        ignoreApis: [],
        ignoreErrors: []
    },                    

ignoreUrls

The ignoreUrls attribute is used to ignore certain URLs. Logs at the URLs that comply with a specified rule are not reported. The value can be String,RegExp,Function, or an array of the preceding three types. Example:

__bl.setConfig({
                ignore: {
                    ignoreUrls: [
                    'http://host1/',  // Character string
                    /. +? host2. +/,     // Regular expression
                    function(str) {   // Method
                        if (str && str.indexOf('host3') >= 0) {
                            return true;
                        }
                        return false;
                    }]
                }
            });                    

ignoreApis

The ignoreApis attribute is used to ignore certain APIs that comply with a specified rule. The value can be String, RegExp, Function, or an array of the preceding three types. Example:

__bl.setConfig({
                ignore: {
                    ignoreApis: [
                    'api1','api2','api3', // Character string
                    /^random/,  // Regular expression
                    function(str) { // Method
                        if (str && str.indexOf('api3') >= 0) return true;
                        return false;
                    }]
                }
            });                    

ignoreErrors

The ignoreErrors attribute is used to ignore certain JS errors that comply with a specified rule. The value can be String, RegExp, Function, or an array of the preceding three types. Example:

__bl.setConfig({
                ignore: {
                    ignoreErrors: [
                    'test error', // Character string
                    /^Script error\.? $/, // Regular expression
                    function(str) { // Method
                        if (str && str.indexOf('Unkown error') >= 0) return true;
                        return false;
                    }]
                }
            });            

config.sample: configures sample reporting of logs

To reduce the number of reported items and load, this configuration item randomly samples and reports performance logs and successful API call logs. When processing logs, the background will restore the data based on the sampling configuration. Therefore, the configuration does not affect the reporting of other types of logs, such as JS error logs and failed API call logs.

The value of sample can be 1, 10, or 100, corresponding to the sampling ratio 1/sample. That is, 1 indicates 100% sampling, 10 indicates 10% sampling, and 100 indicates 1% sampling. The default value is 1.

Notice Sampling is performed randomly. If the number of reported items is small, this configuration item may cause large statistical result errors. This configuration item is recommended for the sites with daily average PVs of more than 1 million.

sendResource: reports static resources

If sendResource is set to true, the static resources loaded to the current page are reported when the page load event is triggered. If page loading is slow, you can view the static resource waterfall chart on the Session Traces page to determine the reason.

Sample code of SendResource

<script>
!( function(c,b,d,a){c[a]||(c[a]={});c[a].config={pid:"xxxxxx",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>            
Note The determination is made when the page load event is triggered. Therefore, configure sendResource in config (as shown in the preceding example). Do not use the setConfig method because this method may trigger the determination after the page load event is complete. In this situation, this configuration item is invalid.

c1 \ c2 \ c3: configuration items with custom fields.

:

In addition to the configuration items listed above, you may need more information when handling business problems. Therefore, the ARMS SDK provides three configuration items that allow you to customize fields. After the configuration, the fields are included in each reported log.

More information