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
16 changes: 11 additions & 5 deletions src/main/java/net/hollowcube/posthog/PostHogClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import static net.hollowcube.posthog.PostHogNames.*;

public final class PostHogClientImpl implements PostHogClient {
private static final String LIBRARY_NAME = "github.com/hollow-cube/posthog-java";
private static final String LIBRARY_VERSION = "1.0.0";
private static final String USER_AGENT = String.format("%s/%s", LIBRARY_NAME, LIBRARY_VERSION);
private static final String DEFAULT_LIBRARY_NAME = "github.com/hollow-cube/posthog-java";
private static final String DEFAULT_LIBRARY_VERSION = "1.0.0";
private static final String USER_AGENT = String.format("%s/%s", DEFAULT_LIBRARY_NAME, DEFAULT_LIBRARY_VERSION);
private static final int STACKTRACE_FRAME_LIMIT = 100;

private static final Logger log = LoggerFactory.getLogger(PostHogClientImpl.class);
Expand Down Expand Up @@ -75,8 +75,8 @@ public final class PostHogClientImpl implements PostHogClient {
this.personalApiKey = personalApiKey;

this.defaultEventProperties = gson.toJsonTree(defaultEventProperties).getAsJsonObject();
this.defaultEventProperties.addProperty("$lib", LIBRARY_NAME);
this.defaultEventProperties.addProperty("$lib_version", LIBRARY_VERSION);
this.setPropertyIfAbsent(this.defaultEventProperties, LIB, DEFAULT_LIBRARY_NAME);
this.setPropertyIfAbsent(this.defaultEventProperties, LIB_VERSION, DEFAULT_LIBRARY_VERSION);
this.eventBatchTimeout = eventBatchTimeout;

// Always enable local evaluation with personal api key.
Expand Down Expand Up @@ -448,4 +448,10 @@ public void captureException(@NotNull Throwable throwable, @Nullable String dist
}
return stackFrames;
}

private void setPropertyIfAbsent(@NotNull JsonObject object, @NotNull String key, @NotNull String value) {
if (!object.has(key)) {
object.addProperty(key, value);
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/net/hollowcube/posthog/PostHogNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public final class PostHogNames {
public static final String GROUP_KEY = "$groupkey";
public static final String GROUP_SET = "$group_set";

public static final String LIB = "$lib";
public static final String LIB_VERSION = "$lib_version";

// This group is typically autocaptured by other SDKs, see here
// https://posthog.com/docs/product-analytics/autocapture
public static final String AUTO_CAPTURE = "$autocapture";
Expand Down
Loading