@@ -117,9 +117,22 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
117
117
return activate (experimentKey , userId , Collections .<String , String >emptyMap ());
118
118
}
119
119
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
+
120
126
public @ Nullable Variation activate (@ Nonnull String experimentKey ,
121
127
@ Nonnull String userId ,
122
128
@ 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 {
123
136
124
137
if (!validateUserId (userId )) {
125
138
logger .info ("Not activating user for experiment \" {}\" ." , experimentKey );
@@ -135,27 +148,42 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
135
148
return null ;
136
149
}
137
150
138
- return activate (currentConfig , experiment , userId , attributes );
151
+ return activate (currentConfig , experiment , userId , attributes , sessionId );
139
152
}
140
153
141
154
public @ Nullable Variation activate (@ Nonnull Experiment experiment ,
142
155
@ Nonnull String userId ) {
143
156
return activate (experiment , userId , Collections .<String , String >emptyMap ());
144
157
}
145
158
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
+
146
165
public @ Nullable Variation activate (@ Nonnull Experiment experiment ,
147
166
@ Nonnull String userId ,
148
167
@ Nonnull Map <String , String > attributes ) {
149
168
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
+
150
177
ProjectConfig currentConfig = getProjectConfig ();
151
178
152
- return activate (currentConfig , experiment , userId , attributes );
179
+ return activate (currentConfig , experiment , userId , attributes , sessionId );
153
180
}
154
181
155
182
private @ Nullable Variation activate (@ Nonnull ProjectConfig projectConfig ,
156
183
@ Nonnull Experiment experiment ,
157
184
@ Nonnull String userId ,
158
- @ Nonnull Map <String , String > attributes ) {
185
+ @ Nonnull Map <String , String > attributes ,
186
+ @ CheckForNull String sessionId ) {
159
187
// determine whether all the given attributes are present in the project config. If not, filter out the unknown
160
188
// attributes.
161
189
attributes = filterAttributes (projectConfig , attributes );
@@ -173,8 +201,8 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
173
201
}
174
202
175
203
if (experiment .isRunning ()) {
176
- LogEvent impressionEvent =
177
- eventBuilder . createImpressionEvent ( projectConfig , experiment , variation , userId , attributes );
204
+ LogEvent impressionEvent = eventBuilder . createImpressionEvent ( projectConfig , experiment , variation , userId ,
205
+ attributes , sessionId );
178
206
logger .info ("Activating user \" {}\" in experiment \" {}\" ." , userId , experiment .getKey ());
179
207
logger .debug (
180
208
"Dispatching impression event to URL {} with params {} and payload \" {}\" ." ,
@@ -197,13 +225,26 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
197
225
198
226
public void track (@ Nonnull String eventName ,
199
227
@ Nonnull String userId ) throws UnknownEventTypeException {
200
- track (eventName , userId , Collections .<String , String >emptyMap (), null );
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 );
201
235
}
202
236
203
237
public void track (@ Nonnull String eventName ,
204
238
@ Nonnull String userId ,
205
239
@ Nonnull Map <String , String > attributes ) throws UnknownEventTypeException {
206
- track (eventName , userId , attributes , null );
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 );
207
248
}
208
249
209
250
public void track (@ Nonnull String eventName ,
@@ -212,17 +253,33 @@ public void track(@Nonnull String eventName,
212
253
track (eventName , userId , Collections .<String , String >emptyMap (), eventValue );
213
254
}
214
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 );
261
+ }
262
+
215
263
public void track (@ Nonnull String eventName ,
216
264
@ Nonnull String userId ,
217
265
@ Nonnull Map <String , String > attributes ,
218
266
long eventValue ) throws UnknownEventTypeException {
219
- track (eventName , userId , attributes , (Long )eventValue );
267
+ track (eventName , userId , attributes , (Long )eventValue , null );
268
+ }
269
+
270
+ 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 );
220
276
}
221
277
222
278
private void track (@ Nonnull String eventName ,
223
279
@ Nonnull String userId ,
224
280
@ Nonnull Map <String , String > attributes ,
225
- @ CheckForNull Long eventValue ) throws UnknownEventTypeException {
281
+ @ CheckForNull Long eventValue ,
282
+ @ CheckForNull String sessionId ) throws UnknownEventTypeException {
226
283
227
284
ProjectConfig currentConfig = getProjectConfig ();
228
285
@@ -238,16 +295,9 @@ private void track(@Nonnull String eventName,
238
295
attributes = filterAttributes (currentConfig , attributes );
239
296
240
297
// create the conversion event request parameters, then dispatch
241
- LogEvent conversionEvent ;
242
- if (eventValue == null ) {
243
- conversionEvent = eventBuilder .createConversionEvent (currentConfig , bucketer , userId ,
244
- eventType .getId (), eventType .getKey (),
245
- attributes );
246
- } else {
247
- conversionEvent = eventBuilder .createConversionEvent (currentConfig , bucketer , userId ,
248
- eventType .getId (), eventType .getKey (), attributes ,
249
- eventValue );
250
- }
298
+ LogEvent conversionEvent = eventBuilder .createConversionEvent (currentConfig , bucketer , userId ,
299
+ eventType .getId (), eventType .getKey (), attributes ,
300
+ eventValue , sessionId );
251
301
252
302
if (conversionEvent == null ) {
253
303
logger .info ("There are no valid experiments for event \" {}\" to track." , eventName );
@@ -265,7 +315,7 @@ private void track(@Nonnull String eventName,
265
315
}
266
316
267
317
notificationBroadcaster .broadcastEventTracked (eventName , userId , attributes , eventValue ,
268
- conversionEvent );
318
+ conversionEvent );
269
319
}
270
320
271
321
//======== live variable getters ========//
0 commit comments