Skip to content

Commit d4ecef8

Browse files
authored
feature: add set methods for person properties (#1)
1 parent 1374c2c commit d4ecef8

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

src/main/java/net/hollowcube/posthog/PostHog.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,52 @@ public static void identify(@NotNull String distinctId, @Nullable Object propert
119119
getClient().identify(distinctId, properties);
120120
}
121121

122+
/**
123+
* Set the given properties with the person profile of the user (distinct id).
124+
*
125+
* @param distinctId Unique ID of the target in your database. May not be empty.
126+
* @param properties Properties to set (including overwriting previous values) on the person profile
127+
* @param propertiesSetOnce Properties to set only if missing on the person profile
128+
*/
129+
public static void set(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) {
130+
getClient().set(distinctId, properties, propertiesSetOnce);
131+
}
132+
133+
/**
134+
* Set the given properties with the person profile of the user (distinct id).
135+
*
136+
* <p>The objects must be serializable to a JSON object via Gson (not primitive or array)</p>
137+
*
138+
* @param distinctId Unique ID of the target in your database. May not be empty.
139+
* @param properties Properties to set (including overwriting previous values) on the person profile
140+
* @param propertiesSetOnce Properties to set only if missing on the person profile
141+
*/
142+
public static void set(@NotNull String distinctId, @Nullable Object properties, @Nullable Object propertiesSetOnce) {
143+
getClient().set(distinctId, properties, propertiesSetOnce);
144+
}
145+
146+
/**
147+
* Set the given properties with the person profile of the user (distinct id).
148+
*
149+
* @param distinctId Unique ID of the target in your database. May not be empty.
150+
* @param properties Properties to set (including overwriting previous values) on the person profile
151+
*/
152+
public static void set(@NotNull String distinctId, @Nullable Map<String, Object> properties) {
153+
getClient().set(distinctId, properties);
154+
}
155+
156+
/**
157+
* Set the given properties with the person profile of the user (distinct id).
158+
*
159+
* <p>The object must be serializable to a JSON object via Gson (not primitive or array)</p>
160+
*
161+
* @param distinctId Unique ID of the target in your database. May not be empty.
162+
* @param properties Properties to set (including overwriting previous values) on the person profile
163+
*/
164+
public static void set(@NotNull String distinctId, @Nullable Object properties) {
165+
getClient().set(distinctId, properties);
166+
}
167+
122168
/**
123169
* Alias the given distinct ID to the given alias.
124170
*

src/main/java/net/hollowcube/posthog/PostHogClient.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,62 @@ default void identify(@NotNull String distinctId, @Nullable Object properties) {
130130
capture(distinctId, IDENTIFY, eventProps);
131131
}
132132

133+
/**
134+
* Set the given properties with the person profile of the user (distinct id).
135+
*
136+
* @param distinctId Unique ID of the target in your database. May not be empty.
137+
* @param properties Properties to set (including overwriting previous values) on the person profile
138+
* @param propertiesSetOnce Properties to set only if missing on the person profile
139+
*/
140+
default void set(@NotNull String distinctId, @Nullable Map<String, Object> properties, @Nullable Map<String, Object> propertiesSetOnce) {
141+
Map<String, Object> eventProps = new HashMap<>();
142+
if (properties != null) eventProps.put(SET, properties);
143+
if (propertiesSetOnce != null) eventProps.put(SET_ONCE, propertiesSetOnce);
144+
capture(distinctId, SET, eventProps);
145+
}
146+
147+
/**
148+
* Set the given properties with the person profile of the user (distinct id).
149+
*
150+
* <p>The objects must be serializable to a JSON object via Gson (not primitive or array)</p>
151+
*
152+
* @param distinctId Unique ID of the target in your database. May not be empty.
153+
* @param properties Properties to set (including overwriting previous values) on the person profile
154+
* @param propertiesSetOnce Properties to set only if missing on the person profile
155+
*/
156+
default void set(@NotNull String distinctId, @Nullable Object properties, @Nullable Object propertiesSetOnce) {
157+
Map<String, Object> eventProps = new HashMap<>();
158+
if (properties != null) eventProps.put(SET, properties);
159+
if (propertiesSetOnce != null) eventProps.put(SET_ONCE, propertiesSetOnce);
160+
capture(distinctId, SET, eventProps);
161+
}
162+
163+
/**
164+
* Set the given properties with the person profile of the user (distinct id).
165+
*
166+
* @param distinctId Unique ID of the target in your database. May not be empty.
167+
* @param properties Properties to set (including overwriting previous values) on the person profile
168+
*/
169+
default void set(@NotNull String distinctId, @Nullable Map<String, Object> properties) {
170+
Map<String, Object> eventProps = new HashMap<>();
171+
if (properties != null) eventProps.put(SET, properties);
172+
capture(distinctId, SET, eventProps);
173+
}
174+
175+
/**
176+
* Set the given properties with the person profile of the user (distinct id).
177+
*
178+
* <p>The object must be serializable to a JSON object via Gson (not primitive or array)</p>
179+
*
180+
* @param distinctId Unique ID of the target in your database. May not be empty.
181+
* @param properties Properties to set (including overwriting previous values) on the person profile
182+
*/
183+
default void set(@NotNull String distinctId, @Nullable Object properties) {
184+
Map<String, Object> eventProps = new HashMap<>();
185+
if (properties != null) eventProps.put(SET, properties);
186+
capture(distinctId, SET, eventProps);
187+
}
188+
133189
/**
134190
* Alias the given distinct ID to the given alias.
135191
*

0 commit comments

Comments
 (0)