Package net.hollowcube.posthog
Class PostHog
java.lang.Object
net.hollowcube.posthog.PostHog
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAlias the given distinct ID to the given alias.static voidCapture an event with the given name for the given distinct ID with no properties.static voidCapture an event with the given name for the given ID with properties from the given object.static voidCapture an event with the given name for the given distinct ID with the provided properties.static voidcaptureException(@NotNull Throwable throwable) static voidcaptureException(@NotNull Throwable throwable, @NotNull String distinctId) static voidcaptureException(@NotNull Throwable throwable, @NotNull String distinctId, @NotNull Map<String, Object> properties) static voidcaptureException(@NotNull Throwable throwable, @Nullable String distinctId, @Nullable Object properties) static voidflush()Queue an immediate flush of the pending event queue.static @NotNull FeatureFlagStatesgetAllFeatureFlags(@NotNull String distinctId) Get all feature flags for the given distinct ID.static @NotNull FeatureFlagStatesgetAllFeatureFlags(@NotNull String distinctId, @Nullable FeatureFlagContext context) Get all feature flags for the given distinct ID with extra context.static @NotNull PostHogClientstatic @NotNull FeatureFlagStategetFeatureFlag(@NotNull String key, @NotNull String distinctId) Get the feature flag state for the given distinct ID.static @NotNull FeatureFlagStategetFeatureFlag(@NotNull String key, @NotNull String distinctId, @Nullable FeatureFlagContext context) Get the feature flag state for the given distinct ID with extra context.static voidgroupIdentify(@NotNull String type, @NotNull String key, @NotNull Object properties) Assign the given properties to the given group (type & key).static voidAssign the given properties to the given group (type & key).static voidLink the given properties with the person profile of the user (distinct id).static voididentify(@NotNull String distinctId, @Nullable Object properties, @Nullable Object propertiesSetOnce) Link the given properties with the person profile of the user (distinct id).static voidLink the given properties with the person profile of the user (distinct id).static voididentify(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) Link the given properties with the person profile of the user (distinct id).static voidstatic voidinit(@NotNull String projectApiKey, @NotNull Function<PostHogClient.Builder, PostHogClient.Builder> builderFunc) static booleanisFeatureEnabled(@NotNull String key, @NotNull String distinctId) Check if the given feature flag is enabled for the given distinct ID.static booleanisFeatureEnabled(@NotNull String key, @NotNull String distinctId, @Nullable FeatureFlagContext context) Check if the given feature flag is enabled for the given distinct ID with extra context.static voidTriggers a full reload of all local feature flags from the remote server.static voidSet the given properties with the person profile of the user (distinct id).static voidSet the given properties with the person profile of the user (distinct id).static voidSet the given properties with the person profile of the user (distinct id).static voidset(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) Set the given properties with the person profile of the user (distinct id).static voidshutdown()static void
-
Constructor Details
-
PostHog
public PostHog()
-
-
Method Details
-
init
-
init
public static void init(@NotNull @NotNull String projectApiKey, @NotNull @NotNull Function<PostHogClient.Builder, PostHogClient.Builder> builderFunc) -
getClient
-
shutdown
@Blocking public static void shutdown() -
shutdown
-
capture
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 profilepropertiesSetOnce- 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 profilepropertiesSetOnce- 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
-
set
public static void set(@NotNull @NotNull String distinctId, @Nullable @Nullable Map<String, Object> properties, @Nullable @Nullable Map<String, Object> propertiesSetOnce) Set 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 profilepropertiesSetOnce- Properties to set only if missing on the person profile
-
set
public static void set(@NotNull @NotNull String distinctId, @Nullable @Nullable Object properties, @Nullable @Nullable Object propertiesSetOnce) Set 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 profilepropertiesSetOnce- Properties to set only if missing on the person profile
-
set
public static void set(@NotNull @NotNull String distinctId, @Nullable @Nullable Map<String, Object> properties) Set 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
-
set
Set 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
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 emptykey- Group key. Must not be emptyproperties- 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 emptykey- Group key. Must not be emptyproperties- 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 keydistinctId- 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 keydistinctId- Unique ID of the target in your database. May not be emptycontext- 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 keydistinctId- 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 keydistinctId- Unique ID of the target in your database. May not be emptycontext- 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 emptycontext- 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
-
captureException
-
captureException
-
captureException
-