Posthog class

Entry point for the PostHog Flutter SDK.

Use the singleton returned by Posthog to set up the SDK, capture events, identify users, evaluate feature flags, and control session replay.

Constructors

Posthog()
Returns the singleton PostHog client instance.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
logger → PostHogLogger
Per-level logger facade for capturing structured logs.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addExceptionStep(String message, {Map<String, Object>? properties}) → Future<void>
Records an exception step (breadcrumb-style context record).
alias({required String alias}) → Future<void>
Creates an alias for the current user.
capture({required String eventName, Map<String, Object>? properties, Map<String, Object>? userProperties, Map<String, Object>? userPropertiesSetOnce}) → Future<void>
Captures a custom event.
captureException({required Object error, StackTrace? stackTrace, Map<String, Object>? properties}) → Future<void>
Captures an exception with optional custom properties.
captureFeatureInteraction(String flag, {String? flagVariant}) → Future<void>
Captures a $feature_interaction event when the user interacts with the feature behind the feature flag flag.
captureFeatureView(String flag, {String? flagVariant}) → Future<void>
Captures a $feature_view event when the user sees the feature behind the feature flag flag.
captureLog({required String body, PostHogLogSeverity level = PostHogLogSeverity.info, Map<String, Object>? attributes, String? traceId, String? spanId, int? traceFlags}) → Future<void>
Captures a structured log record.
capturePushNotificationOpened({String? title, String? subtitle, String? body, Map<String, Object?>? payload, String? action}) → Future<void>
Captures $push_notification_opened when a user opens a push notification.
captureRunZonedGuardedError({required Object error, StackTrace? stackTrace, Map<String, Object>? properties}) → Future<void>
Captures a runZonedGuarded error with optional custom properties.
close() → Future<void>
Closes the PostHog SDK and cleans up resources.
debug(bool enabled) → Future<void>
Enables or disables verbose logs about the inner workings of the SDK.
disable() → Future<void>
Opts the current user out of data collection.
enable() → Future<void>
Opts the current user back in to data collection.
flush() → Future<void>
Flushes queued events immediately where supported by the platform.
getAllFeatureFlags() → Future<List<PostHogFeatureFlagResult>?>
Returns the results of all currently loaded feature flags.
getDistinctId() → Future<String>
Returns the registered distinctId property.
getFeatureFlag(String key, {bool? sendFeatureFlagEvent}) → Future<Object?>
Returns the feature flag value for key.
getFeatureFlagPayload(String key) → Future<Object?>
Returns the payload for the feature flag key.
getFeatureFlagResult(String key, {bool sendEvent = true}) → Future<PostHogFeatureFlagResult?>
Returns the full feature flag result for key, including value and payload.
getSessionId() → Future<String?>
Returns the session ID if a session is active.
group({required String groupType, required String groupKey, Map<String, Object>? groupProperties}) → Future<void>
Associates the current user with a group.
identify({required String userId, Map<String, Object>? userProperties, Map<String, Object>? userPropertiesSetOnce}) → Future<void>
Associates events with a specific user.
isFeatureEnabled(String key, {bool? sendFeatureFlagEvent}) → Future<bool>
Returns whether a boolean feature flag is enabled.
isOptOut() → Future<bool>
Returns whether the current user has opted out of data collection.
isSessionReplayActive() → Future<bool>
Returns whether session replay is currently active.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optIn() → Future<void>
Opts the current user back in to data collection.
optOut() → Future<void>
Opts the current user out of data collection.
register(String key, Object value) → Future<void>
Registers a super property sent with all following events.
registerPushNotificationToken(String deviceToken, {String? appId}) → Future<void>
Registers this device's push token or Firebase Installation ID (FID) so PostHog Workflows can target it.
reloadFeatureFlags() → Future<void>
Reloads feature flags for the current user.
reset() → Future<void>
Resets all cached properties including the distinctId.
resetGroupPropertiesForFlags({String? groupType, bool reloadFeatureFlags = true}) → Future<void>
Clears group properties that were set for feature flag evaluation via setGroupPropertiesForFlags.
resetPersonPropertiesForFlags({bool reloadFeatureFlags = true}) → Future<void>
Clears all person properties that were set for feature flag evaluation via setPersonPropertiesForFlags.
screen({required String screenName, Map<String, Object>? properties}) → Future<void>
Captures a screen view event.
setGroupPropertiesForFlags(String groupType, Map<String, Object> groupProperties, {bool reloadFeatureFlags = true}) → Future<void>
Sets properties for a specific groupType that are used only for feature flag evaluation.
setPersonProperties({Map<String, Object>? userPropertiesToSet, Map<String, Object>? userPropertiesToSetOnce}) → Future<void>
Sets person properties for the current user without requiring identify.
setPersonPropertiesForFlags(Map<String, Object> userProperties, {bool reloadFeatureFlags = true}) → Future<void>
Sets person properties that are used only for feature flag evaluation.
setup(PostHogConfig config) → Future<void>
Initializes the PostHog SDK.
startSessionRecording({bool resumeCurrent = true}) → Future<void>
Starts session recording.
stopSessionRecording() → Future<void>
Stops the current session recording if one is in progress.
toString() → String
A string representation of this object.
inherited
unregister(String key) → Future<void>
Unregisters a previously registered super property.
unregisterPushNotificationToken() → Future<void>
Unregisters this device's push token so Workflows stop targeting it — for example from your logout flow.

Operators

operator ==(Object other) → bool
The equality operator.
inherited