Skip to content

Add official WeChat Mini Program SDK #4491

Open

Description

@marandaneto

Context

This is the WeChat Mini Program runtime scope split out of #2223.

WeChat Mini Programs do not provide the browser APIs expected by posthog-js or posthog-js-lite. They use platform-specific APIs such as wx.request, wx storage, and Mini Program lifecycle hooks.

Proposed scope

Provide an officially supported PostHog SDK for the WeChat Mini Program runtime, preferably built on @posthog/core.

MVP capabilities

  • Event capture
  • User identification and reset
  • Persistent and session super properties
  • Session tracking
  • Persistent event queue
  • Batching, retries, and explicit flushing using wx.request
  • Persistence using WeChat storage APIs
  • Appropriate flushing during Mini Program lifecycle transitions

Out of scope for the initial SDK

Browser DOM-based features such as web autocapture, heatmaps, and session replay require separate Mini Program-specific designs and should not be implied by the MVP.

Acceptance criteria

  • A supported package is published from this repository
  • Capture, identify, reset, super properties, and sessions work across app restarts
  • Networking and persistence use WeChat-supported APIs without browser polyfills
  • Background/foreground lifecycle behavior is covered
  • Unit tests cover persistence, batching, retries, sessions, and lifecycle transitions
  • A runnable WeChat Mini Program example and setup documentation are provided

Related

Activity

  1. github-actions commented on Aug 11, 2026

    @github-actions
    Contributor

    AI triage for #4491

    Conclusion: Valid, well-scoped feature request for a new officially supported runtime SDK; it is not a small compatibility fix.
    Confidence: 94%
    Suggested labels: enhancement, web

    Thanks — this is a clear request for a dedicated Mini Program SDK rather than browser-SDK compatibility. The proposed MVP and exclusions are appropriately scoped: it should use WeChat-native transport, storage, and lifecycle APIs, and should not imply support for DOM-dependent features such as autocapture, heatmaps, or replay.

    @posthog/core provides the shared capture, identity, session, queue, batching, and retry behavior needed for a platform implementation, but this remains a new published package with a transport adapter, durable persistence behavior, lifecycle integration, test coverage, and a runnable example. It should be planned as a dedicated SDK effort rather than addressed through browser polyfills.

    Investigation

    • PostHogCoreStateless explicitly requires platform implementations to provide fetch, library metadata, and synchronous persisted-property access through abstract methods, while retaining shared queueing, batching, retries, capture, identity, and session behavior.
    • PostHogFetchOptions and PostHogFetchResponse define a fetch-like promise interface, so a WeChat implementation would need a small wx.request adapter that translates its callback response into status, text(), and json().
    • posthog-js-lite is browser-specific: packages/web/src/posthog-web.ts uses browser storage, window, history APIs, and the Fetch API, so it is not a suitable Mini Program runtime target.
    • posthog-react-native demonstrates the existing supported pattern of extending PostHogCore, supplying storage and transport implementations, delaying initialization until asynchronous storage preload completes, and flushing/persisting on application lifecycle transitions.
    • packages/react-native/src/storage.ts provides React-Native-specific storage wrappers and cannot be reused directly for WeChat storage APIs.
    • No WeChat/Mini Program package or runnable example was found under the workspace packages or examples.

    Relevant files: packages/core/src/posthog-core-stateless.ts, packages/core/src/posthog-core.ts, packages/core/src/types.ts, packages/web/src/posthog-web.ts, packages/react-native/src/posthog-rn.ts, packages/react-native/src/storage.ts, packages/core/package.json, pnpm-workspace.yaml

    Fix assessment

    • Straightforward: no
    • Risk: high
    • Reason: Although @posthog/core supplies the core analytics behavior, this request requires a new supported and published runtime package plus native transport, persistence durability, lifecycle semantics, test infrastructure, documentation, and a Mini Program example. Incorrect lifecycle or storage handling could lose or duplicate queued events.

    Fix PR skipped: feature requests require an explicit trusted fix command or mode: fix before opening a draft PR

    Pi session

    The resumable JSONL pi session for this run was saved to a private gist: https://gist.github.com/marandaneto/0ffde89f160808dcfc855ef9e710596e

    Download it locally, then fork it into your own pi session:

    pi --fork path/to/session.jsonl

    Saved session:

    Close proposal

    None. No issue close action was taken.


    Generated by posthog-watcher-action using pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions