Integrating Mini Programs Based on the Uniapp Development Framework¶
Changelog
2026.8.25:
@cloudcare/rum-uniapp2.2.22: AddedallowedTracingUrls, matching by full request URL;allowedTracingOriginsis now a deprecated compatibility configuration; fixed page attribution on Douyin when navigation and page stack are temporarily empty.
2026.8.20:
@cloudcare/rum-uniapp2.2.21: Added fields for page first render, FP, FCP, LCP, Ready state, page exit reason,setDatasegment duration, and platform capability, which can be used to identify slow rendering and white screen candidates.
2026.8.11:
@cloudcare/rum-uniapp: AddedallowTraceHeaderWithoutSessionconfiguration, defaulting tofalse; when enabled, if the current session does not hit the RUM sampling rate, requests matchingallowedTracingOriginswill still inject Trace Headers, but will not force sampling or report RUM data for that session.
2022.9.29: Initialization parameters added isIntakeUrl configuration for determining whether to collect resource data based on the request resource URL; all resources are collected by default.
2022.3.29:
- Added
traceTypeconfiguration for configuring the trace tool type; defaults toddtraceif not configured. Currently supports 6 data types:ddtrace,zipkin,skywalking_v3,jaeger,zipkin_single_header,w3c_traceparent. - Added
allowedTracingOriginsfor all request lists allowed to inject headers required by the trace collector. Can be the request origin or a regular expression.
Prerequisites¶
- Install DataKit.
Application Integration¶
Log in to the TrueWatch console, go to the Real User Monitoring (RUM) page, and click Create in the upper left corner to start creating a new application.
On the right side, select the integration method for installation configuration, click Parameter Configuration on the right, fill in the relevant configuration parameters, and then copy them to your project.
Usage¶
Import the code at the top of the Uniapp project entry file main.js as follows:
NPM¶
Import (refer to the uniapp official npm import guide)
...
import Vue from 'vue'
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxRum } = require('@cloudcare/rum-uniapp')
// Initialize Rum
datafluxRum.init(Vue, {
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address; must be added to the domain whitelist in the WeChat Mini Program management console
applicationId: '<Application ID>', // Required, application ID generated by the dataflux platform
env: 'testing', // Optional, mini program environment
version: '1.0.0', // Optional, mini program version
service: 'miniapp', // Service name for the current application
trackInteractions: true, // User action data
sampleRate: 100, // Percentage of metric data collection; 100 means full collection, 0 means no collection
allowedTracingUrls: ['https://api.example.com/v1/', /https:\/\/.*\.my-api-domain\.com\/v2\//], // Matches by full request URL
})
//#endif
....
Import (refer to the uniapp official npm import guide)
...
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
import { datafluxRum } from '@cloudcare/rum-uniapp'
// Initialize Rum
datafluxRum.initVue3({
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address; must be added to the domain whitelist in the WeChat Mini Program management console
applicationId: '<Application ID>', // Required, application ID generated by the dataflux platform
env: 'testing', // Optional, mini program environment
version: '1.0.0', // Optional, mini program version
service: 'miniapp', // Service name for the current application
trackInteractions: true, // User action data
sampleRate: 100, // Percentage of metric data collection; 100 means full collection, 0 means no collection
allowedTracingUrls: ['https://api.example.com/v1/', /https:\/\/.*\.my-api-domain\.com\/v2\//], // Matches by full request URL
})
//#endif
....
CDN¶
Download the file and import it locally (Download URL)
...
import Vue from 'vue'
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxRum } = require('./dataflux-rum-uniapp.js'); // Local path to the JS file
// Initialize Rum
datafluxRum.init(Vue, {
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address; must be added to the domain whitelist in the WeChat Mini Program management console
applicationId: '<Application ID>', // Required, application ID generated by the dataflux platform
env: 'testing', // Optional, mini program environment
version: '1.0.0', // Optional, mini program version
service: 'miniapp', // Service name for the current application
trackInteractions: true, // User action data
sampleRate: 100, // Percentage of metric data collection; 100 means full collection, 0 means no collection
allowedTracingUrls: ['https://api.example.com/v1/', /https:\/\/.*\.my-api-domain\.com\/v2\//], // Matches by full request URL
})
//#endif
....
Download the file and import it locally (Download URL)
...
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
import { datafluxRum } from './dataflux-rum-uniapp.js'; // Local path to the JS file
// Initialize Rum
datafluxRum.initVue3({
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address; must be added to the domain whitelist in the WeChat Mini Program management console
applicationId: '<Application ID>', // Required, application ID generated by the dataflux platform
env: 'testing', // Optional, mini program environment
version: '1.0.0', // Optional, mini program version
service: 'miniapp', // Service name for the current application
trackInteractions: true, // User action data
sampleRate: 100, // Percentage of metric data collection; 100 means full collection, 0 means no collection
allowedTracingUrls: ['https://api.example.com/v1/', /https:\/\/.*\.my-api-domain\.com\/v2\//], // Matches by full request URL
})
//#endif
....
Configuration¶
Initialization Parameters¶
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
applicationId |
String | Yes | Application ID created from TrueWatch. | |
datakitOrigin |
String | Yes | DataKit data report Origin; ❗️ Must be added to the request whitelist in the Mini Program management console. |
|
env |
String | No | Current environment of the mini program, e.g., prod: production environment; gray: canary environment; pre: pre-release environment; common: daily environment; local: local environment. |
|
version |
String | No | Version number of the mini program application. | |
service |
String | No | Service name for the current application. Defaults to miniapp. Custom configuration is supported. |
|
sampleRate |
Number | No | 100 |
Percentage of metric data collection; 100 means full collection, 0 means no collection. |
trackInteractions |
Boolean | No | false |
Whether to enable user action collection. |
traceType |
Enum | No | ddtrace |
Configures the trace tool type. Defaults to ddtrace if not configured. Currently supports 6 data types: ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent.❗️ 1. opentelemetry supports zipkin_single_header, w3c_traceparent, zipkin, jaeger 4 types.2. Configuring the corresponding traceType requires setting different Access-Control-Allow-Headers for the corresponding API service. See How APM connects to RUM. |
traceId128Bit |
Boolean | No | false |
Whether to generate a 128-bit traceID. Corresponds to traceType. Currently supports zipkin, jaeger. |
allowedTracingUrls |
Array | No | [] |
A list of full request URL matches allowed to inject Trace Headers. Strings match by URL prefix; regular expressions and functions receive the full URL; objects use { match, traceType } to specify the propagation type for a single rule. Requires version 2.2.22 or above. |
allowedTracingOrigins |
Array | No | Deprecated compatibility configuration, only matches by request Origin; use allowedTracingUrls for new projects. When both are set, allowedTracingUrls takes precedence. |
|
allowTraceHeaderWithoutSession |
Boolean | No | false |
Whether to still inject Trace Headers for requests matching allowedTracingUrls when the current session is not sampled. When enabled, this does not force sampling or report RUM data for that session. |
isIntakeUrl |
Function | No | function(url) {return false} |
Custom method to determine whether to collect resource data based on the request resource URL. All resources are collected by default. Returns: false means collect, true means do not collect. ❗️ 1. The return value of this parameter must be of type Boolean, otherwise it is considered invalid. 2. Requires version 2.1.13 or above. |
Trace Header URL Matching¶
allowedTracingUrls matches using the full request URL. Strings match by URL prefix, RegExp and Function receive the full URL; when a single rule requires a different propagation type, use { match, traceType }:
allowedTracingUrls: [
'https://api.example.com/v1/',
/https:\/\/.*\.my-api-domain\.com\/v2\//,
function (url) {
return url.indexOf('https://internal.example.com/') === 0
},
{ match: 'https://otel.example.com/', traceType: 'w3c_traceparent' },
]
When delivered via remote configuration, only JSON-representable strings or { match: String, traceType } can be used; RegExp and Function cannot be delivered. allowedTracingOrigins is only used for backward compatibility with old configurations; if both parameters exist, the SDK only uses allowedTracingUrls.
Page Performance and White Screen Candidates¶
Versions 2.2.21 and above of @cloudcare/rum-uniapp collect page lifecycle, platform Performance entry, and setData duration. All duration fields are reported to TrueWatch in nanoseconds (ns).
The SDK does not capture screenshots and cannot confirm whether business content after the skeleton screen is usable. Therefore, metrics can only be used to identify performance anomalies and white screen candidates, and cannot independently prove that a visual white screen occurred on the page.
Platform Capability and Lifecycle¶
| Field | Type | Description |
|---|---|---|
performance_supported |
Boolean | Whether the Performance Observer subscription was successful on the current platform |
first_render_supported |
Boolean | Whether a first render signal usable by the SDK exists on the current platform |
view_start_reason |
String | page_load, page_show, or session_renewal |
view_end_reason |
String | onHide, onUnload, or session_renewal |
ready_reached |
Boolean | Whether the page lifecycle has reached onReady |
first_render_reached |
Boolean | Whether the current page has received the platform's first render signal |
ended_before_ready |
Boolean | Whether the page_load View ended before reaching onReady |
ended_before_render |
Boolean | When the first render signal is supported, whether the page_load View ended before the first render |
view_is_active |
Boolean | Whether the View is still active |
ended_before_render is only statistically meaningful when first_render_supported=true. Session renewal only splits the RUM View and does not indicate a page reload, so no conclusion of premature page exit is generated.
Rendering and setData Metrics¶
| Field | Description |
|---|---|
loading_time |
Maximum loading duration observed from page navigation and lifecycle |
page_ready_time |
Duration from View start to onReady |
first_render_time |
WeChat firstRender.duration; for Douyin, first-paint - navigationStart |
page_fp |
FP duration relative to the current page's navigationStart |
page_fcp |
FCP duration relative to the current page's navigationStart |
page_lcp |
Duration of the most recent LCP on the current page relative to navigationStart |
view_setdata_count |
Number of valid setData update samples |
view_setdata_duration |
Cumulative duration of all valid updates |
view_setdata_max_duration |
Maximum duration of a single update |
view_setdata_pending_duration |
Cumulative waiting duration from entering the queue to starting the update |
view_setdata_update_duration |
Cumulative execution duration from starting the update to completion |
view_setdata_merged_count |
Number of updates merged by the platform |
The SDK associates platform entries with page instances by route, pageId, and the latest navigationStart to avoid cross-page contamination from rapid page switching, same-route reconstruction, and delayed callbacks. Delayed setData callbacks from hidden pages, unloaded pages, or old components are not counted in the current View.
Recommended Statistics¶
For white screen candidate statistics, first filter by view_start_reason=page_load, performance_supported=true, and first_render_supported=true, then observe the following metrics:
| Issue | Recommended Condition | Description |
|---|---|---|
| Slow first render | first_render_time exceeds business threshold |
Calculate P75, P95, and the proportion exceeding the threshold |
| Ended before first render | ended_before_render=true |
High-confidence white screen candidate, but users actively returning quickly can also trigger this |
| Long time not Ready | page_ready_time exceeds business threshold |
Reflects lifecycle or initialization blocking, not equivalent to visual white screen |
| Ended before Ready | ended_before_ready=true |
Combine with view_end_reason and dwell time to exclude quick exits |
| Slow FCP/LCP | page_fcp or page_lcp exceeds business threshold |
Used to observe content appearance and main content stabilization speed |
During the startup phase, action_type=launch_attempt is also reported to calculate the coverage of native launch entries. The absence of a platform Performance entry cannot be used as evidence of zero duration or white screen.
For platform performance specifications, refer to WeChat Mini Program PerformanceEntry, WeChat Mini Program setData Performance, Douyin Mini Program createObserver, and Douyin Mini Program PerformanceEntry.
Notes:
- The DataKit domain corresponding to
datakitOriginmust be added to the request whitelist in the Mini Program management console. - Currently, the performance data API exposure across different mini program platforms is not yet unified, which may result in incomplete collection of some performance data, such as
mini program launch,mini program package download, andscript injection. Apart from the WeChat platform, data may be missing on other platforms. - Currently, the
profilefield in the returned data of each platform's mini program request resource APIs (uni.request,uni.downloadFile) is only unsupported by the iOS system for WeChat Mini Programs. This leads to incomplete collection of timing-related resource information. There is currently no solution: request, downloadFile, API support status. - When
trackInteractions(user action collection) is enabled, due to the limitations of WeChat Mini Programs, control content and structure data cannot be collected. Therefore, in the mini program SDK, we use declarative programming. By setting thedata-nameattribute in the template, you can add a name to interactive elements to facilitate locating operation records in subsequent statistics. For example:
