@@ -150,7 +150,7 @@ public static IterableApi sharedInstanceWithApiKeyWithUserId(Context currentCont
150
150
{
151
151
return sharedInstanceWithApiKey (currentContext , apiKey , null , userId , debugMode );
152
152
}
153
-
153
+
154
154
/**
155
155
* Returns a shared instance of IterableApi. Updates the client data if an instance already exists.
156
156
* Should be called whenever the app is opened.
@@ -281,7 +281,7 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
281
281
if (_email != null ) {
282
282
requestJSON .put (IterableConstants .KEY_EMAIL , _email );
283
283
} else {
284
-
284
+ requestJSON . put ( IterableConstants . KEY_USER_ID , _userId );
285
285
}
286
286
requestJSON .put (IterableConstants .KEY_EVENTNAME , eventName );
287
287
@@ -297,8 +297,8 @@ public void track(String eventName, String campaignId, String templateId, JSONOb
297
297
}
298
298
299
299
public void sendPush (String email , int campaignId ) {
300
- sendPush (email , campaignId , null , null );
301
- }
300
+ sendPush (email , campaignId , null , null );
301
+ }
302
302
303
303
/**
304
304
* Sends a push campaign to an email address at the given time.
@@ -354,7 +354,12 @@ public void updateEmail(String newEmail) {
354
354
355
355
sendRequest (IterableConstants .ENDPOINT_UPDATEEMAIL , requestJSON );
356
356
357
- _email = newEmail ;
357
+ if (_email != null ) {
358
+ _email = newEmail ;
359
+ } else {
360
+ IterableLogger .w (TAG , "updateEmail should not be called with a userId. " +
361
+ "Init SDK with sharedInstanceWithApiKey instead of sharedInstanceWithApiKeyWithUserId" );
362
+ }
358
363
}
359
364
360
365
public void updateUser (JSONObject dataFields ) {
@@ -363,6 +368,8 @@ public void updateUser(JSONObject dataFields) {
363
368
try {
364
369
if (_email != null ) {
365
370
requestJSON .put (IterableConstants .KEY_EMAIL , _email );
371
+ } else {
372
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
366
373
}
367
374
368
375
requestJSON .put (IterableConstants .KEY_DATAFIELDS , dataFields );
@@ -418,7 +425,11 @@ protected void trackPushOpen(int campaignId, int templateId, String messageId) {
418
425
JSONObject requestJSON = new JSONObject ();
419
426
420
427
try {
421
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
428
+ if (_email != null ) {
429
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
430
+ } else {
431
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
432
+ }
422
433
requestJSON .put (IterableConstants .KEY_CAMPAIGNID , campaignId );
423
434
requestJSON .put (IterableConstants .KEY_TEMPLATE_ID , templateId );
424
435
requestJSON .put (IterableConstants .KEY_MESSAGE_ID , messageId );
@@ -438,7 +449,11 @@ protected void disablePush(String token) {
438
449
JSONObject requestJSON = new JSONObject ();
439
450
try {
440
451
requestJSON .put (IterableConstants .KEY_TOKEN , token );
441
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
452
+ if (_email != null ) {
453
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
454
+ } else {
455
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
456
+ }
442
457
}
443
458
catch (JSONException e ) {
444
459
e .printStackTrace ();
@@ -480,7 +495,12 @@ private void registerDeviceToken(String applicationName, String token, JSONObjec
480
495
481
496
JSONObject requestJSON = new JSONObject ();
482
497
try {
483
- requestJSON .put (IterableConstants .KEY_EMAIL , _email );
498
+ if (_email != null ) {
499
+ requestJSON .put (IterableConstants .KEY_EMAIL , _email );
500
+ } else {
501
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
502
+ }
503
+
484
504
if (dataFields == null ) {
485
505
dataFields = new JSONObject ();
486
506
}
0 commit comments