All Products
Search
Document Center

Application Real-Time Monitoring Service:Set up browser monitoring for Weex

Last Updated:Mar 11, 2026

Application Real-Time Monitoring Service (ARMS) browser monitoring collects page view (PV), API call, and error data from your Weex app through the @arms/js-sdk package.

Prerequisites

Before you begin, make sure that you have:

  • An ARMS browser monitoring site with a valid site ID (pid)

  • Node.js and npm in your development environment

  • A Weex project that uses the stream module

Step 1: Install the SDK

Run the following command in your Weex project root:

npm install @arms/js-sdk --save

Step 2: Initialize the SDK

Create a monitor.js file in the /utils directory. This file serves as a centralized monitoring module that the rest of your application imports.

The initialization code has two parts:

  • Weex transport layer -- Boilerplate that enables HTTP reporting in Weex. ARMS requires custom sendRequest and postRequest functions that use the Weex stream module.

  • SDK configuration -- Your project-specific settings such as site ID and reporting endpoint.

// /utils/monitor.js
import WeexLogger from '@arms/js-sdk/weex';

// --- Weex transport layer (copy as-is) ---
const fetch = weex.requireModule('stream').fetch;
const serialize = (data) => {
    data = data || {};
    var arr = [];
    for (var k in data) {
        if (Object.prototype.hasOwnProperty.call(data, k) && data[k] !== undefined) {
            arr.push(k + '=' + encodeURIComponent(data[k]).replace(/\(/g, '%28').replace(/\)/g, '%29'));
        }
    }
    return arr.join('&');
};

// --- SDK configuration (replace placeholders with your values) ---
const wxLogger = WeexLogger.singleton({
    pid: '<YOUR_SITE_ID>',
    uid: '<YOUR_USER_ID>',           // User identifier for UV reports
    page: '<YOUR_INITIAL_PAGE>',     // Initial page name; triggers a PV report on init
    imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?',
    // For the Singapore region, use:
    // imgUrl: 'https://arms-retcode-sg.aliyuncs.com/r.png?',

    // GET transport
    sendRequest: (data, imgUrl) => {
        const url = imgUrl + serialize(data);
        fetch({
            method: 'GET',
            url
        });
    },
    // POST transport
    postRequest: (data, imgUrl) => {
        fetch({
            method: 'POST',
            type: 'json',
            url: imgUrl,
            body: JSON.stringify(data)
        });
    }
});

export default wxLogger;

Replace the following placeholders with your values:

PlaceholderDescriptionExample
<YOUR_SITE_ID>Site ID assigned by ARMS when you created the sitexxxxxxxx
<YOUR_USER_ID>User identifier for UV trackinguser_12345
<YOUR_INITIAL_PAGE>Name of the first page to report on initializationHome
Note

WeexLogger.singleton(props) returns a singleton instance. The props argument only takes effect on the first call. All subsequent calls return the same instance regardless of the arguments passed.

Step 3: Report logs

Import the wxLogger instance from any module to report monitoring data:

import wxLogger from '/utils/monitor';

// Report an API call
wxLogger.api('/search.do', true, 233, 'SUCCESS');

For the full list of log reporting methods, see SDK methods.

API reference

singleton(props)

A static method that returns a singleton WeexLogger instance. Use this at the application entry point to initialize the SDK. The props parameter only takes effect on the first call.

ParameterTypeRequiredDefaultDescription
pidStringYesNoneSite ID assigned by ARMS
pageStringNoNoneInitial page name. Triggers a PV report after initialization
uidStringYesNoneUser ID for UV tracking
imgUrlStringNoNoneReporting endpoint URL. Must end with ?

setPage(nextPage)

Sets the current page name and reports a PV log.

import wxLogger from '/utils/monitor';

wxLogger.setPage(nextPage);
ParameterTypeRequiredDefaultDescription
nextPageStringYesNoneName of the new page

setConfig(config)

Updates SDK configuration after initialization. Accepts the same parameters as singleton(). For the full parameter list, see setConfig().

import wxLogger from '/utils/monitor';

wxLogger.setConfig(config);
ParameterTypeRequiredDefaultDescription
configObjectYesNoneConfiguration properties to update
uidStringYesStorage settingsUser ID for UV data collection

SDK parameters

The following parameters are available in WeexLogger.singleton(props) and wxLogger.setConfig(config).

ParameterTypeRequiredDefaultDescription
pidStringYesNoneUnique project ID, auto-generated by ARMS when you create a site
uidStringYesNoneUser identifier for UV tracking. If not set, the SDK auto-generates a value and refreshes it every six months
tagStringNoNoneCustom tag attached to every log entry
releaseStringNoundefinedApplication version. Set this to compare metrics across releases
environmentStringNoprodDeployment environment. Valid values: prod (online), gray (phased-release), pre (staging), daily (daily build), local (local development)
sampleIntegerNo1Sampling rate from 1 to 100. Performance logs and successful API logs are sampled at a 1/sample ratio. For details, see Statistical metrics

For the complete parameter reference, see SDK reference.