Skip to content

Commit 9d8d040

Browse files
author
任庆友
committed
Release 3.1.17
1 parent 4b6004b commit 9d8d040

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

SensorsAnalyticsSDK/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<groupId>com.sensorsdata.analytics.javasdk</groupId>
1616
<name>SensorsAnalyticsSDK</name>
1717
<artifactId>SensorsAnalyticsSDK</artifactId>
18-
<version>3.1.16</version>
18+
<version>3.1.17</version>
1919
<description>The official Java SDK of Sensors Analytics</description>
2020
<url>http://sensorsdata.cn</url>
2121

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/HelloSensorsAnalytics.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class HelloSensorsAnalytics {
99

1010
public static void main(String[] args) throws Exception {
1111
// Sensors Analytics 采集事件的 URL
12-
final String SA_SERVER_URL = "http://10.10.11.209:8006/sa?project=default&token=bbb";
12+
final String SA_SERVER_URL = "http://sdk-test.datasink.sensorsdata.cn/sa?project=renqingyou&token=95c73ae661f85aa0";
1313

1414
// DebugConsumer
1515
final SensorsAnalytics sa = new SensorsAnalytics(new SensorsAnalytics.DebugConsumer
@@ -40,6 +40,8 @@ public static void main(String[] args) throws Exception {
4040
properties.put("$os_version", "8.1"); // 操作系统的具体版本
4141
properties.put("$ip", "123.123.123.123"); // 请求中能够拿到用户的IP,则把这个传递给SA,SA会自动根据这个解析省份、城市
4242
properties.put("Channel", "baidu"); // 用户是通过baidu这个渠道过来的
43+
properties.put("$project","abc");
44+
properties.put("$token","123");
4345
sa.track(cookieId, false, "ViewHomePage", properties); // 记录访问首页这个event
4446

4547
// 1.2 搜索商品

SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/javasdk/SensorsAnalytics.java

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)