@liuzengwei/log-mp-sdk
v0.1.3
Published
uni-app data collection SDK focused on analytics-ready events
Downloads
43
Maintainers
Readme
log-mp SDK
Analytics-first data collection SDK for uni-app (WeChat Mini Program first).
Documentation
- API documentation: docs/API.md
Install
npm i @org/log-mp-sdkQuick Start
import { reporter } from "@org/log-mp-sdk";
reporter.init({
appId: "demo-app",
endpoint: "https://example.com/collect",
transport: "wx",
environment: "prod",
strictSchema: true
});
reporter.track("click", { elementId: "submit-button" });
reporter.trackCustom("biz_order_submit", { orderType: "normal", amount: 120 });Event Types in MVP
page_viewclicksession_startsession_endcustomviatrackCustom
Runtime Notes
- Call
initonce at app startup. - Call
flushon app hide or page unload. - Register custom schemas before calling
trackCustom.
Use Hook Pattern (Recommended)
You can encapsulate SDK usage into a hook-like module and only expose business-friendly methods.
1) Create useTracking module
See: examples/uniapp-wechat/useTracking.ts
2) Initialize once in app entry
See: examples/uniapp-wechat/main.ts.example
3) Use in each page
See: examples/uniapp-wechat/page-home.example.ts
This pattern keeps reporter hidden in one module and avoids repetitive initialization in pages.
