edit-icon download-icon

SDK configuration items

Last Updated: Jul 13, 2018

This topics describes initial configuration items of the ARMS browser monitoring SDK, and explains how to use different parameters for different application scenarios.

Usage

When embedding a BI probe in a page, you can add extra parameters to config. Alternatively, call the setConfig method on the browser JS code after page initialization is complete. For more information, see API user guide.

Example

  1. <script>
  2. !(function(c,b,d,a){c[a]||(c[a]={});c[a].config={pid:"xxxxxx",enableSPA:true};
  3. with(b)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("crossorigin","",src=d)
  4. })(window,document,"https://retcode.alicdn.com/retcode/bl.js","__bl");
  5. </script>

In this example, in addition to the default pid parameter, the enableSPA parameter is added to config and is used in single page application (SPA) scenario.

Configuration items

Parameter Type Description Required Default value
pid String The unique ID of a project, automatically generated when ARMS creates the site Yes None
page String The page name, extracted from the key part of the URL of the current page No host + pathname
enableSPA Boolean If to listen for the hashchange event on the page and report PV again, applicable to SPA scenarios No false
parseHash Function Used together with enableSPA. For more information, see the following description. No See the following description
disableHook Boolean If to disable AJAX request listening, which is listened for by default and used for reporting the API call success rate No false
ignoreUrlCase Boolean If to ignore the capitalization of Page URL, which is true by default No true
ignoreUrlPath * The URL filtering rule. For more information, see the following description No See the following description
ingoreApiPath * The API filtering rule. For more information, see the following description. No See the following description
disabled Boolean If to disable the log reporting function No false

Detailed description of some configuration items

parseHash is a method for resolving URL hash to page

In the SPA scenario (see Introduction to advanced scenarios), this parameter is used in the method that resolves URL hash to the “page” field after enableSPA is set to true and a hashchange event is triggered on the page.

The default value is a simple string processing method:

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

Normally this item does not need to be modified. You must modify this item if a custom page name is required during reporting or if URL hash is complex.

Example:

  1. // Define the mapping relationship between hash and page on the page.
  2. var PAGE_MAP = {
  3. '/': 'Homepage',
  4. '/contact': 'Contact us',
  5. '/list': 'Data list',
  6. // ...
  7. };
  8. // Call the SDK method after page onload.
  9. window.addEventListener('load', function (e) {
  10. // Call the setConfig method to modify SDK configuration items.
  11. __bl.setConfig({
  12. parseHash: function (hash) {
  13. key = hash.replace(/\?.*$/, '');
  14. return PAGE_MAP[key] || 'Unknown page';
  15. }
  16. });
  17. });

ignoreUrlPath - URL filtering rule

In a scenario where the page URL is similar to http://xxx.com/projects/123456 (“projects” is followed by the project ID), if xxx.com/projects/123456 is reported as a page, the page cannot be aggregated to one group when viewing the data. Therefore, such non-key characters must be filtered out.

Application scenario

This configuration item works only when the page URL is automatically obtained and used as “page”. This configuration item doesn’t work if you have modified page by manually calling the setPage or setConfig method (see the API user guide) or set enableSPA to true.

The default value is an array, which doesn’t need to be modified in most cases.

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

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

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

  • String or RegExp: Removes matching strings. For more information about RegExp, see the regular expression syntax.
  • Object<rule, target>: The object contains two keys: rule and target. For more information about input parameters of the replace method of JS strings, see the String::replace method in related JS tutorials.
  • Function: The original string is used as the input parameter for method execution, and the execution result is used as “page”.
  • Array: Sets multiple rules, each of which can be of one of the preceding types.

config.ignoreApiPath - API filtering rule

This configuration item filters out non-key characters in API URLs when APIs are automatically reported. The usage and function are the same as ignoreUrlPath.

The default value is an object, which doesn’t need to be modified in most cases.

  1. {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 interface URL.

Thank you! We've received your feedback.