Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 38 additions & 23 deletions src/main/java/net/hollowcube/posthog/PostHog.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void shutdown(@NotNull Duration timeout) {
* Capture an event with the given name for the given distinct ID with no properties.
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param event Name of the event. May not be empty.
* @param event Name of the event. May not be empty.
*/
public static void capture(@NotNull String distinctId, @NotNull String event) {
getClient().capture(distinctId, event);
Expand All @@ -53,7 +53,7 @@ public static void capture(@NotNull String distinctId, @NotNull String event) {
* Capture an event with the given name for the given distinct ID with the provided properties.
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param event Name of the event. May not be empty.
* @param event Name of the event. May not be empty.
* @param properties Event properties
*/
public static void capture(@NotNull String distinctId, @NotNull String event, @NotNull Map<String, Object> properties) {
Expand All @@ -66,7 +66,7 @@ public static void capture(@NotNull String distinctId, @NotNull String event, @N
* <p>The object must be serializable to a JSON object via Gson (not primitive or array)</p>
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param event Name of the event. May not be empty.
* @param event Name of the event. May not be empty.
* @param properties Event object data
*/
public static void capture(@NotNull String distinctId, @NotNull String event, @NotNull Object properties) {
Expand All @@ -76,8 +76,8 @@ public static void capture(@NotNull String distinctId, @NotNull String event, @N
/**
* Link the given properties with the person profile of the user (distinct id).
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param propertiesSetOnce Properties to set only if missing on the person profile
*/
public static void identify(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) {
Expand All @@ -89,8 +89,8 @@ public static void identify(@NotNull String distinctId, @Nullable Map<String, Ob
*
* <p>The objects must be serializable to a JSON object via Gson (not primitive or array)</p>
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param propertiesSetOnce Properties to set only if missing on the person profile
*/
public static void identify(@NotNull String distinctId, @Nullable Object properties, @Nullable Object propertiesSetOnce) {
Expand Down Expand Up @@ -122,8 +122,8 @@ public static void identify(@NotNull String distinctId, @Nullable Object propert
/**
* Set the given properties with the person profile of the user (distinct id).
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param propertiesSetOnce Properties to set only if missing on the person profile
*/
public static void set(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) {
Expand All @@ -135,8 +135,8 @@ public static void set(@NotNull String distinctId, @Nullable Map<String, Object>
*
* <p>The objects must be serializable to a JSON object via Gson (not primitive or array)</p>
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param properties Properties to set (including overwriting previous values) on the person profile
* @param propertiesSetOnce Properties to set only if missing on the person profile
*/
public static void set(@NotNull String distinctId, @Nullable Object properties, @Nullable Object propertiesSetOnce) {
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void set(@NotNull String distinctId, @Nullable Object properties)
* Alias the given distinct ID to the given alias.
*
* @param distinctId Unique ID of the target in your database. May not be empty.
* @param alias Alias to set for the distinct ID. May not be empty.
* @param alias Alias to set for the distinct ID. May not be empty.
*/
public static void alias(@NotNull String distinctId, @NotNull String alias) {
getClient().alias(distinctId, alias);
Expand All @@ -178,8 +178,8 @@ public static void alias(@NotNull String distinctId, @NotNull String alias) {
/**
* Assign the given properties to the given group (type &amp; key).
*
* @param type Group type. Must not be empty
* @param key Group key. Must not be empty
* @param type Group type. Must not be empty
* @param key Group key. Must not be empty
* @param properties Properties to set (including overwriting previous values) on the group
*/
public static void groupIdentify(@NotNull String type, @NotNull String key, @NotNull Map<String, Object> properties) {
Expand All @@ -191,8 +191,8 @@ public static void groupIdentify(@NotNull String type, @NotNull String key, @Not
*
* <p>The object must be serializable to a JSON object via Gson (not primitive or array)</p>
*
* @param type Group type. Must not be empty
* @param key Group key. Must not be empty
* @param type Group type. Must not be empty
* @param key Group key. Must not be empty
* @param properties Properties to set (including overwriting previous values) on the group
*/
public static void groupIdentify(@NotNull String type, @NotNull String key, @NotNull Object properties) {
Expand All @@ -212,7 +212,7 @@ public static void flush() {
/**
* Check if the given feature flag is enabled for the given distinct ID.
*
* @param key Feature flag key
* @param key Feature flag key
* @param distinctId Unique ID of the target in your database. May not be empty
* @return True if the feature flag is enabled for the given distinct ID, false otherwise
*/
Expand All @@ -223,9 +223,9 @@ public static boolean isFeatureEnabled(@NotNull String key, @NotNull String dist
/**
* Check if the given feature flag is enabled for the given distinct ID with extra context.
*
* @param key Feature flag key
* @param key Feature flag key
* @param distinctId Unique ID of the target in your database. May not be empty
* @param context Extra context to pass to the feature flag evaluation
* @param context Extra context to pass to the feature flag evaluation
* @return True if the feature flag is enabled for the given distinct ID, false otherwise
*/
public static boolean isFeatureEnabled(@NotNull String key, @NotNull String distinctId, @Nullable FeatureFlagContext context) {
Expand All @@ -235,7 +235,7 @@ public static boolean isFeatureEnabled(@NotNull String key, @NotNull String dist
/**
* Get the feature flag state for the given distinct ID.
*
* @param key Feature flag key
* @param key Feature flag key
* @param distinctId Unique ID of the target in your database. May not be empty
* @return Feature flag state
*/
Expand All @@ -246,9 +246,9 @@ public static boolean isFeatureEnabled(@NotNull String key, @NotNull String dist
/**
* Get the feature flag state for the given distinct ID with extra context.
*
* @param key Feature flag key
* @param key Feature flag key
* @param distinctId Unique ID of the target in your database. May not be empty
* @param context Extra context to pass to the feature flag evaluation
* @param context Extra context to pass to the feature flag evaluation
* @return Feature flag state
*/
public static @NotNull FeatureFlagState getFeatureFlag(@NotNull String key, @NotNull String distinctId, @Nullable FeatureFlagContext context) {
Expand All @@ -271,7 +271,7 @@ public static boolean isFeatureEnabled(@NotNull String key, @NotNull String dist
* Get all feature flags for the given distinct ID with extra context.
*
* @param distinctId Unique ID of the target in your database. May not be empty
* @param context Extra context to pass to the feature flag evaluation
* @param context Extra context to pass to the feature flag evaluation
* @return Feature flag states
*/
public static @NotNull FeatureFlagStates getAllFeatureFlags(@NotNull String distinctId, @Nullable FeatureFlagContext context) {
Expand All @@ -288,6 +288,21 @@ public static void reloadFeatureFlags() {
getClient().reloadFeatureFlags();
}

/**
* Blocks until local feature flags have been fetched, or the timeout is reached.
*
* <p>This is useful during application startup to ensure feature flags are available
* before accepting requests. If it fails, local evals are disabled until it re-fetches (and it succeeds).
*
* @param timeout Maximum time to wait for the fetch to complete
* @return true if feature flags were successfully loaded, false if the fetch failed or timed out
* @throws UnsupportedOperationException if local feature flag evaluation is not enabled
*/
@Blocking
public static boolean loadRemoteFeatureFlags(@NotNull Duration timeout) {
return getClient().loadRemoteFeatureFlags(timeout);
}

// Exceptions

public static void captureException(@NotNull Throwable throwable) {
Expand Down
Loading
Loading