openpanel-miniprogram
OpenPanel SDK for WeChat Mini Programs.
Install
npm install openpanel-miniprogram
Quick Start
import { OpenPanel, installAutoTracking } from 'openpanel-miniprogram';
const op = new OpenPanel({
clientId: 'YOUR_CLIENT_ID',
apiUrl: 'https://your-instance.com',
});
installAutoTracking(op);
App({
onLaunch() {
op.identify({ profileId: 'user-123' });
},
});
import { OpenPanel } from 'openpanel-miniprogram';
const op = new OpenPanel({ clientId: 'YOUR_CLIENT_ID' });
Page({
onTap() {
op.track('button_click', { button: 'buy_now' });
},
});
Options
interface MiniprogramOpenPanelOptions {
clientId: string;
clientSecret?: string;
apiUrl?: string;
requestAdapter?: WxRequestAdapter;
storageAdapter?: StorageAdapter;
autoTrackPageView?: boolean;
debug?: boolean;
filter?: (payload) => boolean;
disabled?: boolean;
}
API
All methods from @openpanel/sdk are available:
op.track(name, properties?)
op.identify({ profileId, firstName?, lastName?, email?, properties? })
op.setGroup(groupId)
op.setGroups(groupIds)
op.upsertGroup({ id, type, name, properties? })
op.increment({ profileId, property, value? })
op.decrement({ profileId, property, value? })
op.revenue(amount, properties?)
op.setGlobalProperties(properties)
op.clear()
op.screenView(pagePath, properties?)
op.destroy()
Offline Support
Events are automatically queued when the device is offline and flushed when connectivity returns. The queue is persisted to wx.storage so events survive app restarts.
How It Works
- Extends
@openpanel/sdk core class
- Replaces HTTP layer with
wx.request
- Persists offline queue + device/session IDs via
wx.storage
- Listens to network status changes for auto-flush
- Auto-populates global properties:
__platform, __os, __model, __system, __screen, __wxVersion, __sdkVersion
License
MIT