Plugin Support
Due to the use of third-party plugins, mini program does not allow you to override the App and Page objects or modify the official API definitions, which causes monitoring to fail. The Agent provides a solution for plugins, requiring you to manually call Agent APIs for support. Plugin-related APIs must be used after enabling the plugin mode, which is set in the Agent startup configuration. When plugin mode is enabled, the Agent does not monitor automatically; you need to set it manually.
- To address errors caused by monitoring startup in lower versions, the Mini Program Agent enables the plugin mode by default. That is, the default behavior of the Agent is not to enable monitoring for Mini Program SDK versions below 2.6.4, and to enable monitoring automatically for versions 2.6.4 and above (WeChat mini program SDK 2.6.4 and later removes the restriction on plugin imports, so monitoring can be enabled directly). If your mini program project is below 2.6.4 and does not use plugins, you can set
plugin: falseto forcibly disable plugin mode and enable monitoring for lower versions. - For WeCom mini programs, the default SDK version may be low. If there is no data and you are not using plugins, it is recommended to set
plugin: falseto disable plugin mode.
Identifying Plugin Usage
You can set the plugin mode switch in the Agent initialization configuration: plugin.
true: Enable the plugin functionfalse: Disable the plugin function
Example:
monitor.config({
...,
plugin: true,
...
})
App
Use the hookApp API to wrap the original App parameters.
app.js
const monitor = require('./agent/tingyun-mp-agent.js');
App(monitor.hookApp({
onLaunch: function() {
// ...
},
...
}))
Page
Use the hookPage API to wrap the original Page parameters.
const monitor = require('./agent/tingyun-mp-agent.js');
Page(monitor.hookPage({
onLoad: function() {
// ...
},
...
}))
Component
For pages built with components, use hookComponent.
const monitor = require('./agent/tingyun-mp-agent.js');
Component(monitor.hookComponent({
// ...
}))
Network Request
Use the Agent-provided API monitor.request to send network requests. The parameters are consistent with the official wx.request API.
const monitor = require('./agent/tingyun-mp-agent.js');
monitor.request({
url: '...'
});