@rk911/tracker-sdk 1.7.10 → 1.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/session.js +2 -5
- package/native/android/AndroidTracker.java +54 -3
- package/package.json +1 -1
- package/platforms/web.js +6 -0
package/core/session.js
CHANGED
|
@@ -61,10 +61,6 @@ export class SessionManager {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
setUser(userId, isNative = false) {
|
|
64
|
-
if (!userId && this.userId && !isNative) {
|
|
65
|
-
// 防误置空:外部未准备好用户身份传空时,若内存中已有合法 userId,绝不置空;清空需调用 resetSession
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
64
|
this.userId = userId || null
|
|
69
65
|
this.isNativeUserId = !!isNative
|
|
70
66
|
if (userId) {
|
|
@@ -72,7 +68,7 @@ export class SessionManager {
|
|
|
72
68
|
if (!isNative) {
|
|
73
69
|
this.adapter.setStorage('userId', userId)
|
|
74
70
|
}
|
|
75
|
-
} else if (!userId
|
|
71
|
+
} else if (!userId) {
|
|
76
72
|
this.adapter.removeStorage('userId')
|
|
77
73
|
this.adapter.removeStorage('_tracker_user_id')
|
|
78
74
|
}
|
|
@@ -169,6 +165,7 @@ export class SessionManager {
|
|
|
169
165
|
resetSession() {
|
|
170
166
|
this.adapter.removeSessionStorage(this._storageKey)
|
|
171
167
|
this.adapter.removeStorage('_tracker_user_id')
|
|
168
|
+
this.adapter.removeStorage('userId')
|
|
172
169
|
this.userId = null
|
|
173
170
|
this.isNativeUserId = false
|
|
174
171
|
this.isNativeSessionId = false
|
|
@@ -245,6 +245,18 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
245
245
|
return deviceId;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
public String getUserId() {
|
|
249
|
+
return userId != null ? userId : "";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public String getPhone() {
|
|
253
|
+
return phone != null ? phone : "";
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public String getStoreName() {
|
|
257
|
+
return storeName != null ? storeName : "";
|
|
258
|
+
}
|
|
259
|
+
|
|
248
260
|
public void setUserId(String userId) {
|
|
249
261
|
updateUser(userId, null, null);
|
|
250
262
|
}
|
|
@@ -365,6 +377,27 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
365
377
|
});
|
|
366
378
|
}
|
|
367
379
|
|
|
380
|
+
public void trackCustom(final String eventName, final String elementText, final JSONObject customProperties) {
|
|
381
|
+
postBgTask(new Runnable() {
|
|
382
|
+
@Override
|
|
383
|
+
public void run() {
|
|
384
|
+
try {
|
|
385
|
+
JSONObject event = createBaseEvent("custom", eventName);
|
|
386
|
+
if (!TextUtils.isEmpty(elementText)) {
|
|
387
|
+
event.put("elementText", elementText);
|
|
388
|
+
}
|
|
389
|
+
if (customProperties != null) {
|
|
390
|
+
event.put("extraData", customProperties.toString());
|
|
391
|
+
}
|
|
392
|
+
enqueueEvent(event);
|
|
393
|
+
flushAsync();
|
|
394
|
+
} catch (Exception e) {
|
|
395
|
+
Log.e(TAG, "===> [Native Tracker trackCustom Failed]", e);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
368
401
|
public void track(final String eventName, final JSONObject customProperties) {
|
|
369
402
|
postBgTask(new Runnable() {
|
|
370
403
|
@Override
|
|
@@ -520,6 +553,10 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
520
553
|
event.put("eventName", eventName);
|
|
521
554
|
event.put("timestamp", System.currentTimeMillis());
|
|
522
555
|
event.put("sequence", sequence);
|
|
556
|
+
event.put("sessionId", sessionId);
|
|
557
|
+
if (!TextUtils.isEmpty(userId)) {
|
|
558
|
+
event.put("userId", userId);
|
|
559
|
+
}
|
|
523
560
|
event.put("pageRoute", currentPageRoute);
|
|
524
561
|
String autoTitle = getFriendlyPageTitle(currentPageRoute);
|
|
525
562
|
if (!TextUtils.isEmpty(autoTitle)) {
|
|
@@ -657,9 +694,23 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
657
694
|
try {
|
|
658
695
|
JSONObject body = new JSONObject();
|
|
659
696
|
body.put("appId", Integer.parseInt(appId));
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
697
|
+
|
|
698
|
+
// 批次级别会话与用户身份防护:优先取首条事件自身的 sessionId 与 userId,防切换账号后历史批次被新身份篡改
|
|
699
|
+
String batchSessionId = sessionId;
|
|
700
|
+
String batchUserId = userId != null ? userId : "";
|
|
701
|
+
if (!records.isEmpty()) {
|
|
702
|
+
JSONObject firstEvt = records.get(0).json;
|
|
703
|
+
if (firstEvt.has("sessionId") && !TextUtils.isEmpty(firstEvt.optString("sessionId"))) {
|
|
704
|
+
batchSessionId = firstEvt.optString("sessionId");
|
|
705
|
+
}
|
|
706
|
+
if (firstEvt.has("userId") && !TextUtils.isEmpty(firstEvt.optString("userId"))) {
|
|
707
|
+
batchUserId = firstEvt.optString("userId");
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
body.put("sessionId", batchSessionId);
|
|
712
|
+
body.put("deviceId", deviceId != null ? deviceId : "");
|
|
713
|
+
body.put("userId", batchUserId);
|
|
663
714
|
body.put("phone", phone != null ? phone : "");
|
|
664
715
|
body.put("storeName", storeName != null ? storeName : "");
|
|
665
716
|
body.put("platform", "android");
|
package/package.json
CHANGED
package/platforms/web.js
CHANGED
|
@@ -26,6 +26,12 @@ export const ROUTE_TITLE_MAP = {
|
|
|
26
26
|
'/pages/integralMall/integralGoodsInfo': '积分商品详情',
|
|
27
27
|
'/pages/my/setting/setting': '设置',
|
|
28
28
|
'/pages/selfInvoice/index': '自助开票',
|
|
29
|
+
'/pages/circle/userHome/userHome': '个人主页',
|
|
30
|
+
'/pages/circle/rank': '圈子排行榜',
|
|
31
|
+
'/pages/pickup/list': '自提订单',
|
|
32
|
+
'/pages/mall/order/index': '我的订单',
|
|
33
|
+
'/pages/my/userInfo': '个人资料',
|
|
34
|
+
'/live/index/log': '直播记录',
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export class WebAdapter {
|