@@ -1148,37 +1148,48 @@ UrlEncodedFormEntity getHttpEntry(final String data) throws IOException {
11481148 final boolean compressData ;
11491149 }
11501150
1151- private void addEvent (String distinctId , boolean isLoginId , String originDistinceId ,
1151+ private void addEvent (String distinctId , boolean isLoginId , String originDistinctId ,
11521152 String actionType , String eventName , Map <String , Object > properties )
11531153 throws InvalidArgumentException {
11541154 assertKey ("Distinct Id" , distinctId );
11551155 assertProperties (actionType , properties );
11561156 if (actionType .equals ("track" )) {
11571157 assertKeyWithRegex ("Event Name" , eventName );
11581158 } else if (actionType .equals ("track_signup" )) {
1159- assertKey ("Original Distinct Id" , originDistinceId );
1159+ assertKey ("Original Distinct Id" , originDistinctId );
11601160 }
11611161
11621162 // Event time
11631163 long time = System .currentTimeMillis ();
1164- if (properties != null && properties .containsKey ("$time" )) {
1165- Date eventTime = (Date ) properties .get ("$time" );
1166- properties .remove ("$time" );
1164+ Map <String , Object > newProperties = null ;
1165+ if (properties != null ) {
1166+ newProperties = new HashMap <String , Object >(properties );
1167+ }
1168+ if (newProperties != null && newProperties .containsKey ("$time" )) {
1169+ Date eventTime = (Date ) newProperties .get ("$time" );
1170+ newProperties .remove ("$time" );
11671171 time = eventTime .getTime ();
11681172 }
11691173
11701174 String eventProject = null ;
1171- if (properties != null && properties .containsKey ("$project" )) {
1172- eventProject = (String ) properties .get ("$project" );
1173- properties .remove ("$project" );
1175+ String eventToken = null ;
1176+ if (newProperties != null ) {
1177+ if (newProperties .containsKey ("$project" )) {
1178+ eventProject = (String ) newProperties .get ("$project" );
1179+ newProperties .remove ("$project" );
1180+ }
1181+ if (newProperties .containsKey ("$token" )) {
1182+ eventToken = (String ) newProperties .get ("$token" );
1183+ newProperties .remove ("$token" );
1184+ }
11741185 }
11751186
11761187 Map <String , Object > eventProperties = new HashMap <String , Object >();
11771188 if (actionType .equals ("track" ) || actionType .equals ("track_signup" )) {
11781189 eventProperties .putAll (superProperties );
11791190 }
1180- if (properties != null ) {
1181- eventProperties .putAll (properties );
1191+ if (newProperties != null ) {
1192+ eventProperties .putAll (newProperties );
11821193 }
11831194
11841195 if (isLoginId ) {
@@ -1200,6 +1211,10 @@ private void addEvent(String distinctId, boolean isLoginId, String originDistinc
12001211 event .put ("project" , eventProject );
12011212 }
12021213
1214+ if (eventToken != null ) {
1215+ event .put ("token" , eventToken );
1216+ }
1217+
12031218 if (enableTimeFree ) {
12041219 event .put ("time_free" , true );
12051220 }
@@ -1208,7 +1223,7 @@ private void addEvent(String distinctId, boolean isLoginId, String originDistinc
12081223 event .put ("event" , eventName );
12091224 } else if (actionType .equals ("track_signup" )) {
12101225 event .put ("event" , eventName );
1211- event .put ("original_id" , originDistinceId );
1226+ event .put ("original_id" , originDistinctId );
12121227 }
12131228
12141229 this .consumer .send (event );
@@ -1220,15 +1235,27 @@ private void addItem(String itemType, String itemId, String actionType,
12201235 assertKey ("Item Id" , itemId );
12211236 assertProperties (actionType , properties );
12221237
1238+ Map <String , Object > newProperties = null ;
1239+ if (properties != null ) {
1240+ newProperties = new HashMap <String , Object >(properties );
1241+ }
1242+
12231243 String eventProject = null ;
1224- if (properties != null && properties .containsKey ("$project" )) {
1225- eventProject = (String ) properties .get ("$project" );
1226- properties .remove ("$project" );
1244+ String eventToken = null ;
1245+ if (newProperties != null ) {
1246+ if (newProperties .containsKey ("$project" )) {
1247+ eventProject = (String ) newProperties .get ("$project" );
1248+ newProperties .remove ("$project" );
1249+ }
1250+ if (newProperties .containsKey ("$token" )) {
1251+ eventToken = (String ) newProperties .get ("$token" );
1252+ newProperties .remove ("$token" );
1253+ }
12271254 }
12281255
12291256 Map <String , Object > eventProperties = new HashMap <String , Object >();
1230- if (properties != null ) {
1231- eventProperties .putAll (properties );
1257+ if (newProperties != null ) {
1258+ eventProperties .putAll (newProperties );
12321259 }
12331260
12341261 Map <String , String > libProperties = getLibProperties ();
@@ -1243,6 +1270,10 @@ private void addItem(String itemType, String itemId, String actionType,
12431270 record .put ("project" , eventProject );
12441271 }
12451272
1273+ if (eventToken != null ) {
1274+ record .put ("token" , eventToken );
1275+ }
1276+
12461277 record .put ("item_type" , itemType );
12471278 record .put ("item_id" , itemId );
12481279 this .consumer .send (record );
@@ -1371,7 +1402,7 @@ private static ObjectMapper getJsonObjectMapper() {
13711402 return jsonObjectMapper ;
13721403 }
13731404
1374- private static final String SDK_VERSION = "3.1.16 " ;
1405+ private static final String SDK_VERSION = "3.1.17 " ;
13751406
13761407 private static final Pattern KEY_PATTERN = Pattern .compile (
13771408 "^((?!^distinct_id$|^original_id$|^time$|^properties$|^id$|^first_id$|^second_id$|^users$|^events$|^event$|^user_id$|^date$|^datetime$)[a-zA-Z_$][a-zA-Z\\ d_$]{0,99})$" ,
0 commit comments