All Products
Search
Document Center

Application Real-Time Monitoring Service:Install the browser monitoring agent by using CDN

Last Updated:Mar 11, 2026

Application Real-Time Monitoring Service (ARMS) browser monitoring captures performance metrics, JavaScript errors, and API call data from real users. Adding a CDN-hosted script snippet to your HTML page is the fastest way to start collecting data. For the npm approach, see Install the browser monitoring agent by using npm.

Prerequisites

Before you begin, make sure that you have:

  • An Alibaba Cloud account with ARMS activated

  • A web application where you can edit the HTML source

  • (Optional) sdk.rum.aliyuncs.com and arms-retcode.aliyuncs.com added to your Content Security Policy (CSP) allowlist, if your application enforces CSP

Step 1: Create an application in the ARMS console

  1. Log on to the ARMS console.

  2. In the left-side navigation pane, choose Browser Monitoring > Browser Monitoring. In the top navigation bar, select a region.

  3. On the Browser Monitoring page, click Create Application Site in the upper-right corner.

  4. In the Frontend, Mobile, and Client Applications section of the Integration Center panel, click Web & H5.

    Dialog Box Create New Site

  5. In the Create an application step of the Integrate Web & H5 panel, enter a name for your application.

Step 2: Configure SDK extensions

In the Configuration items for the SDK extension step of the Integrate Web & H5 panel, select the options that match your monitoring needs. The console generates the agent code snippet based on your selections.

OptionDescription
Disable Automatic API ReportingStops automatic API success rate tracking. You must manually call __bl.api() to report the API success rate.
Enable Automatic SPA ResolutionMonitors the hashchange event and automatically reports page views (PVs). Select this option for single-page applications (SPAs).
Enable FMP CollectionCollects First Meaningful Paint (FMP) timing data.
Enable Page Resource ReportingReports static resources loaded on the page when the onload event fires.
Associated with Application MonitoringLinks API requests with ARMS Application Monitoring for end-to-end tracing.
Enable User Behavior BacktrackingRecords user behavior traces that you can view in JS Error Diagnosis.
Enable Console TrackingTraces user behavior in the console. The behavior can be error, warn, log, or info.
Important

Enabling Enable Console Tracking affects the path of the Console panel.

Step 3: Add the agent to your page

Choose one of the following CDN loading methods. Each has different trade-offs between page load performance and monitoring coverage.

MethodBest forTrade-off
Asynchronous loadingPage load speed is the priorityCannot capture JavaScript errors or resource loading errors that occur before the SDK finishes initializing
Synchronous loadingFull error coverage from page load startBlocks page rendering until the SDK finishes loading

Asynchronous loading (recommended for performance)

The browser loads the SDK asynchronously without blocking page rendering.

Copy the generated snippet from the console and paste it as the first element inside the <body> tag of your HTML page, then restart your application.

Asynchronous loading tab

HTML example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
    <meta name="viewport" content="width=device-width" />
    <title>ARMS</title>
  </head>
  <body>
    <script>
      !(function (c, b, d, a) {
        c[a] || (c[a] = {})
        c[a].config = {
          pid: '<your-pid>',
          appType: 'web',
          imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?',
          sendResource: true,
          enableLinkTrace: true,
          behavior: true,
          useFmp: true,
          enableSPA: true,
        }
        with (b)
          with (body)
            with (insertBefore(createElement('script'), firstChild))
              setAttribute('crossorigin', '', (src = d))
      })(window, document, 'https://sdk.rum.aliyuncs.com/v1/bl.js', '__bl')
    </script>
    <div id="app"></div>
  </body>
</html>

Synchronous loading (recommended for full error coverage)

The browser blocks page rendering until the SDK finishes loading. Use this method to capture every JavaScript error and resource loading error from the start of the page lifecycle.

Copy the generated snippet from the console and paste it as the first element inside the <body> tag of your HTML page, then restart your application.

Synchronous loading tab

npm package

You can also install the browser monitoring agent by using npm.

  1. Run the following command to install the npm package:

       npm install alife-logger --save
  2. Run the following command to initialize the npm package:

       const BrowserLogger = require('alife-logger');
       const __bl = BrowserLogger.singleton({pid:"b590lhguqs@8cc3f63543d****",appType:"web",imgUrl:"https://arms-retcode.aliyuncs.com/r.png?",sendResource:true,behavior:true,enableLinkTrace:true,enableConsole:true});

For details, see Install the browser monitoring agent by using npm.

Set a custom UID

By default, the SDK automatically generates a user ID (UID) to track unique visitors (UVs). This UID is updated every six months.

To associate monitoring data with your own user identifiers, such as login IDs, add the uid property to the config object:

uid: 'xxx' // Replace with your user identifier, such as a login ID

Example with custom UID in the asynchronous loading snippet:

<script>
  !(function (c, b, d, a) {
    c[a] || (c[a] = {})
    c[a].config = {
      pid: '<your-pid>',
      appType: undefined,
      imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?',
      uid: '<your-uid>',
    }
    with (b)
      with (body)
        with (insertBefore(createElement('script'), firstChild))
          setAttribute('crossorigin', '', (src = d))
  })(window, document, 'https://sdk.rum.aliyuncs.com/v1/bl.js', '__bl')
</script>
Important

If you change options in the SDK Extension Configuration section of the console, the generated code updates. Copy and paste the new snippet to your page.

Common SDK parameters

The following table lists frequently used parameters. Set these in the config object of the initialization snippet.

ParameterTypeRequiredDefaultDescription
pidStringYesNoneUnique project ID, auto-generated when you create the application site in ARMS.
uidStringNoAuto-generatedUser identifier for tracking unique visitors. If not set, the SDK generates one and rotates it every six months.
tagStringNoNoneCustom tag attached to every log entry.
releaseStringNoundefinedApplication version string. Set this to compare monitoring data across releases.
environmentStringNoprodDeployment environment. Valid values: prod (production), gray (phased-release), pre (staging), daily (daily build), local (local development).
sampleIntegerNo1Sampling ratio for performance logs and successful API logs, from 1 to 100. Logs are sampled at a 1/sample ratio. For details, see Statistical metrics.
behaviorBooleanNotrueRecords user behavior leading up to errors, useful for troubleshooting.
enableSPABooleanNofalseListens for hashchange events and reports a new PV on each route change. Enable for SPAs.
enableLinkTraceBooleanNofalseEnables front-to-back tracing, linking browser requests to server-side traces. For details, see Use the front-to-back tracing feature to diagnose API errors.

For the full parameter list, see SDK reference.