diff --git a/launchdarkly-android-client-sdk/src/androidTest/java/com/launchdarkly/android/EventTest.java b/launchdarkly-android-client-sdk/src/androidTest/java/com/launchdarkly/android/EventTest.java index a04d6342..bfe4e2d3 100644 --- a/launchdarkly-android-client-sdk/src/androidTest/java/com/launchdarkly/android/EventTest.java +++ b/launchdarkly-android-client-sdk/src/androidTest/java/com/launchdarkly/android/EventTest.java @@ -233,7 +233,7 @@ public void testUserObjectRemovedFromCustomEvent() { LDUser user = builder.build(); - final CustomEvent event = new CustomEvent("key1", user.getKey(), null); + final CustomEvent event = new CustomEvent("key1", user.getKey(), null, null); assertNull(event.user); assertEquals(user.getKey(), event.userKey); @@ -246,7 +246,7 @@ public void testFullUserObjectIncludedInCustomEvent() { LDUser user = builder.build(); - final CustomEvent event = new CustomEvent("key1", user, null); + final CustomEvent event = new CustomEvent("key1", user, null, null); assertEquals(user, event.user); assertNull(event.userKey); diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/Event.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/Event.java index 502bb31d..43f2b8a2 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/Event.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/Event.java @@ -48,16 +48,20 @@ class IdentifyEvent extends GenericEvent { class CustomEvent extends GenericEvent { @Expose private final JsonElement data; + @Expose + private final Double metricValue; - CustomEvent(String key, LDUser user, JsonElement data) { + CustomEvent(String key, LDUser user, JsonElement data, Double metricValue) { super("custom", key, user); this.data = data; + this.metricValue = metricValue; } - CustomEvent(String key, String userKey, JsonElement data) { + CustomEvent(String key, String userKey, JsonElement data, Double metricValue) { super("custom", key, null); this.data = data; this.userKey = userKey; + this.metricValue = metricValue; } } diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClient.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClient.java index b43b16ca..14c2a00f 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClient.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClient.java @@ -224,14 +224,19 @@ protected LDClient(final Application application, @NonNull final LDConfig config } @Override - public void track(String eventName, JsonElement data) { + public void track(String eventName, JsonElement data, Double metricValue) { if (config.inlineUsersInEvents()) { - sendEvent(new CustomEvent(eventName, userManager.getCurrentUser(), data)); + sendEvent(new CustomEvent(eventName, userManager.getCurrentUser(), data, metricValue)); } else { - sendEvent(new CustomEvent(eventName, userManager.getCurrentUser().getKey(), data)); + sendEvent(new CustomEvent(eventName, userManager.getCurrentUser().getKey(), data, metricValue)); } } + @Override + public void track(String eventName, JsonElement data) { + track(eventName, data, null); + } + @Override public void track(String eventName) { track(eventName, null); diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClientInterface.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClientInterface.java index 537668fa..5a12ae85 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClientInterface.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/LDClientInterface.java @@ -54,6 +54,18 @@ public interface LDClientInterface extends Closeable { */ void setOnline(); + /** + * Tracks that a user performed an event. + * + * @param eventName the name of the event + * @param data a JSON object containing additional data associated with the event + * @param metricValue A numeric value used by the LaunchDarkly experimentation feature in + * numeric custom metrics. Can be omitted if this event is used by only + * non-numeric metrics. This field will also be returned as part of the + * custom event for Data Export. (Optional) + */ + void track(String eventName, JsonElement data, Double metricValue); + /** * Tracks that a user performed an event. *