Skip to content

Commit cdba194

Browse files
chore: update timestamp and support string/map metadata
1 parent f6708ae commit cdba194

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

sdk/src/main/java/com/hcaptcha/sdk/HCaptchaVerifyParams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public class HCaptchaVerifyParams implements Serializable {
4343
* Optional user journey events to be passed to hCaptcha.
4444
* Contains user interaction events for analytics.
4545
*/
46-
@JsonProperty("user_journey")
46+
@JsonProperty("userjourney")
4747
private Object userJourney;
4848
}

sdk/src/main/java/com/hcaptcha/sdk/journeylitics/ConsoleSink.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

sdk/src/main/java/com/hcaptcha/sdk/journeylitics/JLConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.hcaptcha.sdk.journeylitics;
22

33
import java.util.Arrays;
4+
import java.util.Collections;
45
import java.util.List;
56

67
/**
@@ -32,7 +33,7 @@ public class JLConfig {
3233
}
3334

3435
JLConfig() {
35-
this(true, true, true, true, true, true, true, Arrays.asList(ConsoleSink.INSTANCE));
36+
this(true, true, true, true, true, true, true, Collections.emptyList());
3637
}
3738

3839
/**

sdk/src/main/java/com/hcaptcha/sdk/journeylitics/JLEvent.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44

55
import java.util.Map;
6+
import java.util.concurrent.TimeUnit;
67

78
public class JLEvent {
8-
private final long timestampMs;
9+
private final long timestamp;
910
private final EventKind kind;
1011
private final String view;
11-
private final Map<String, Object> metadata;
12+
private final Object metadata;
1213

13-
JLEvent(long timestampMs, EventKind kind, String view, Map<String, Object> metadata) {
14-
this.timestampMs = timestampMs;
14+
JLEvent(long timestamp, EventKind kind, String view, Object metadata) {
15+
this.timestamp = timestamp;
1516
this.kind = kind;
1617
this.view = view;
1718
this.metadata = metadata;
1819
}
1920

2021
JLEvent(EventKind kind, String view, Map<String, Object> metadata) {
21-
this(System.currentTimeMillis(), kind, view, metadata);
22+
this(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), kind, view, metadata);
2223
}
2324

2425
JLEvent(EventKind kind, String view) {
2526
this(kind, view, new java.util.HashMap<>());
2627
}
2728

29+
/**
30+
* UNIX timestamp (seconds).
31+
*/
2832
@JsonProperty("ts")
29-
long getTimestampMs() {
30-
return timestampMs;
33+
long getTimestamp() {
34+
return timestamp;
3135
}
3236

3337
@JsonProperty("k")
@@ -41,7 +45,7 @@ String getView() {
4145
}
4246

4347
@JsonProperty("m")
44-
Map<String, Object> getMetadata() {
48+
Object getMetadata() {
4549
return metadata;
4650
}
4751
}

sdk/src/test/java/com/hcaptcha/sdk/journeylitics/JourneyliticsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.hcaptcha.sdk.journeylitics;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
35
import org.junit.Assert;
46
import org.junit.Test;
57

@@ -28,5 +30,23 @@ public void emit(JLEvent event) {
2830
sink.emit(new JLEvent(EventKind.click, "Button", new HashMap<>(meta)));
2931
Assert.assertTrue(captured.size() == before + 1);
3032
}
33+
34+
@Test
35+
public void metadata_serializes_as_string() throws Exception {
36+
final ObjectMapper mapper = new ObjectMapper();
37+
final JLEvent event = new JLEvent(1234567890L, EventKind.click, "Button", "meta-string");
38+
final JsonNode node = mapper.readTree(mapper.writeValueAsString(event));
39+
Assert.assertEquals("meta-string", node.get("m").asText());
40+
}
41+
42+
@Test
43+
public void metadata_serializes_as_object() throws Exception {
44+
final ObjectMapper mapper = new ObjectMapper();
45+
final Map<String, Object> meta = new HashMap<>();
46+
meta.put("id", "submit-btn");
47+
final JLEvent event = new JLEvent(1234567890L, EventKind.click, "Button", meta);
48+
final JsonNode node = mapper.readTree(mapper.writeValueAsString(event));
49+
Assert.assertEquals("submit-btn", node.get("m").get("id").asText());
50+
}
3151
}
3252

0 commit comments

Comments
 (0)