Skip to content

Mini Program Application Integration


By introducing the SDK file, collect performance metrics, error logs, and resource request data from mini program applications, and report them to the TrueWatch platform to visually analyze the performance of mini program applications.

Prerequisites (Datakit Integration)

Start Integration

  1. Go to RUM > Create > Web.
  2. Enter the application name.
  3. Enter the application ID.
  4. Choose the application integration method:

  5. Public DataWay: Directly receives RUM data without installing the DataKit collector.

  6. Local Environment Deployment: Receives RUM data after meeting the prerequisites.

Integration Methods

  1. Ensure DataKit is installed and configured to be publicly accessible with the IP geolocation database installed.
  2. Obtain parameters like applicationId, env, version from the console, and start integrating the application.
  3. When integrating the SDK, set datakitOrigin to the domain name or IP of DataKit.

  1. Obtain parameters like applicationId, clientToken, and site from the console, and start integrating the application.
  2. No need to configure datakitOrigin when integrating the SDK; data will be sent to the public DataWay by default.

Usage

Introduce the code in the mini program's app.js file as follows:

Note: The introduction must occur before the App() initialization.

Refer to the official WeChat npm introduction method for NPM package introduction.

const { datafluxRum } = require('@cloudcare/rum-miniapp')
// Initialize Rum
datafluxRum.init({
  datakitOrigin: '<DATAKIT ORIGIN>', // Required, Datakit domain address. Must be added to the WeChat mini program admin whitelist.
  site: "http://172.16.212.186:9529", // Domain of the public DataWay corresponding site
  clientToken: "a993f53a8ea04bc6b9350e5e670a3a3b", // Client token required for public DataWay reporting, generated when creating the application in the Guance 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 of the current application.
  trackInteractions: true,
  traceType: 'ddtrace', // Optional, defaults to ddtrace. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent 6 types.
  allowedTracingOrigins: ['https://api.example.com',/https:\/\/.*\.my-api-domain\.com/],  // Optional, list of all requests allowed to inject headers required by the trace collector. Can be request origin or regex.
})

Introduce locally by downloading the file.

const { datafluxRum } = require('./lib/dataflux-rum-miniapp.js')
// Initialize Rum
datafluxRum.init({
  datakitOrigin: '<DATAKIT ORIGIN>', // Required, Datakit domain address. Must be added to the WeChat mini program admin whitelist.
  site: "http://172.16.212.186:9529", // Domain of the public DataWay corresponding site
  clientToken: "a993f53a8ea04bc6b9350e5e670a3a3b", // Client token required for public DataWay reporting, generated when creating the application in the Guance 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 of the current application.
  trackInteractions: true,
  traceType: 'ddtrace', // Optional, defaults to ddtrace. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent 6 types.
  allowedTracingOrigins: ['https://api.example.com',/https:\/\/.*\.my-api-domain\.com/],  // Optional, list of all requests allowed to inject headers required by the trace collector. Can be request origin or regex.
})

Configuration

Initialization Parameters

Parameter Type Required Default Value Description
applicationId String Yes Application ID created in TrueWatch.
datakitOrigin String Yes Data reporting Origin for DataKit.
❗️ Must be added to the request whitelist in the mini program admin backend.
site String Yes (Required for Public DataWay method) Domain of the public DataWay corresponding site. Note: Protocol (including ://), domain (or IP address) [and port]. e.g., https://www.dataway.com, http://100.20.34.3:8088.
clientToken String Yes (Required for Public DataWay method) Client token required for public DataWay reporting, generated when creating the application in the TrueWatch console.
env String No Current environment of the mini program application, e.g., prod: production; gray: gray; pre: pre-release; common: daily; local: local.
version String No Version number of the mini program application.
service String No miniapp Service name of the current application, defaults to miniapp, supports custom configuration.
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 interaction collection.
traceType Enum No ddtrace Configure the trace tool type. Defaults to ddtrace if not configured. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent 6 types.
❗️
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. Refer to APM How to Connect RUM.
traceId128Bit Boolean No false Whether to generate traceID in 128 bytes. Corresponds to traceType, currently supports zipkin, jaeger.
allowedTracingOrigins Array No [] 【New】List of all requests allowed to inject headers required by the ddtrace collector. Can be request origin or regex, origin: Protocol (including ://), domain (or IP address) [and port]. _e.g., ["https://api.example.com", /https:\\/\\/._\\.my-api-domain\\.com/]*
isIntakeUrl Function No function(url) {return false} Custom method to determine whether to collect data for a resource based on its request URL. Returns: false means collect, true means do not collect.
❗️
1. The return result of this parameter method must be Boolean, otherwise it is considered invalid.
2. Requires version 2.1.10 or above.

Notes

  1. The DataKit domain corresponding to datakitOrigin must be added to the request whitelist in the mini program admin backend.
  2. Because the current WeChat mini program resource request APIs wx.request and wx.downloadFile return data where the profile field is not supported on iOS systems, this leads to incomplete collection of timing-related data in resource information. There is currently no solution: request, downloadFile, API Support.
  3. After enabling user interaction collection with trackInteractions, due to WeChat mini program limitations, it's impossible to collect the content and structure data of controls. Therefore, in the mini program SDK, we adopt a declarative programming approach. By setting the data-name attribute in the wxml file, you can add a name to the interactive element, facilitating the subsequent identification of operation records during statistics. For example:
<button bindtap="bindSetData" data-name="setData">
  setData
</button>