@rk911/tracker-sdk 1.7.14 → 1.7.16
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/tracker.js +24 -1
- package/index.js +1 -0
- package/native/android/AndroidTracker.java +74 -4
- package/package.json +1 -1
package/core/tracker.js
CHANGED
|
@@ -59,6 +59,15 @@ export class Tracker {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
setPflag(pflag, platformName) {
|
|
63
|
+
if (typeof pflag !== 'undefined' && pflag !== null && pflag !== '') {
|
|
64
|
+
this.config.pflag = pflag
|
|
65
|
+
}
|
|
66
|
+
if (platformName) {
|
|
67
|
+
this.config.platformName = platformName
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
// ---- 插件管理 ----
|
|
63
72
|
|
|
64
73
|
use(plugin) {
|
|
@@ -159,7 +168,21 @@ export class Tracker {
|
|
|
159
168
|
scrollDepth: eventData.scrollDepth || this._currentScrollDepth || null,
|
|
160
169
|
errorMessage: eventData.errorMessage || null,
|
|
161
170
|
errorStack: eventData.errorStack || null,
|
|
162
|
-
extraData:
|
|
171
|
+
extraData: (function (cfg, ex) {
|
|
172
|
+
var obj = ex
|
|
173
|
+
if (typeof obj === 'string') {
|
|
174
|
+
try { obj = JSON.parse(obj) } catch (e) { obj = { _raw: obj } }
|
|
175
|
+
} else if (!obj || typeof obj !== 'object') {
|
|
176
|
+
obj = {}
|
|
177
|
+
}
|
|
178
|
+
if (cfg.pflag !== '' && cfg.pflag !== undefined && obj.pflag === undefined) {
|
|
179
|
+
obj.pflag = cfg.pflag
|
|
180
|
+
}
|
|
181
|
+
if (cfg.platformName && obj.platformName === undefined) {
|
|
182
|
+
obj.platformName = cfg.platformName
|
|
183
|
+
}
|
|
184
|
+
return Object.keys(obj).length > 0 ? JSON.stringify(obj) : null
|
|
185
|
+
})(this.config, eventData.extraData),
|
|
163
186
|
extKey: eventData.extKey || null,
|
|
164
187
|
extValue: eventData.extValue || null,
|
|
165
188
|
extIntValue: eventData.extIntValue || null,
|
package/index.js
CHANGED
|
@@ -74,7 +74,10 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
74
74
|
private volatile String userId;
|
|
75
75
|
private volatile String phone;
|
|
76
76
|
private volatile String storeName;
|
|
77
|
+
private volatile String userName;
|
|
77
78
|
private volatile int sequence = 0;
|
|
79
|
+
private volatile int pflag = -1;
|
|
80
|
+
private volatile String platformName = "";
|
|
78
81
|
|
|
79
82
|
private HandlerThread bgThread;
|
|
80
83
|
private Handler bgHandler;
|
|
@@ -201,6 +204,7 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
201
204
|
this.userId = userId != null ? userId : "";
|
|
202
205
|
this.phone = phone != null ? phone : "";
|
|
203
206
|
this.storeName = storeName != null ? storeName : "";
|
|
207
|
+
this.userName = "";
|
|
204
208
|
this.sessionId = "android_" + System.currentTimeMillis() + "_" + (int) (Math.random() * 10000);
|
|
205
209
|
|
|
206
210
|
// 初始化 SQLite 本地持久化数据库 (S1 防丢保障)
|
|
@@ -231,10 +235,29 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
public void updateUser(String userId, String phone, String storeName) {
|
|
238
|
+
updateUser(userId, phone, storeName, null);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public void updateUser(String userId, String phone, String storeName, String userName) {
|
|
234
242
|
if (userId != null) this.userId = userId;
|
|
235
243
|
if (phone != null) this.phone = phone;
|
|
236
244
|
if (storeName != null) this.storeName = storeName;
|
|
237
|
-
|
|
245
|
+
if (userName != null) this.userName = userName;
|
|
246
|
+
Log.i(TAG, "===> [Native Tracker User Updated] UserId: " + this.userId + ", Phone: " + this.phone + ", Store: " + this.storeName + ", User: " + this.userName);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
public void setPlatform(int pflag, String platformName) {
|
|
250
|
+
this.pflag = pflag;
|
|
251
|
+
this.platformName = platformName != null ? platformName : "";
|
|
252
|
+
Log.i(TAG, "===> [Native Tracker Platform Updated] pflag: " + this.pflag + ", platformName: " + this.platformName);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public int getPflag() {
|
|
256
|
+
return pflag;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public String getPlatformName() {
|
|
260
|
+
return platformName != null ? platformName : "";
|
|
238
261
|
}
|
|
239
262
|
|
|
240
263
|
public String getSessionId() {
|
|
@@ -257,6 +280,10 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
257
280
|
return storeName != null ? storeName : "";
|
|
258
281
|
}
|
|
259
282
|
|
|
283
|
+
public String getUserName() {
|
|
284
|
+
return userName != null ? userName : "";
|
|
285
|
+
}
|
|
286
|
+
|
|
260
287
|
public void setUserId(String userId) {
|
|
261
288
|
updateUser(userId, null, null);
|
|
262
289
|
}
|
|
@@ -337,6 +364,13 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
337
364
|
@Override
|
|
338
365
|
public void run() {
|
|
339
366
|
try {
|
|
367
|
+
if ("video_play_end".equals(eventName) && customProperties != null) {
|
|
368
|
+
long dur = customProperties.optLong("playDurationMs", 0);
|
|
369
|
+
String reason = customProperties.optString("endReason", "");
|
|
370
|
+
if (dur < 200 && "refresh_list".equals(reason)) {
|
|
371
|
+
return; // 过滤列表刷新重置引起的毫秒级假停播
|
|
372
|
+
}
|
|
373
|
+
}
|
|
340
374
|
JSONObject event = createBaseEvent("video", eventName);
|
|
341
375
|
event.put("elementId", "video_" + videoId);
|
|
342
376
|
if (!TextUtils.isEmpty(videoTitle)) {
|
|
@@ -344,6 +378,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
344
378
|
} else {
|
|
345
379
|
event.put("elementText", "video_" + videoId);
|
|
346
380
|
}
|
|
381
|
+
// 强绑定视频自身页面路由,杜绝切页(如切商城)并发导致的页面篡改错位
|
|
382
|
+
event.put("pageRoute", "com.renrui.home.fragment.HomeFragment");
|
|
347
383
|
event.put("pageTitle", "小视频推荐");
|
|
348
384
|
|
|
349
385
|
JSONObject extra = new JSONObject();
|
|
@@ -377,6 +413,18 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
377
413
|
});
|
|
378
414
|
}
|
|
379
415
|
|
|
416
|
+
public void trackVideoComment(final long videoId, final String videoTitle, final String commentText) {
|
|
417
|
+
try {
|
|
418
|
+
JSONObject props = new JSONObject();
|
|
419
|
+
props.put("content", commentText);
|
|
420
|
+
trackVideo("video_comment", videoId, videoTitle, props);
|
|
421
|
+
} catch (Exception ignored) {}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public void trackCustom(final String eventName, final String elementText) {
|
|
425
|
+
trackCustom(eventName, elementText, (JSONObject) null);
|
|
426
|
+
}
|
|
427
|
+
|
|
380
428
|
public void trackCustom(final String eventName, final String elementText, final JSONObject customProperties) {
|
|
381
429
|
postBgTask(new Runnable() {
|
|
382
430
|
@Override
|
|
@@ -432,7 +480,11 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
432
480
|
@Override
|
|
433
481
|
public void run() {
|
|
434
482
|
try {
|
|
435
|
-
|
|
483
|
+
String eventType = "click";
|
|
484
|
+
if (elementId != null && (elementId.startsWith("look") || elementId.contains("Exposure") || elementId.contains("Show") || elementId.contains("Bubble"))) {
|
|
485
|
+
eventType = "exposure";
|
|
486
|
+
}
|
|
487
|
+
JSONObject event = createBaseEvent(eventType, "legacy_dadian");
|
|
436
488
|
event.put("frontUrl", frontUrl);
|
|
437
489
|
event.put("elementId", elementId);
|
|
438
490
|
if (postParam != null) event.put("postParam", postParam);
|
|
@@ -485,6 +537,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
485
537
|
if (!TextUtils.isEmpty(phone)) extra.put("phone", phone);
|
|
486
538
|
if (!TextUtils.isEmpty(storeName)) extra.put("storeName", storeName);
|
|
487
539
|
if (!TextUtils.isEmpty(userId)) extra.put("userId", userId);
|
|
540
|
+
if (pflag != -1) extra.put("pflag", pflag);
|
|
541
|
+
if (!TextUtils.isEmpty(platformName)) extra.put("platformName", platformName);
|
|
488
542
|
extra.put("platform", "android");
|
|
489
543
|
|
|
490
544
|
event.put("extraData", extra.toString());
|
|
@@ -578,6 +632,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
578
632
|
if (!TextUtils.isEmpty(phone)) extra.put("phone", phone);
|
|
579
633
|
if (!TextUtils.isEmpty(storeName)) extra.put("storeName", storeName);
|
|
580
634
|
if (!TextUtils.isEmpty(userId)) extra.put("userId", userId);
|
|
635
|
+
if (pflag != -1) extra.put("pflag", pflag);
|
|
636
|
+
if (!TextUtils.isEmpty(platformName)) extra.put("platformName", platformName);
|
|
581
637
|
extra.put("platform", "android");
|
|
582
638
|
event.put("extraData", extra.toString());
|
|
583
639
|
return event;
|
|
@@ -713,7 +769,10 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
713
769
|
body.put("userId", batchUserId);
|
|
714
770
|
body.put("phone", phone != null ? phone : "");
|
|
715
771
|
body.put("storeName", storeName != null ? storeName : "");
|
|
772
|
+
body.put("userName", userName != null ? userName : "");
|
|
716
773
|
body.put("platform", "android");
|
|
774
|
+
if (pflag != -1) body.put("pflag", pflag);
|
|
775
|
+
if (!TextUtils.isEmpty(platformName)) body.put("platformName", platformName);
|
|
717
776
|
|
|
718
777
|
JSONArray eventsArr = new JSONArray();
|
|
719
778
|
for (EventRecord record : records) {
|
|
@@ -948,6 +1007,11 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
948
1007
|
private String getPresetTextForElementId(String elementId) {
|
|
949
1008
|
if (TextUtils.isEmpty(elementId)) return "";
|
|
950
1009
|
String lower = elementId.toLowerCase();
|
|
1010
|
+
if (lower.equals("ll_page_one")) return "首页";
|
|
1011
|
+
if (lower.equals("ll_page_two")) return "银友圈";
|
|
1012
|
+
if (lower.equals("ll_page_three")) return "小视频";
|
|
1013
|
+
if (lower.equals("ll_page_four")) return "商城";
|
|
1014
|
+
if (lower.equals("ll_page_five")) return "我的";
|
|
951
1015
|
if (lower.contains("to_top") || lower.contains("scroll_top")) return "置顶";
|
|
952
1016
|
if (!lower.contains("background") && !lower.contains("feedback") && !lower.contains("fallback") && !lower.contains("callback")
|
|
953
1017
|
&& (lower.startsWith("back") || lower.endsWith("back") || lower.contains("_back") || lower.contains("back_") || lower.equals("back"))) return "返回";
|
|
@@ -974,10 +1038,16 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
974
1038
|
elementId = target.getClass().getSimpleName();
|
|
975
1039
|
}
|
|
976
1040
|
|
|
977
|
-
String
|
|
1041
|
+
String preset = getPresetTextForElementId(elementId);
|
|
1042
|
+
String extracted = "";
|
|
1043
|
+
// 核心 Tab 优先使用标准预置文案,防止被角标红点(如 tv_video_badge: "待观看")抢先误提取
|
|
1044
|
+
if (!TextUtils.isEmpty(preset) && elementId != null && elementId.startsWith("ll_page_")) {
|
|
1045
|
+
extracted = preset;
|
|
1046
|
+
} else {
|
|
1047
|
+
extracted = extractViewText(target);
|
|
1048
|
+
}
|
|
978
1049
|
if (TextUtils.isEmpty(extracted)) {
|
|
979
1050
|
// 1. 优先使用知名图标 ID 映射(解决置顶、返回、关闭等图标抓取不到或被误抓的问题)
|
|
980
|
-
String preset = getPresetTextForElementId(elementId);
|
|
981
1051
|
if (!TextUtils.isEmpty(preset)) {
|
|
982
1052
|
extracted = preset;
|
|
983
1053
|
} else if (target.getParent() instanceof ViewGroup) {
|