Skip to content

Commit

Permalink
fix: include posthog library property in events (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Nov 6, 2023
1 parent e4dfb72 commit 0a27805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions posthog/src/main/java/com/posthog/java/PostHog.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private JSONObject getEventJson(String event, String distinctId, Map<String, Obj
eventJson.put("timestamp", Instant.now().toString());
eventJson.put("distinct_id", distinctId);
eventJson.put("event", event);
eventJson.put("$lib", "posthog-java");
if (properties != null) {
eventJson.put("properties", properties);
}
Expand Down
15 changes: 15 additions & 0 deletions posthog/src/test/java/com/posthog/java/PostHogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public void testCaptureWithProperties() {
+ "\"}").isEqualTo(new JSONObject(json, "distinct_id", "event", "properties", "timestamp").toString());
}

@Test
public void testCaptureIncludesLibProperty() {
ph.capture("test id", "test event", new HashMap<String, Object>() {
{
put("movie_id", 123);
put("category", "romcom");
}
});
ph.shutdown();
assertEquals(1, sender.calls.size());
assertEquals(1, sender.calls.get(0).size());
JSONObject json = sender.calls.get(0).get(0);
assertThatJson("{\"$lib\":\"posthog-java\"}").isEqualTo(new JSONObject(json, "$lib").toString());
}

@Test
public void testIdentifySimple() {
ph.identify("test id", new HashMap<String, Object>() {
Expand Down

0 comments on commit 0a27805

Please sign in to comment.