Class PostHog
-
- All Implemented Interfaces:
-
com.posthog.PostHogCoreInterface,com.posthog.PostHogStatelessInterface,com.posthog.server.PostHogInterface
public final class PostHog extends PostHogStateless implements PostHogInterface
-
-
Constructor Summary
Constructors Constructor Description PostHog()
-
Method Summary
Modifier and Type Method Description <T extends PostHogConfig> Unitsetup(T config)Setup the SDK Unitclose()Closes the SDK Unitidentify(String distinctId, Map<String, Object> userProperties, Map<String, Object> userPropertiesSetOnce)Identifies the user Docs https://posthog. Unitflush()Flushes all the events in the Queue right away Unitdebug(Boolean enable)Enables or disables the debug mode Unitcapture(String distinctId, String event, Map<String, Object> properties, Map<String, Object> userProperties, Map<String, Object> userPropertiesSetOnce, Map<String, String> groups, Date timestamp, Boolean appendFeatureFlags)Captures events BooleanisFeatureEnabled(String distinctId, String key, Boolean defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)Returns if a feature flag is enabled, the feature flag must be a Boolean Docs https://posthog.com/docs/feature-flags and https://posthog. ObjectgetFeatureFlag(String distinctId, String key, Object defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)Returns the feature flags variant if multi-variant, otherwise whether it is enabled or not Docs https://posthog.com/docs/feature-flags and https://posthog. ObjectgetFeatureFlagPayload(String distinctId, String key, Object defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)Returns the feature flag payload Docs https://posthog.com/docs/feature-flags and https://posthog. FeatureFlagResultgetFeatureFlagResult(String distinctId, String key, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties, Boolean sendFeatureFlagEvent)Returns the feature flag result containing both value and payload. Unitgroup(String distinctId, String type, String key, Map<String, Object> groupProperties)Creates a group Docs https://posthog. Unitalias(String distinctId, String alias)Creates an alias for the user Docs https://posthog. UnitreloadFeatureFlags()Reloads feature flag definitions from the server for use with local evaluation. UnitcaptureException(Throwable exception, String distinctId, Map<String, Object> properties)Captures an exception Docs https://posthog. final static <T extends PostHogConfig> PostHogInterfacewith(T config)Set up the SDK and returns an instance that you can hold and pass it around -
Methods inherited from class com.posthog.PostHogStateless
aliasStateless, captureExceptionStateless, captureStateless, getFeatureFlagPayloadStateless, getFeatureFlagResultStateless, getFeatureFlagStateless, groupStateless, isFeatureEnabledStateless, isOptOut, optIn, optOut, setup -
Methods inherited from class com.posthog.server.PostHogInterface
capture, capture, captureException, captureException, captureException, getFeatureFlag, getFeatureFlag, getFeatureFlag, getFeatureFlagPayload, getFeatureFlagPayload, getFeatureFlagPayload, getFeatureFlagResult, getFeatureFlagResult, group, identify, identify, isFeatureEnabled, isFeatureEnabled, isFeatureEnabled -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
setup
<T extends PostHogConfig> Unit setup(T config)
Setup the SDK
- Parameters:
config- the SDK configuration
-
identify
Unit identify(String distinctId, Map<String, Object> userProperties, Map<String, Object> userPropertiesSetOnce)
Identifies the user Docs https://posthog.com/docs/product-analytics/identify
- Parameters:
distinctId- the distinctIduserProperties- the user properties, set as a "$set" property, Docs https://posthog.userPropertiesSetOnce- the user properties to set only once, set as a "$set_once" property, Docs https://posthog.
-
capture
Unit capture(String distinctId, String event, Map<String, Object> properties, Map<String, Object> userProperties, Map<String, Object> userPropertiesSetOnce, Map<String, String> groups, Date timestamp, Boolean appendFeatureFlags)
Captures events
- Parameters:
distinctId- the distinctId of the user performing the eventevent- the event nameproperties- the custom propertiesuserProperties- the user properties, set as a "$set" property, Docs https://posthog.userPropertiesSetOnce- the user properties to set only once, set as a "$set_once" property, Docs https://posthog.groups- the groups, set as a "$groups" property, Docs https://posthog.timestamp- the timestamp for the eventappendFeatureFlags- when true, enriches the event with feature flag properties
-
isFeatureEnabled
Boolean isFeatureEnabled(String distinctId, String key, Boolean defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)
Returns if a feature flag is enabled, the feature flag must be a Boolean Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments
- Parameters:
distinctId- the distinctIdkey- the KeydefaultValue- the default value if not found, false if not given
-
getFeatureFlag
Object getFeatureFlag(String distinctId, String key, Object defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)
Returns the feature flags variant if multi-variant, otherwise whether it is enabled or not Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments
- Parameters:
distinctId- the distinctIdkey- the KeydefaultValue- the default value if not found
-
getFeatureFlagPayload
Object getFeatureFlagPayload(String distinctId, String key, Object defaultValue, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties)
Returns the feature flag payload Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments
- Parameters:
distinctId- the distinctIdkey- the KeydefaultValue- the default value if not found
-
getFeatureFlagResult
FeatureFlagResult getFeatureFlagResult(String distinctId, String key, Map<String, String> groups, Map<String, Object> personProperties, Map<String, Map<String, Object>> groupProperties, Boolean sendFeatureFlagEvent)
Returns the feature flag result containing both value and payload. Docs https://posthog.com/docs/feature-flags and https://posthog.com/docs/experiments
- Parameters:
distinctId- the distinctIdkey- the Keygroups- groups for group-based flagspersonProperties- person properties for flag evaluationgroupProperties- group properties for flag evaluationsendFeatureFlagEvent- whether to send the $feature_flag_called event, or null to use config default
-
group
Unit group(String distinctId, String type, String key, Map<String, Object> groupProperties)
Creates a group Docs https://posthog.com/docs/product-analytics/group-analytics
- Parameters:
distinctId- the distinctIdtype- the Group typekey- the Group keygroupProperties- the Group properties, set as a "$group_set" property, Docs https://posthog.
-
alias
Unit alias(String distinctId, String alias)
Creates an alias for the user Docs https://posthog.com/docs/product-analytics/identify#alias-assigning-multiple-distinct-ids-to-the-same-user
- Parameters:
distinctId- the distinctIdalias- the alias
-
reloadFeatureFlags
Unit reloadFeatureFlags()
Reloads feature flag definitions from the server for use with local evaluation. Note that feature flag definitions are automatically fetched on initialization and periodically refreshed, so this method only needs to be called if you want to force an immediate refresh. Docs https://posthog.com/docs/feature-flags/local-evaluation
-
captureException
Unit captureException(Throwable exception, String distinctId, Map<String, Object> properties)
Captures an exception Docs https://posthog.com/docs/error-tracking
- Parameters:
exception- the exception to capturedistinctId- the distinctIdproperties- the exception properties to add to the event
-
with
final static <T extends PostHogConfig> PostHogInterface with(T config)
Set up the SDK and returns an instance that you can hold and pass it around
-
-
-
-