UNPKG

@capawesome/capacitor-posthog

Version:

Unofficial Capacitor plugin for PostHog SDK.

57 lines 1.72 kB
import { WebPlugin } from '@capacitor/core'; import posthog from 'posthog-js'; export class PosthogWeb extends WebPlugin { async alias(options) { posthog.alias(options.alias); } async capture(options) { posthog.capture(options.event, options.properties); } async getFeatureFlag(options) { const value = posthog.getFeatureFlag(options.key); return value === undefined ? { value: null } : { value }; } async getFeatureFlagPayload(options) { return { value: posthog.getFeatureFlagPayload(options.key) }; } async flush() { this.throwUnimplementedError(); } async group(options) { posthog.group(options.type, options.key, options.groupProperties); } async identify(options) { posthog.identify(options.distinctId, options.userProperties); } async isFeatureEnabled(options) { const enabled = posthog.isFeatureEnabled(options.key); return { enabled: enabled || false }; } async register(options) { posthog.register({ [options.key]: options.value, }); } async reloadFeatureFlags() { posthog.reloadFeatureFlags(); } async reset() { posthog.reset(); } async screen(_options) { this.throwUnimplementedError(); } async setup(options) { const host = options.host || 'https://us.i.posthog.com'; posthog.init(options.apiKey, { api_host: host, }); } async unregister(options) { posthog.unregister(options.key); } throwUnimplementedError() { throw this.unimplemented('Not implemented on web.'); } } //# sourceMappingURL=web.js.map