Class PostHog

  • All Implemented Interfaces:
    com.posthog.PostHogCoreInterface , com.posthog.PostHogStatelessInterface , com.posthog.server.PostHogInterface

    
    public final class PostHog
    extends PostHogStateless implements PostHogInterface
                        
    • Constructor Detail

      • PostHog

        PostHog()
    • Method Detail

      • 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 distinctId
        userProperties - 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.
      • flush

         Unit flush()

        Flushes all the events in the Queue right away

      • 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 event
        event - the event name
        properties - the custom properties
        userProperties - 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 event
        appendFeatureFlags - 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 distinctId
        key - the Key
        defaultValue - 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 distinctId
        key - the Key
        defaultValue - 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 distinctId
        key - the Key
        groups - groups for group-based flags
        personProperties - person properties for flag evaluation
        groupProperties - group properties for flag evaluation
        sendFeatureFlagEvent - 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 distinctId
        type - the Group type
        key - the Group key
        groupProperties - 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 distinctId
        alias - 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 capture
        distinctId - the distinctId
        properties - the exception properties to add to the event