Skip to content

Commit 5405a2b

Browse files
authored
Introduce event tags to track API (#83)
1 parent eeb820c commit 5405a2b

File tree

107 files changed

+564
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+564
-451
lines changed

core-api/src/jmh/java/com/optimizely/ab/BenchmarkUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBuilderBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -38,7 +38,9 @@
3838
import com.optimizely.ab.event.internal.EventBuilderV1;
3939
import com.optimizely.ab.event.internal.EventBuilderV2;
4040
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
41+
import com.optimizely.ab.internal.EventTagUtils;
4142
import com.optimizely.ab.internal.ProjectValidationUtils;
43+
import com.optimizely.ab.internal.ReservedEventKey;
4244
import com.optimizely.ab.notification.NotificationListener;
4345
import com.optimizely.ab.notification.NotificationBroadcaster;
4446

@@ -117,22 +119,9 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
117119
return activate(experimentKey, userId, Collections.<String, String>emptyMap());
118120
}
119121

120-
public @Nullable Variation activate(@Nonnull String experimentKey,
121-
@Nonnull String userId,
122-
@CheckForNull String sessionId) throws UnknownExperimentException {
123-
return activate(experimentKey, userId, Collections.<String, String>emptyMap(), sessionId);
124-
}
125-
126122
public @Nullable Variation activate(@Nonnull String experimentKey,
127123
@Nonnull String userId,
128124
@Nonnull Map<String, String> attributes) throws UnknownExperimentException {
129-
return activate(experimentKey, userId, attributes, null);
130-
}
131-
132-
public @Nullable Variation activate(@Nonnull String experimentKey,
133-
@Nonnull String userId,
134-
@Nonnull Map<String, String> attributes,
135-
@CheckForNull String sessionId) throws UnknownExperimentException {
136125

137126
if (!validateUserId(userId)) {
138127
logger.info("Not activating user for experiment \"{}\".", experimentKey);
@@ -148,42 +137,27 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
148137
return null;
149138
}
150139

151-
return activate(currentConfig, experiment, userId, attributes, sessionId);
140+
return activate(currentConfig, experiment, userId, attributes);
152141
}
153142

154143
public @Nullable Variation activate(@Nonnull Experiment experiment,
155144
@Nonnull String userId) {
156145
return activate(experiment, userId, Collections.<String, String>emptyMap());
157146
}
158147

159-
public @Nullable Variation activate(@Nonnull Experiment experiment,
160-
@Nonnull String userId,
161-
@CheckForNull String sessionId) {
162-
return activate(experiment, userId, Collections.<String, String>emptyMap(), sessionId);
163-
}
164-
165148
public @Nullable Variation activate(@Nonnull Experiment experiment,
166149
@Nonnull String userId,
167150
@Nonnull Map<String, String> attributes) {
168151

169-
return activate(experiment, userId, attributes, null);
170-
}
171-
172-
public @Nullable Variation activate(@Nonnull Experiment experiment,
173-
@Nonnull String userId,
174-
@Nonnull Map<String, String> attributes,
175-
@CheckForNull String sessionId) {
176-
177152
ProjectConfig currentConfig = getProjectConfig();
178153

179-
return activate(currentConfig, experiment, userId, attributes, sessionId);
154+
return activate(currentConfig, experiment, userId, attributes);
180155
}
181156

182157
private @Nullable Variation activate(@Nonnull ProjectConfig projectConfig,
183158
@Nonnull Experiment experiment,
184159
@Nonnull String userId,
185-
@Nonnull Map<String, String> attributes,
186-
@CheckForNull String sessionId) {
160+
@Nonnull Map<String, String> attributes) {
187161
// determine whether all the given attributes are present in the project config. If not, filter out the unknown
188162
// attributes.
189163
attributes = filterAttributes(projectConfig, attributes);
@@ -202,7 +176,7 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
202176

203177
if (experiment.isRunning()) {
204178
LogEvent impressionEvent = eventBuilder.createImpressionEvent(projectConfig, experiment, variation, userId,
205-
attributes, sessionId);
179+
attributes);
206180
logger.info("Activating user \"{}\" in experiment \"{}\".", userId, experiment.getKey());
207181
logger.debug(
208182
"Dispatching impression event to URL {} with params {} and payload \"{}\".",
@@ -225,61 +199,39 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
225199

226200
public void track(@Nonnull String eventName,
227201
@Nonnull String userId) throws UnknownEventTypeException {
228-
track(eventName, userId, Collections.<String, String>emptyMap(), null, null);
229-
}
230-
231-
public void track(@Nonnull String eventName,
232-
@Nonnull String userId,
233-
@CheckForNull String sessionId) throws UnknownEventTypeException {
234-
track(eventName, userId, Collections.<String, String>emptyMap(), null, sessionId);
202+
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
235203
}
236204

237205
public void track(@Nonnull String eventName,
238206
@Nonnull String userId,
239207
@Nonnull Map<String, String> attributes) throws UnknownEventTypeException {
240-
track(eventName, userId, attributes, null, null);
241-
}
242-
243-
public void track(@Nonnull String eventName,
244-
@Nonnull String userId,
245-
@Nonnull Map<String, String> attributes,
246-
@CheckForNull String sessionId) throws UnknownEventTypeException {
247-
track(eventName, userId, attributes, null, sessionId);
208+
track(eventName, userId, attributes, Collections.<String, String>emptyMap());
248209
}
249210

211+
/**
212+
* @deprecated see {@link #track(String, String, Map)} and pass in the revenue value as an event tag instead.
213+
*/
250214
public void track(@Nonnull String eventName,
251215
@Nonnull String userId,
252216
long eventValue) throws UnknownEventTypeException {
253-
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue);
254-
}
255-
256-
public void track(@Nonnull String eventName,
257-
@Nonnull String userId,
258-
long eventValue,
259-
@CheckForNull String sessionId) throws UnknownEventTypeException {
260-
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue, sessionId);
217+
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.singletonMap(
218+
ReservedEventKey.REVENUE.toString(), eventValue));
261219
}
262220

221+
/**
222+
* @deprecated see {@link #track(String, String, Map, long)} and pass in the revenue value as an event tag instead.
223+
*/
263224
public void track(@Nonnull String eventName,
264225
@Nonnull String userId,
265226
@Nonnull Map<String, String> attributes,
266227
long eventValue) throws UnknownEventTypeException {
267-
track(eventName, userId, attributes, (Long)eventValue, null);
228+
track(eventName, userId, attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
268229
}
269230

270231
public void track(@Nonnull String eventName,
271-
@Nonnull String userId,
272-
@Nonnull Map<String, String> attributes,
273-
long eventValue,
274-
@CheckForNull String sessionId) throws UnknownEventTypeException {
275-
track(eventName, userId, attributes, (Long)eventValue, sessionId);
276-
}
277-
278-
private void track(@Nonnull String eventName,
279232
@Nonnull String userId,
280233
@Nonnull Map<String, String> attributes,
281-
@CheckForNull Long eventValue,
282-
@CheckForNull String sessionId) throws UnknownEventTypeException {
234+
@Nonnull Map<String, ?> eventTags) throws UnknownEventTypeException {
283235

284236
ProjectConfig currentConfig = getProjectConfig();
285237

@@ -294,10 +246,18 @@ private void track(@Nonnull String eventName,
294246
// attributes.
295247
attributes = filterAttributes(currentConfig, attributes);
296248

249+
Long eventValue = null;
250+
if (eventTags == null) {
251+
logger.warn("Event tags is null when non-null was expected. Defaulting to an empty event tags map.");
252+
eventTags = Collections.<String, String>emptyMap();
253+
} else {
254+
eventValue = EventTagUtils.getRevenueValue(eventTags);
255+
}
256+
297257
// create the conversion event request parameters, then dispatch
298258
LogEvent conversionEvent = eventBuilder.createConversionEvent(currentConfig, bucketer, userId,
299259
eventType.getId(), eventType.getKey(), attributes,
300-
eventValue, sessionId);
260+
eventTags);
301261

302262
if (conversionEvent == null) {
303263
logger.info("There are no valid experiments for event \"{}\" to track.", eventName);

core-api/src/main/java/com/optimizely/ab/OptimizelyRuntimeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/UnknownEventTypeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/UnknownExperimentException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/UnknownLiveVariableException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/annotations/VisibleForTesting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/bucketing/Bucketer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/bucketing/UserProfile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/bucketing/internal/MurmurHash3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Attribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/EventType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Experiment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Group.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/IdKeyMapped.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/IdMapped.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/LiveVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/LiveVariableUsageInstance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/ProjectConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/ProjectConfigUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/TrafficAllocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Variation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/audience/AndCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/audience/Audience.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/audience/Condition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)