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
streammodule
Step 1: Install the SDK
Run the following command in your Weex project root:
npm install @arms/js-sdk --saveStep 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
sendRequestandpostRequestfunctions that use the Weexstreammodule.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:
| Placeholder | Description | Example |
|---|---|---|
<YOUR_SITE_ID> | Site ID assigned by ARMS when you created the site | xxxxxxxx |
<YOUR_USER_ID> | User identifier for UV tracking | user_12345 |
<YOUR_INITIAL_PAGE> | Name of the first page to report on initialization | Home |
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.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pid | String | Yes | None | Site ID assigned by ARMS |
page | String | No | None | Initial page name. Triggers a PV report after initialization |
uid | String | Yes | None | User ID for UV tracking |
imgUrl | String | No | None | Reporting 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);| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
nextPage | String | Yes | None | Name 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);| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
config | Object | Yes | None | Configuration properties to update |
uid | String | Yes | Storage settings | User ID for UV data collection |
SDK parameters
The following parameters are available in WeexLogger.singleton(props) and wxLogger.setConfig(config).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pid | String | Yes | None | Unique project ID, auto-generated by ARMS when you create a site |
uid | String | Yes | None | User identifier for UV tracking. If not set, the SDK auto-generates a value and refreshes it every six months |
tag | String | No | None | Custom tag attached to every log entry |
release | String | No | undefined | Application version. Set this to compare metrics across releases |
environment | String | No | prod | Deployment environment. Valid values: prod (online), gray (phased-release), pre (staging), daily (daily build), local (local development) |
sample | Integer | No | 1 | Sampling 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.