More in Mini program analytics
Still have a question?
Could not find it? A person reads every message, usually within a few hours on business days.
Chat with usShort answer
Register your mini program's AppID under Mini program analytics › Configuration › SDK code, add https://api.pathclue.com to the mini program's request domain list in the WeChat admin console, install @tapcub/miniprogram and build npm in WeChat DevTools, then call TapCub.preInit({ siteKey, appId }) and TapCub.init() in app.js. Launches, page views and page leave times are collected automatically. Check Mini program analytics › Overview › Realtime for $mp_launch.
1. Register the AppID
Open Mini program analytics › Configuration › SDK code and click Add app identifier. Enter the mini program's AppID (it starts with wx). Data from an AppID that is not registered is dropped by the collector, with no error in the mini program.
2. Allow the collection domain
In the WeChat mini program admin console, go to Development › Development management › Server domain and add this to the request legal domains:
https://api.pathclue.com
Without it, requests never leave the device in production. (In DevTools you may not notice, because domain checks can be turned off there.)
3. Install the SDK
In the mini program project root:
npm install @tapcub/miniprogram
Then in WeChat DevTools choose Tools › Build npm so the package is copied into miniprogram_npm.
4. Initialize
In app.js:
import { TapCub } from '@tapcub/miniprogram/wx';
TapCub.preInit({
siteKey: 'YOUR_SITE_KEY',
appId: 'YOUR_APPID',
});
App({
onLaunch() {
TapCub.init();
},
});
appIdmust be the registered AppID. The collection address is built in; leaveendpointout unless TapCub gives you a dedicated address.preInithooks the App and Page lifecycles, so you do not need to forwardonLaunchoronShowyourself.- China mode: pass
region: 'cn', callinitonly after the user agrees, and callTapCub.grantConsent(['analytics']), or no events are sent.
5. What is collected automatically
- Cold start:
$mp_launchand$mp_show, with the scene value. - Pages: showing a page sends
$mp_view_screen; hiding it sends$mp_page_leavewith the time on page. - Clicks: off by default; pass
autoTrack: truetopreInitto collect them.
If your framework must not patch the global Page, wrap each page instead:
import { wrapPage } from '@tapcub/miniprogram/wx';
Page(wrapPage({ /* page options */ }));
For custom views, call TapCub.trackScreen('Name').
6. Events and identity
TapCub.track('purchase', { revenue: 19.9, currency: 'CNY' });
TapCub.login(openid, {}, { type: 'openid' });
TapCub.logout();
Event names can be up to 100 characters, with up to 30 custom properties and string values up to 200 characters. Login IDs can be up to 200 characters. To link openid, unionid and your own user ID across mini programs, apps and the website, see Identity on mini programs.
7. Verify
Preview the mini program on a phone (with domain checks on) and open Mini program analytics › Overview › Realtime. $mp_launch should appear within seconds. Then look at scene values under Scenes & sharing › Scenes and pages under Pages & events › Pages.
Privacy
The SDK does not read location, contacts or the clipboard, so it adds no privacy API to your WeChat user privacy guidelines. The local queue holds up to 10,000 events, 7 days or 1 MB. Failed requests (429, 5xx, network errors) back off from 1 second up to 300 seconds while events wait in the queue.
Troubleshooting
- Works in DevTools, nothing in production: the request domain is not in the legal domain list.
- No data at all: AppID not registered,
siteKeymissing, orinitnot called (in China mode, before consent). - No page views on some pages: those pages do not go through the patched
Page; usewrapPageortrackScreen. loginhas no effect: the ID is longer than 200 characters or a placeholder value, or the project is not in identified mode.
Related
Did this answer your question?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.