diff --git a/src/main/java/com/launchdarkly/client/IdentifyEvent.java b/src/main/java/com/launchdarkly/client/IdentifyEvent.java new file mode 100644 index 000000000..b7e599b69 --- /dev/null +++ b/src/main/java/com/launchdarkly/client/IdentifyEvent.java @@ -0,0 +1,10 @@ +package com.launchdarkly.client; + +import com.google.gson.JsonObject; + +class IdentifyEvent extends Event { + + IdentifyEvent(LDUser user) { + super("identify", user.getKey(), user); + } +} diff --git a/src/main/java/com/launchdarkly/client/LDClient.java b/src/main/java/com/launchdarkly/client/LDClient.java index 703b2293a..2a00d2df9 100644 --- a/src/main/java/com/launchdarkly/client/LDClient.java +++ b/src/main/java/com/launchdarkly/client/LDClient.java @@ -104,7 +104,7 @@ protected CloseableHttpClient createClient() { * @param user the user that performed the event * @param data a JSON object containing additional data associated with the event */ - public void sendEvent(String eventName, LDUser user, JsonObject data) { + public void track(String eventName, LDUser user, JsonObject data) { boolean processed = eventProcessor.sendEvent(new CustomEvent(eventName, user, data)); if (!processed) { logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events."); @@ -117,11 +117,25 @@ public void sendEvent(String eventName, LDUser user, JsonObject data) { * @param eventName the name of the event * @param user the user that performed the event */ - public void sendEvent(String eventName, LDUser user) { + public void track(String eventName, LDUser user) { if (this.offline) { return; } - sendEvent(eventName, user, null); + track(eventName, user, null); + } + + /** + * Register the user + * @param user the user to register + */ + public void identify(LDUser user) { + if (this.offline) { + return; + } + boolean processed = eventProcessor.sendEvent(new IdentifyEvent(user)); + if (!processed) { + logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events."); + } } private void sendFlagRequestEvent(String featureKey, LDUser user, boolean value) { diff --git a/src/main/java/com/launchdarkly/client/LDUser.java b/src/main/java/com/launchdarkly/client/LDUser.java index f2c67c7ab..2c6c5eca5 100644 --- a/src/main/java/com/launchdarkly/client/LDUser.java +++ b/src/main/java/com/launchdarkly/client/LDUser.java @@ -27,6 +27,11 @@ public class LDUser { private String key; private String secondary; private String ip; + private String email; + private String gender; + private String firstName; + private String lastName; + private LDCountryCode country; private Map custom; private static final Logger logger = LoggerFactory.getLogger(LDUser.class); @@ -41,6 +46,10 @@ protected LDUser(Builder builder) { this.ip = builder.ip; this.country = builder.country; this.secondary = builder.secondary; + this.firstName = builder.firstName; + this.lastName = builder.lastName; + this.email = builder.email; + this.gender = builder.gender; this.custom = new HashMap(builder.custom); } @@ -63,6 +72,14 @@ String getKey() { String getSecondary() { return secondary; } + String getGender() { return gender; } + + String getFirstName() { return firstName; } + + String getLastName() { return lastName; } + + String getEmail() { return email; } + JsonElement getCustom(String key) { return custom.get(key); } @@ -84,6 +101,10 @@ public static class Builder { private String key; private String secondary; private String ip; + private String firstName; + private String lastName; + private String email; + private String gender; private LDCountryCode country; private Map custom; @@ -157,6 +178,26 @@ public Builder country(LDCountryCode country) { return this; } + public Builder firstName(String firstName) { + this.firstName = firstName; + return this; + } + + public Builder lastName(String lastName) { + this.lastName = lastName; + return this; + } + + public Builder gender(String gender) { + this.gender = gender; + return this; + } + + public Builder email(String email) { + this.email = email; + return this; + } + /** * Add a {@link java.lang.String}-valued custom attribute * @param k the key for the custom attribute