Skip to main content
The WeChat Mini Program RUM SDK provides the flashcatRum instance through @flashcatcloud/fc-sdk-miniprogram. After initialization, the SDK automatically collects page lifecycle events, user actions, network requests, app errors, and performance metrics, then reports them to Flashduty RUM.

Prerequisites

Before integrating the SDK, complete these steps:
  • Create or select a RUM application in the Flashduty console, then obtain the Application ID and Client Token
  • Confirm that your Mini Program can access the RUM intake URL. The default URL is https://browser.flashcat.cloud/api/v2/rum; configure proxy if your network policy requires forwarding
  • If you use WeChat DevTools, build npm so miniprogram_npm can reference the SDK package

Install the SDK

Install the RUM SDK in the Mini Program project root:
After installation, run Tools > Build npm in WeChat DevTools.

Initialize the SDK

Initialize the SDK as early as possible in the Mini Program entry file. The SDK wraps page lifecycle hooks, request methods, and app error listeners during initialization, so initializing it in app.js is recommended.
app.js
Do not use server-side keys in client code. clientToken is the token for client-side reporting, and applicationId identifies the RUM application.

Initialization Parameters

Required Parameters

string
required
RUM application ID. The SDK writes it to application.id so Mini Program data is associated with the correct application.
string
required
Client reporting token. The SDK appends this value to RUM intake requests as the dd-api-key parameter.

Basic Optional Parameters

string
default:"browser.flashcat.cloud"
RUM intake site. When proxy is not configured, the SDK sends events to https://{site}/api/v2/rum.
string | function
Custom reporting proxy. A string proxy produces {proxy}?ddforward={encodedPath}. A function proxy receives { path, parameters } and returns the full intake URL.
string
Service name. The SDK writes it as the service:<value> tag so you can filter RUM data by service.
string
Environment name. The SDK writes it as the env:<value> tag, such as production or staging.
string
Application version. The SDK writes it as the version:<value> tag for release-based error and performance analysis.
number
default:"100"
Session sample rate. The value represents the percentage of sessions to collect. 100 collects all sessions, while 0 collects no session events.
For production environments, a lower sample rate (for example, 10 for 10% sampling) is typically recommended to reduce storage cost.
number
default:"15000"
Batch flush interval in milliseconds. By default, the SDK tries to flush event batches every 15 seconds and also flushes when the Mini Program moves to the background.
(event: unknown) => boolean | void
Callback executed before an event is sent. Return false to prevent the current event from being sent to Flashduty.
boolean
default:"false"
Enables debug logs. When enabled, the SDK logs initialization, monitoring startup, event collection, and batch reporting details to the console.
boolean
default:"true"
Controls whether the SDK generates an anonymous user ID when no user information is set. When enabled, the SDK writes the anonymous ID to usr.id and usr.anonymous_id.

Collection Toggles

The following toggles control automatic collection. They are all enabled by default:

Use User Information and Global Context

After sign-in, use setUser() to associate events with the current user. The SDK writes these fields to the usr object on subsequent RUM events.
app.js
You can also use setGlobalContext() to add business context. Global context is written to the context field on subsequent events.
app.js

Manually Report Events

In addition to automatic collection, you can add business events, errors, actions, and custom timings manually.
pages/order/detail.js

Next Steps

Advanced Configuration

Configure proxying, distributed tracing, sessions, and manual instrumentation.

Compatibility

Learn about Mini Program base library, development tool, and platform API requirements.

Data Collection

Learn which event types, fields, and platform APIs the SDK collects automatically.