tencent cloud

Feedback

Configuration Guide

Last updated: 2022-02-09 16:16:22

    Configuration Description

    The configuration items in the configuration file are as detailed below:

    Configuration Item Description
    id It is a required string and is empty by default.
    It is the project ID assigned by RUM.
    uin It is a recommended string and is the UIN field in the cookie by default.
    It is the unique ID of the current user. When a log is reported, it will be used to check whether the user is in the allowlist. Its value can contain only letters, digits, and @=._-, and its regular expression is /^[@=.0-9a-zA-Z_-]{1,60}$/.
    reportApiSpeed It is an optional boolean value or object and is false by default.
    It specifies whether to enable API speed test.
    reportAssetSpeed It is an optional boolean value and is false by default.
    It specifies whether to enable static resource speed test.
    pagePerformance It is an optional boolean value or object and is true by default.
    It specifies whether to enable page speed test.
    webVitals It is an optional boolean value and is true by default.
    It specifies whether to enable Web Vitals speed test.
    onError It is an optional boolean value and is true by default.
    It specifies whether to enable error listening in the current instance to get error logs.
    aid It is an optional boolean value and is true by default.
    It specifies whether to generate aid in the current instance.
    random It is an optional number and is 1 by default.
    It is the sample rate. Value range: 0–1.
    spa It is an optional boolean value and is false by default.
    It specifies whether the current page is an SPA page. If the value is true, hashchange and the history API will be listened on to report the PV during page redirect.
    version It is an optional string and is the SDK version number by default.
    It is the version of the currently reported content. If the page uses PWA or an offline package, it can be used to judge the version of the code where the currently reported content is from. Its value can contain up to 60 letters, digits, and =._-, and its regular expression is /^[0-9a-zA-Z.,:_-]{1,60}$/.
    delay It is an optional number and is 1000 ms by default.
    It is the time period for reducing reporting traffic, within which multiple reports will be merged into one reporting request.
    repeat It is an optional number and is 5 by default.
    It is the number of repeated reports. After it is exceeded, the same error will not be reported again.
    env It is an optional enum and is Aegis.environment.production by default.
    It is the current environment where the project runs.
    offlineLog It is an optional boolean value and is false by default.
    It specifies whether to use offline log.
    offlineLogExp It is an optional number and is 3 by default.
    It is the offline log validity period.
    api It is an optional object and is {} by default. Fields:
  • apiDetail: it specifies whether to report the API request parameters and returned value if an API fails. It is an optional boolean value and is false by default.
  • retCodeHandler: Function(data: String, url: String, xhr: Object):{isErr: boolean, code: string}: it is the hook function for return code reporting and will pass in the API response data, request url, and xhr object. resourceTypeHandler: Function: it is the request resource type correction hook function and will pass in the API url. Its returned value is static or fetch. For more information, see api.retCodeHandler.
  • reportRequest: it is a boolean value and is false by default. After it is enabled, aegis.info will report the full data with no need to configure the allowlist, and information of all APIs will be reported (you need to enable reportApiSpeed in the reporting API).
  • speedSample It is an optional boolean value and is true by default.
    It specifies whether to sample the speed test logs (that is, each URL reports only one speed test log).
    hostUrl It is optional and is //aegis.qq.com by default.
    It is the host address that affects all reported data. After the following URL addresses are set, they will overwrite the original reporting addresses.
    url It is an optional string and is //aegis.qq.com/collect by default.
    It is the log reporting address.
    You can set it to an empty string to disable log reporting.
    pvUrl It is an optional string and is //aegis.qq.com/collect/pv by default.
    It is the PV reporting address.
    You can set it to an empty string to disable PV reporting.
    whiteListUrl It is an optional string and is //aegis.qq.com/collect/whitelist by default.
    It is the allowlist confirming API.
    You can set it to an empty string to disable allowlist API request.
    offlineUrl It is an optional string and is //aegis.qq.com/collect/offline by default.
    It is the offline log reporting address.
    You can set it to an empty string to disable offline log reporting.
    eventUrl It is an optional string and is //aegis.qq.com/collect/events by default.
    It is the custom event reporting address.
    You can set it to an empty string to disable custom event reporting.
    speedUrl It is an optional string and is //aegis.qq.com/speed by default.
    It is the speed test log reporting address.
    You can set it to an empty string to disable speed test data reporting.
    customTimeUrl It is an optional string and is //aegis.qq.com/speed/custom by default.
    It is the custom speed test reporting address.
    You can set it to an empty string to disable custom speed test reporting.
    performanceUrl It is an optional string and is //aegis.qq.com/speed/performance by default.
    It is the page performance reporting address.
    You can set it to an empty string to disable page performance reporting.
    webVitalsUrl It is an optional string and is //aegis.qq.com/speed/webvitals by default.
    It is the Web Vitals reporting address.
    You can set it to an empty string to disable Web Vitals reporting.
    dbConfig It is an optional object.
    ext1 It is the additional dimension in custom reporting, which can be overwritten during reporting. It is an optional string.
    ext2 It is the additional dimension in custom reporting, which can be overwritten during reporting. It is an optional string.
    ext3 It is the additional dimension in custom reporting, which can be overwritten during reporting. It is an optional string.

    Sample Code

    api.retCodeHandler

    If the backend returns the following data:

    {
       body: {
           code: 200,
           retCode: 0,
           data: {
               // xxx
           }
       }
    }
    

    If your business requires that if the code is not 200 or retCode is not 0, the request is incorrect. To meet this requirement, you can simply configure as follows:

    new Aegis({
       // xxx
       reportApiSpeed: true, // You need to enable two speed test APIs; otherwise, no return code will be reported
       reportAssetSpeed: true,
       api: {
           retCodeHandler(data, url, xhr) { 
               // `data` is a string. If you want to get an object, you need to manually parse it
               // `url` is the request URL
               // The complete backend `xhr` response can be obtained through `xhr.response`
               try {
                   data = JSON.parse(data)
               } catch(e) {}
               return {
                   isErr: data.body.code !== 200 || data.body.retCode !== 0,
                   code:  data.body.code
               }
           }
       }
    })
    

    api.resourceTypeHandler

    If the API is http://example.com/test-api and the returned Content-Type is text/html, Aegis will consider that the content returned by the API is a static resource. In this case, you can correct the judgment as follows:

    new Aegis({
       reportApiSpeed: true, // You need to enable two speed test APIs; otherwise, no return code will be reported
       reportAssetSpeed: true,
       api: {
           resourceTypeHandler(url) {
               if (url?.indexOf('http://example.com/test-api') != -1) {
                   return 'fetch';
               }
           }
       }
    })
    

    reportApiSpeed.urlHandler

    If your page has RESTful APIs such as:
    www.example.com/user/1000
    www.example.com/user/1001

    You need to aggregate the following APIs when reporting the speed test data:

    new Aegis({
       // xxx
       reportApiSpeed: {
           urlHandler(url, payload) {
               if ((/www\.example\.com\/user\/\d*/).test(url)) {
                   return 'www.example.com/user/:id';
               }
               return url;
           }
       }
       // xxx
    })
    

    pagePerformance.urlHandler

    If your page has RESTful APIs such as:
    www.example.com/user/1000
    www.example.com/user/1001

    You need to aggregate the page addresses when reporting the page speed test data:

    new Aegis({
       // xxx
       pagePerformance: {
           urlHandler() {
               if ((/www\.example\.com\/user\/\d*/).test(window.location.href)) {
                   return 'www.example.com/user/:id';
               }
           }
       }
       // xxx
    })
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support