@@ -117,9 +117,22 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
117117 return activate (experimentKey , userId , Collections .<String , String >emptyMap ());
118118 }
119119
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+
120126 public @ Nullable Variation activate (@ Nonnull String experimentKey ,
121127 @ Nonnull String userId ,
122128 @ 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 {
123136
124137 if (!validateUserId (userId )) {
125138 logger .info ("Not activating user for experiment \" {}\" ." , experimentKey );
@@ -135,27 +148,42 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
135148 return null ;
136149 }
137150
138- return activate (currentConfig , experiment , userId , attributes );
151+ return activate (currentConfig , experiment , userId , attributes , sessionId );
139152 }
140153
141154 public @ Nullable Variation activate (@ Nonnull Experiment experiment ,
142155 @ Nonnull String userId ) {
143156 return activate (experiment , userId , Collections .<String , String >emptyMap ());
144157 }
145158
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+
146165 public @ Nullable Variation activate (@ Nonnull Experiment experiment ,
147166 @ Nonnull String userId ,
148167 @ Nonnull Map <String , String > attributes ) {
149168
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+
150177 ProjectConfig currentConfig = getProjectConfig ();
151178
152- return activate (currentConfig , experiment , userId , attributes );
179+ return activate (currentConfig , experiment , userId , attributes , sessionId );
153180 }
154181
155182 private @ Nullable Variation activate (@ Nonnull ProjectConfig projectConfig ,
156183 @ Nonnull Experiment experiment ,
157184 @ Nonnull String userId ,
158- @ Nonnull Map <String , String > attributes ) {
185+ @ Nonnull Map <String , String > attributes ,
186+ @ CheckForNull String sessionId ) {
159187 // determine whether all the given attributes are present in the project config. If not, filter out the unknown
160188 // attributes.
161189 attributes = filterAttributes (projectConfig , attributes );
@@ -173,8 +201,8 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
173201 }
174202
175203 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 );
178206 logger .info ("Activating user \" {}\" in experiment \" {}\" ." , userId , experiment .getKey ());
179207 logger .debug (
180208 "Dispatching impression event to URL {} with params {} and payload \" {}\" ." ,
@@ -197,13 +225,26 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
197225
198226 public void track (@ Nonnull String eventName ,
199227 @ 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 );
201235 }
202236
203237 public void track (@ Nonnull String eventName ,
204238 @ Nonnull String userId ,
205239 @ 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 );
207248 }
208249
209250 public void track (@ Nonnull String eventName ,
@@ -212,17 +253,33 @@ public void track(@Nonnull String eventName,
212253 track (eventName , userId , Collections .<String , String >emptyMap (), eventValue );
213254 }
214255
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+
215263 public void track (@ Nonnull String eventName ,
216264 @ Nonnull String userId ,
217265 @ Nonnull Map <String , String > attributes ,
218266 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 );
220276 }
221277
222278 private void track (@ Nonnull String eventName ,
223279 @ Nonnull String userId ,
224280 @ Nonnull Map <String , String > attributes ,
225- @ CheckForNull Long eventValue ) throws UnknownEventTypeException {
281+ @ CheckForNull Long eventValue ,
282+ @ CheckForNull String sessionId ) throws UnknownEventTypeException {
226283
227284 ProjectConfig currentConfig = getProjectConfig ();
228285
@@ -238,16 +295,9 @@ private void track(@Nonnull String eventName,
238295 attributes = filterAttributes (currentConfig , attributes );
239296
240297 // 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 );
251301
252302 if (conversionEvent == null ) {
253303 logger .info ("There are no valid experiments for event \" {}\" to track." , eventName );
@@ -265,7 +315,7 @@ private void track(@Nonnull String eventName,
265315 }
266316
267317 notificationBroadcaster .broadcastEventTracked (eventName , userId , attributes , eventValue ,
268- conversionEvent );
318+ conversionEvent );
269319 }
270320
271321 //======== live variable getters ========//
0 commit comments