Class PostHog

java.lang.Object
net.hollowcube.posthog.PostHog

public final class PostHog extends Object
  • Constructor Details

    • PostHog

      public PostHog()
  • Method Details

    • init

      public static void init(@NotNull @NotNull String projectApiKey)
    • init

      public static void init(@NotNull @NotNull String projectApiKey, @NotNull @NotNull Function<PostHogClient.Builder,PostHogClient.Builder> builderFunc)
    • getClient

      @NotNull public static @NotNull PostHogClient getClient()
    • shutdown

      @Blocking public static void shutdown()
    • shutdown

      @Blocking public static void shutdown(@NotNull @NotNull Duration timeout)
    • capture

      public static void capture(@NotNull @NotNull String distinctId, @NotNull @NotNull String event)
      Capture an event with the given name for the given distinct ID with no properties.
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      event - Name of the event. May not be empty.
    • capture

      public static void capture(@NotNull @NotNull String distinctId, @NotNull @NotNull String event, @NotNull @NotNull Map<String,Object> properties)
      Capture an event with the given name for the given distinct ID with the provided properties.
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      event - Name of the event. May not be empty.
      properties - Event properties
    • capture

      public static void capture(@NotNull @NotNull String distinctId, @NotNull @NotNull String event, @NotNull @NotNull Object properties)
      Capture an event with the given name for the given ID with properties from the given object.

      The object must be serializable to a JSON object via Gson (not primitive or array)

      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      event - Name of the event. May not be empty.
      properties - Event object data
    • identify

      public static void identify(@NotNull @NotNull String distinctId, @Nullable @Nullable Map<String,Object> properties, @Nullable @Nullable Map<String,Object> propertiesSetOnce)
      Link the given properties with the person profile of the user (distinct id).
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      properties - Properties to set (including overwriting previous values) on the person profile
      propertiesSetOnce - Properties to set only if missing on the person profile
    • identify

      public static void identify(@NotNull @NotNull String distinctId, @Nullable @Nullable Object properties, @Nullable @Nullable Object propertiesSetOnce)
      Link the given properties with the person profile of the user (distinct id).

      The objects must be serializable to a JSON object via Gson (not primitive or array)

      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      properties - Properties to set (including overwriting previous values) on the person profile
      propertiesSetOnce - Properties to set only if missing on the person profile
    • identify

      public static void identify(@NotNull @NotNull String distinctId, @Nullable @Nullable Map<String,Object> properties)
      Link the given properties with the person profile of the user (distinct id).
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      properties - Properties to set (including overwriting previous values) on the person profile
    • identify

      public static void identify(@NotNull @NotNull String distinctId, @Nullable @Nullable Object properties)
      Link the given properties with the person profile of the user (distinct id).

      The object must be serializable to a JSON object via Gson (not primitive or array)

      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      properties - Properties to set (including overwriting previous values) on the person profile
    • alias

      public static void alias(@NotNull @NotNull String distinctId, @NotNull @NotNull String alias)
      Alias the given distinct ID to the given alias.
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty.
      alias - Alias to set for the distinct ID. May not be empty.
    • groupIdentify

      public static void groupIdentify(@NotNull @NotNull String type, @NotNull @NotNull String key, @NotNull @NotNull Map<String,Object> properties)
      Assign the given properties to the given group (type & key).
      Parameters:
      type - Group type. Must not be empty
      key - Group key. Must not be empty
      properties - Properties to set (including overwriting previous values) on the group
    • groupIdentify

      public static void groupIdentify(@NotNull @NotNull String type, @NotNull @NotNull String key, @NotNull @NotNull Object properties)
      Assign the given properties to the given group (type & key).

      The object must be serializable to a JSON object via Gson (not primitive or array)

      Parameters:
      type - Group type. Must not be empty
      key - Group key. Must not be empty
      properties - Properties to set (including overwriting previous values) on the group
    • flush

      public static void flush()
      Queue an immediate flush of the pending event queue. This call does not block on the flush to be completed.
    • isFeatureEnabled

      public static boolean isFeatureEnabled(@NotNull @NotNull String key, @NotNull @NotNull String distinctId)
      Check if the given feature flag is enabled for the given distinct ID.
      Parameters:
      key - Feature flag key
      distinctId - Unique ID of the target in your database. May not be empty
      Returns:
      True if the feature flag is enabled for the given distinct ID, false otherwise
    • isFeatureEnabled

      public static boolean isFeatureEnabled(@NotNull @NotNull String key, @NotNull @NotNull String distinctId, @Nullable @Nullable FeatureFlagContext context)
      Check if the given feature flag is enabled for the given distinct ID with extra context.
      Parameters:
      key - Feature flag key
      distinctId - Unique ID of the target in your database. May not be empty
      context - Extra context to pass to the feature flag evaluation
      Returns:
      True if the feature flag is enabled for the given distinct ID, false otherwise
    • getFeatureFlag

      @NotNull public static @NotNull FeatureFlagState getFeatureFlag(@NotNull @NotNull String key, @NotNull @NotNull String distinctId)
      Get the feature flag state for the given distinct ID.
      Parameters:
      key - Feature flag key
      distinctId - Unique ID of the target in your database. May not be empty
      Returns:
      Feature flag state
    • getFeatureFlag

      @NotNull public static @NotNull FeatureFlagState getFeatureFlag(@NotNull @NotNull String key, @NotNull @NotNull String distinctId, @Nullable @Nullable FeatureFlagContext context)
      Get the feature flag state for the given distinct ID with extra context.
      Parameters:
      key - Feature flag key
      distinctId - Unique ID of the target in your database. May not be empty
      context - Extra context to pass to the feature flag evaluation
      Returns:
      Feature flag state
    • getAllFeatureFlags

      @NotNull public static @NotNull FeatureFlagStates getAllFeatureFlags(@NotNull @NotNull String distinctId)
      Get all feature flags for the given distinct ID.
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty
      Returns:
      Feature flag states
    • getAllFeatureFlags

      @NotNull public static @NotNull FeatureFlagStates getAllFeatureFlags(@NotNull @NotNull String distinctId, @Nullable @Nullable FeatureFlagContext context)
      Get all feature flags for the given distinct ID with extra context.
      Parameters:
      distinctId - Unique ID of the target in your database. May not be empty
      context - Extra context to pass to the feature flag evaluation
      Returns:
      Feature flag states
    • reloadFeatureFlags

      public static void reloadFeatureFlags()
      Triggers a full reload of all local feature flags from the remote server. Only valid when local evaluation is enabled. This call does not block on the flush to be completed.
      Throws:
      IllegalStateException - if local feature flag evaluation is not enabled.
    • captureException

      public static void captureException(@NotNull @NotNull Throwable throwable)
    • captureException

      public static void captureException(@NotNull @NotNull Throwable throwable, @NotNull @NotNull String distinctId)
    • captureException

      public static void captureException(@NotNull @NotNull Throwable throwable, @NotNull @NotNull String distinctId, @NotNull @NotNull Map<String,Object> properties)
    • captureException

      public static void captureException(@NotNull @NotNull Throwable throwable, @Nullable @Nullable String distinctId, @Nullable @Nullable Object properties)