New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

openpanel-miniprogram

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openpanel-miniprogram

OpenPanel SDK for WeChat Mini Programs

Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
19
26.67%
Maintainers
1
Weekly downloads
 
Created
Source

openpanel-miniprogram

OpenPanel SDK for WeChat Mini Programs. Zero external runtime dependencies.

Install

npm install openpanel-miniprogram

Quick Start

// app.ts
import { OpenPanel } from 'openpanel-miniprogram';

const op = new OpenPanel({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET', // required for self-hosted instances
  apiUrl: 'https://your-instance.com/api', // default: https://api.openpanel.dev
});

App({
  onLaunch() {
    // identify user when ready
    op.identify({ profileId: 'user-123', firstName: 'Alice' });
  },
  logout() {
    op.clear();
  },
});
// pages/index/index.ts
import { op } from '~/app';

Page({
  onTap() {
    op.track('button_click', { button: 'buy_now' });
  },
});

Options

interface MiniprogramOpenPanelOptions {
  clientId: string;                  // Required
  clientSecret?: string;             // Required for self-hosted instances
  apiUrl?: string;                   // Default: https://api.openpanel.dev
  requestAdapter?: WxRequestAdapter; // Default: wx
  storageAdapter?: StorageAdapter;   // Default: wx.getStorageSync/setStorageSync
  waitForProfile?: boolean;          // Queue events until identify() is called
  filter?: (payload) => boolean;     // Filter events before sending
  disabled?: boolean;                // Disable all tracking
  debug?: boolean;                   // Log to console
}

API

Tracking

op.track(name, properties?)
op.screenView(pagePath, properties?)  // shorthand for track('screen_view', { __path: pagePath })
op.revenue(amount, properties?)       // shorthand for track('revenue', { __revenue: amount })

User Identity

op.identify({ profileId, firstName?, lastName?, email?, avatar?, properties? })
op.clear()  // clear user identity, groups, device/session IDs

Groups (B2B)

op.setGroup(groupId)                  // add user to a group
op.setGroups(groupIds)                // add user to multiple groups
op.upsertGroup({ id, type, name, properties? })  // create/update a group

User Properties

op.increment({ profileId, property, value? })
op.decrement({ profileId, property, value? })

Global Properties

op.setGlobalProperties({ key: 'value' })  // merged into every event

Lifecycle

op.ready()          // enable SDK + flush queued events
op.flush()          // manually flush offline queue
op.destroy()        // cleanup network listeners
op.getDeviceId()    // get persisted device ID
op.getSessionId()   // get persisted session ID

Auto Tracking (Optional)

Automatically track common scenarios with per-event switches (all enabled by default):

EventTriggerProperties
screen_viewevery Page.onShow__path page path
app_launchApp.onLaunch__scene / __query / __path from wx.getLaunchOptionsSync()
page_shareonShareAppMessage / onShareTimeline__path page path, __entry (menu / timeline)
import { OpenPanel, installAutoTracking } from 'openpanel-miniprogram';

const op = new OpenPanel({ clientId: 'YOUR_CLIENT_ID' });
installAutoTracking(op); // all events on

// disable specific events
installAutoTracking(op, { events: { screen_view: false } });

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

  • Self-contained implementation (zero runtime dependencies)
  • HTTP layer uses wx.request via configurable adapter
  • 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

Keywords

openpanel

FAQs

Package last updated on 17 Aug 2026

Related posts