Mini-program docs
Scope
Mini-program analytics does not reuse the website's URL, referrer, PV or bounce definitions: sources are the host platform's scenes, pages are page routes (pages/…), data goes to a separate mini_events table, and the console has its own 13 report pages.
Steps
Download
The SDK is published on npm as fmeng-mini-sdk. It has no vendor dependencies and detects the WeChat wx / Alipay my / Douyin tt / Baidu swan runtime automatically. Install it with npm, then run Tools → Build npm in WeChat DevTools:
Projects without npm can download the file into the mini program (e.g. libs/fmeng-mini-sdk.js) and require that path instead:
Initialize
Initialize at the very top of app.js. It must run before App() so the SDK can wrap App and Page lifecycles:
Options: autoTrack (false to disable, or per item { app, page, share, error, performance }), appVersion (defaults to the release version), batchSize (events per request, default 10), flushInterval (batching delay in ms, default 3000), sessionTimeout (default 30 minutes of inactivity).
Auto-tracking
With auto-tracking on (the default), these events need no code:
| Event | Fired when | Key fields |
|---|---|---|
app_launch | App.onLaunch | scene, query, page_route |
app_show | App.onShow (cold start and returning to foreground) | scene, query, page_route |
app_hide | App.onHide, then sent immediately | duration (foreground time) |
page_view | Page.onShow | page_route, query |
share | onShareAppMessage / onShareTimeline (only if the page defines them) | share_source, page_route |
error | App.onError / onUnhandledRejection | message, stack, source |
performance | Page.onLoad → onReady | page_ready |
Each request also carries device model, OS version, network type and screen size. Visitor and session IDs are kept in local storage; a new visit starts after 30 minutes of inactivity.
Manual APIs
Call through getApp().fmeng in pages. Event names are up to 64 characters, with up to 30 properties whose values are strings, numbers or booleans:
Frameworks & platforms
In Taro, uni-app and similar frameworks the framework calls App() / Page() itself; when the SDK cannot patch the globals, wrap the option objects with wrapApp / wrapPage:
Alipay, Douyin and Baidu mini programs use the same SDK and the platform is detected from the runtime. Their scene systems differ, so reports show raw scene values (scene names and categories currently cover WeChat only).
Metrics
- Opens: times the mini program came to the foreground (app_show); cold starts and returning from background both count.
- Users: distinct users; new users first opened within the selected range.
- Visits: sessions; opening again after 30 minutes of inactivity starts a new visit.
- Avg. visit time: foreground time per visit (sum of app_hide durations; first-to-last event span when missing).
- Bounce rate: visits with a single page view ÷ visits with page views.
- Time on page: time until the next page view or backgrounding in the same visit, capped at 30 minutes.
- Retention: share of new users (first open within the range) who open again on day N (N = 1–7, 14, 30).
- Performance: durations are P75 (75% of samples are no slower); FPS is P25 (75% of samples are no lower).