Skip to main content

Manual control acquisition

Supported version: Mini Program Probe >= 1.6.0

Startup configuration​

FieldTypeDefault ValueDescription
collection.manualbooleanfalseWhether to manually control the start of collection. When set to true, automatic collection does not occur after config, and monitor.start() needs to be called to initiate.
collection.bufferbooleanfalseWhen manual is set to true, manual collection is enabled. This determines whether to cache the collected data before calling monitor.start(). false means to discard, while true means to cache in memory.
collection.bufferLimitnumber10The upper limit of memory caching (in terms of the number of entries) when buffer=true; the minimum valid value is 1.

collection.buffer corresponds to two pre-collection strategies:

Buffer valueBehavior
false (default)Do not create monitoring data, cache data to be reported, or report before collection starts; only allow the maintenance of the minimum running state snapshot required for resuming collection.
trueAllow to collect and only cache limited reporting data in memory before the start of collection, and resend after the start of collection.

Default behavior: When collection is not configured or collection.manual=false, the default behavior is to immediately collect data after config.

Example:

// Startup configuration
monitor.config({
// . .. Other probe configurations, such as beacon and key
collection: {
manual: true // Manual control to enable collection, which requires calling monitor.start() to start normal collection
}
})

Calling API​

  • Start collecting:
// Start collecting (final state, can only be activated once)
monitor.start()
  • Give up collecting
// Discard collection (final state, can only take effect once)
monitor.abandon()

start() and abandon() are mutually exclusive: once either one is called, the other will no longer take effect. Both are idempotent, meaning repeated calls have no side effects.

Example:

// init.js
const monitor = require('./mp_agent_1.6.0.js')

monitor.config({
beacon: 'https://your-beacon-host',
key: 'your-app-key',
sampleRate: 1,
collection: {
manual: true
}
})

export default monitor;

// app.js
import monitor from './agent/init.js';

App({
onLaunch() {
// Display the privacy agreement pop-up, and call startCollection after the user agrees
wx.showModal({
title: 'Privacy Authorization',
content: 'Please read the privacy policy before use ..',
success(res) {
if (res.confirm) {
monitor.start() // Start normal data collection from now on
}
},
})
},
})