1.1.0 • Published 6 months ago

posthog-cap v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@capawesome/capacitor-posthog

Unofficial Capacitor plugin for PostHog.^1

Installation

npm install @capawesome/capacitor-posthog posthog-js
npx cap sync

Android

Variables

This plugin will use the following project variables (defined in your app's variables.gradle file):

  • $androidxCoreKtxVersion version of androidx.core:core-ktx (default: 1.13.1)
  • $posthogVersion version of com.posthog:posthog-android (default: 3.10.0)

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { Posthog } from '@capawesome/capacitor-posthog';

const alias = async () => {
  await Posthog.alias({
    alias: 'new-distinct-id',
  });
};

const capture = async () => {
  await Posthog.capture({
    event: 'event',
    properties: {
      key: 'value',
    },
  });
};

const flush = async () => {
  await Posthog.flush();
};

const group = async () => {
  await Posthog.group({
    type: 'group',
    key: 'key',
    groupProperties: {
      key: 'value',
    },
  });
};

const identify = async () => {
  await Posthog.identify({
    distinctId: 'distinct-id',
    userProperties: {
      key: 'value',
    },
  });
};

const register = async () => {
  await Posthog.register({
    key: 'super-property',
    value: 'super-value',
  });
};

const reset = async () => {
  await Posthog.reset();
};

const screen = async () => {
  await Posthog.screen({
    screenTitle: 'screen',
    properties: {
      key: 'value',
    },
  });
};

const setup = async () => {
  await Posthog.setup({
    apiKey: 'YOUR_API_KEY',
    host: 'https://eu.i.posthog.com',
    sessionRecording: true,
    sessionRecordingConfig: {
      maskAllTextInputs: true,
      maskAllImages: true,
      maskAllSandboxedViews: true,
      captureNetworkTelemetry: true,
      screenshotMode: false,
      debouncerDelay: 1.0
    }
  });
};

const unregister = async () => {
  await Posthog.unregister({
    key: 'super-property',
  });
};

API

alias(...)

alias(options: AliasOptions) => Promise<void>

Assign another distinct ID to the current user.

ParamType
optionsAliasOptions

Since: 6.0.0


capture(...)

capture(options: CaptureOptions) => Promise<void>

Capture an event.

ParamType
optionsCaptureOptions

Since: 6.0.0


flush()

flush() => Promise<void>

Flush all events in the queue.

Only available on Android and iOS.

Since: 6.0.0


getFeatureFlag(...)

getFeatureFlag(options: GetFeatureFlagOptions) => Promise<GetFeatureFlagResult>

Get the value of a feature flag.

ParamType
optionsGetFeatureFlagOptions

Returns: Promise<GetFeatureFlagResult>

Since: 7.0.0


getSessionId()

getSessionId() => Promise<GetSessionIdResult>

Get the current session ID.

Only available on Android and iOS.

Returns: Promise<GetSessionIdResult>

Since: 7.1.0


group(...)

group(options: GroupOptions) => Promise<void>

Associate the events for that user with a group.

ParamType
optionsGroupOptions

Since: 6.0.0


identify(...)

identify(options: IdentifyOptions) => Promise<void>

Identify the current user.

ParamType
optionsIdentifyOptions

Since: 6.0.0


isFeatureEnabled(...)

isFeatureEnabled(options: IsFeatureEnabledOptions) => Promise<IsFeatureEnabledResult>

Check if a feature flag is enabled.

ParamType
optionsIsFeatureEnabledOptions

Returns: Promise<IsFeatureEnabledResult>

Since: 7.0.0


register(...)

register(options: RegisterOptions) => Promise<void>

Register a new super property. This property will be sent with every event.

ParamType
optionsRegisterOptions

Since: 6.0.0


reloadFeatureFlags()

reloadFeatureFlags() => Promise<void>

Reload the feature flags.

Since: 7.0.0


reset()

reset() => Promise<void>

Reset the current user's ID and anonymous ID.

Since: 6.0.0


screen(...)

screen(options: ScreenOptions) => Promise<void>

Send a screen event.

Only available on Android and iOS.

ParamType
optionsScreenOptions

Since: 6.0.0


setup(...)

setup(options: SetupOptions) => Promise<void>

Setup the PostHog SDK with the provided options.

Attention: This method should be called before any other method.

ParamType
optionsSetupOptions

Since: 6.0.0


unregister(...)

unregister(options: UnregisterOptions) => Promise<void>

Remove a super property.

ParamType
optionsUnregisterOptions

Since: 6.0.0


Interfaces

AliasOptions

PropTypeDescriptionSince
aliasstringThe new distinct ID to assign to the current user.6.0.0

CaptureOptions

PropTypeDescriptionSince
eventstringThe name of the event to capture.6.0.0
propertiesRecord<string, any>The properties to send with the event.6.0.0

GetFeatureFlagResult

PropTypeDescriptionSince
valuestring | boolean | nullThe value of the feature flag. If the feature flag does not exist, the value will be null.7.0.0

GetFeatureFlagOptions

PropTypeDescriptionSince
keystringThe key of the feature flag.7.0.0

GetSessionIdResult

PropTypeDescriptionSince
sessionIdstring | nullThe current session ID. If no session is active, the value will be null.7.1.0

GroupOptions

PropTypeDescriptionSince
typestringThe group type.6.0.0
keystringThe group key.6.0.0
groupPropertiesRecord<string, any>The properties to send with the group event.6.0.0

IdentifyOptions

PropTypeDescriptionSince
distinctIdstringThe distinct ID of the user.6.0.0
userPropertiesRecord<string, any>The person properties to set.6.0.0

IsFeatureEnabledResult

PropTypeDescriptionSince
enabledbooleanWhether the feature flag is enabled. If the feature flag does not exist, the value will be false.7.0.0

IsFeatureEnabledOptions

PropTypeDescriptionSince
keystringThe key of the feature flag.7.0.0

RegisterOptions

PropTypeDescriptionSince
keystringThe name of the super property.6.0.0
valueanyThe value of the super property.6.0.0

ScreenOptions

PropTypeDescriptionSince
screenTitlestringThe name of the screen.6.0.0
propertiesRecord<string, any>The properties to send with the screen event.6.0.0

SetupOptions

PropTypeDescriptionDefaultSince
apiKeystringThe API key of your PostHog project.6.0.0
hoststringThe host of your PostHog instance.'https://us.i.posthog.com'6.0.0
sessionRecordingbooleanEnable session recording. Only available on iOS.false7.1.0
sessionRecordingConfigSessionRecordingConfigSession recording configuration. Only available on iOS.7.1.0

SessionRecordingConfig

PropTypeDescriptionDefaultSince
maskAllTextInputsbooleanEnable masking of all text and text input fields.true7.1.0
maskAllImagesbooleanEnable masking of all images to a placeholder.true7.1.0
maskAllSandboxedViewsbooleanEnable masking of all sandboxed system views.true7.1.0
captureNetworkTelemetrybooleanEnable capturing network telemetry.true7.1.0
screenshotModebooleanEnable screenshot mode. By default Session replay will capture all the views on the screen as a wireframe. By enabling this option, PostHog will capture the screenshot of the screen. The screenshot may contain sensitive information, use with caution.false7.1.0
debouncerDelaynumberDebouncer delay used to reduce the number of snapshots captured and reduce performance impact.1.07.1.0

UnregisterOptions

PropTypeDescriptionSince
keystringThe name of the super property to remove.6.0.0

Type Aliases

Record

Construct a type with a set of properties K of type T

{

}

Changelog

See CHANGELOG.md.

License

See LICENSE.

Session Recording

This plugin supports PostHog's Session Recording feature on iOS. Session Recording allows you to capture and replay user sessions to understand how users interact with your app.

Enabling Session Recording

To enable Session Recording, set the sessionRecording option to true when calling setup:

await Posthog.setup({
  apiKey: 'YOUR_API_KEY',
  host: 'https://eu.i.posthog.com',
  sessionRecording: true
});

Configuring Session Recording

You can customize the behavior of Session Recording by providing a sessionRecordingConfig object:

await Posthog.setup({
  apiKey: 'YOUR_API_KEY',
  host: 'https://eu.i.posthog.com',
  sessionRecording: true,
  sessionRecordingConfig: {
    // Mask all text inputs (default: true)
    maskAllTextInputs: true,
    // Mask all images (default: true)
    maskAllImages: true,
    // Mask all sandboxed system views (default: true)
    maskAllSandboxedViews: true,
    // Capture network telemetry (default: true)
    captureNetworkTelemetry: true,
    // Use screenshot mode instead of wireframe mode (default: false)
    // Note: Screenshots may contain sensitive information
    screenshotMode: false,
    // Debouncer delay in seconds (default: 1.0)
    debouncerDelay: 1.0
  }
});

Privacy Considerations

Session Recording captures user interactions with your app, which may include sensitive information. Consider the following privacy measures:

  • Use the masking options to hide sensitive content
  • Inform users about session recording in your privacy policy
  • Be cautious when enabling screenshot mode, as it captures actual screenshots instead of wireframes

Platform Support

Session Recording is currently only supported on iOS. When used on other platforms, the session recording options will be ignored.

^1: This project is not affiliated with, endorsed by, sponsored by, or approved by PostHog, Inc. or any of their affiliates or subsidiaries.

1.1.0

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago