@rk911/tracker-sdk 1.7.14 → 1.7.15
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 +61 -3
- 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
|
@@ -75,6 +75,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
75
75
|
private volatile String phone;
|
|
76
76
|
private volatile String storeName;
|
|
77
77
|
private volatile int sequence = 0;
|
|
78
|
+
private volatile int pflag = -1;
|
|
79
|
+
private volatile String platformName = "";
|
|
78
80
|
|
|
79
81
|
private HandlerThread bgThread;
|
|
80
82
|
private Handler bgHandler;
|
|
@@ -237,6 +239,20 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
237
239
|
Log.i(TAG, "===> [Native Tracker User Updated] UserId: " + this.userId + ", Phone: " + this.phone + ", Store: " + this.storeName);
|
|
238
240
|
}
|
|
239
241
|
|
|
242
|
+
public void setPlatform(int pflag, String platformName) {
|
|
243
|
+
this.pflag = pflag;
|
|
244
|
+
this.platformName = platformName != null ? platformName : "";
|
|
245
|
+
Log.i(TAG, "===> [Native Tracker Platform Updated] pflag: " + this.pflag + ", platformName: " + this.platformName);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public int getPflag() {
|
|
249
|
+
return pflag;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public String getPlatformName() {
|
|
253
|
+
return platformName != null ? platformName : "";
|
|
254
|
+
}
|
|
255
|
+
|
|
240
256
|
public String getSessionId() {
|
|
241
257
|
return sessionId;
|
|
242
258
|
}
|
|
@@ -337,6 +353,13 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
337
353
|
@Override
|
|
338
354
|
public void run() {
|
|
339
355
|
try {
|
|
356
|
+
if ("video_play_end".equals(eventName) && customProperties != null) {
|
|
357
|
+
long dur = customProperties.optLong("playDurationMs", 0);
|
|
358
|
+
String reason = customProperties.optString("endReason", "");
|
|
359
|
+
if (dur < 200 && "refresh_list".equals(reason)) {
|
|
360
|
+
return; // 过滤列表刷新重置引起的毫秒级假停播
|
|
361
|
+
}
|
|
362
|
+
}
|
|
340
363
|
JSONObject event = createBaseEvent("video", eventName);
|
|
341
364
|
event.put("elementId", "video_" + videoId);
|
|
342
365
|
if (!TextUtils.isEmpty(videoTitle)) {
|
|
@@ -344,6 +367,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
344
367
|
} else {
|
|
345
368
|
event.put("elementText", "video_" + videoId);
|
|
346
369
|
}
|
|
370
|
+
// 强绑定视频自身页面路由,杜绝切页(如切商城)并发导致的页面篡改错位
|
|
371
|
+
event.put("pageRoute", "com.renrui.home.fragment.HomeFragment");
|
|
347
372
|
event.put("pageTitle", "小视频推荐");
|
|
348
373
|
|
|
349
374
|
JSONObject extra = new JSONObject();
|
|
@@ -377,6 +402,18 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
377
402
|
});
|
|
378
403
|
}
|
|
379
404
|
|
|
405
|
+
public void trackVideoComment(final long videoId, final String videoTitle, final String commentText) {
|
|
406
|
+
try {
|
|
407
|
+
JSONObject props = new JSONObject();
|
|
408
|
+
props.put("content", commentText);
|
|
409
|
+
trackVideo("video_comment", videoId, videoTitle, props);
|
|
410
|
+
} catch (Exception ignored) {}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
public void trackCustom(final String eventName, final String elementText) {
|
|
414
|
+
trackCustom(eventName, elementText, (JSONObject) null);
|
|
415
|
+
}
|
|
416
|
+
|
|
380
417
|
public void trackCustom(final String eventName, final String elementText, final JSONObject customProperties) {
|
|
381
418
|
postBgTask(new Runnable() {
|
|
382
419
|
@Override
|
|
@@ -432,7 +469,11 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
432
469
|
@Override
|
|
433
470
|
public void run() {
|
|
434
471
|
try {
|
|
435
|
-
|
|
472
|
+
String eventType = "click";
|
|
473
|
+
if (elementId != null && (elementId.startsWith("look") || elementId.contains("Exposure") || elementId.contains("Show") || elementId.contains("Bubble"))) {
|
|
474
|
+
eventType = "exposure";
|
|
475
|
+
}
|
|
476
|
+
JSONObject event = createBaseEvent(eventType, "legacy_dadian");
|
|
436
477
|
event.put("frontUrl", frontUrl);
|
|
437
478
|
event.put("elementId", elementId);
|
|
438
479
|
if (postParam != null) event.put("postParam", postParam);
|
|
@@ -485,6 +526,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
485
526
|
if (!TextUtils.isEmpty(phone)) extra.put("phone", phone);
|
|
486
527
|
if (!TextUtils.isEmpty(storeName)) extra.put("storeName", storeName);
|
|
487
528
|
if (!TextUtils.isEmpty(userId)) extra.put("userId", userId);
|
|
529
|
+
if (pflag != -1) extra.put("pflag", pflag);
|
|
530
|
+
if (!TextUtils.isEmpty(platformName)) extra.put("platformName", platformName);
|
|
488
531
|
extra.put("platform", "android");
|
|
489
532
|
|
|
490
533
|
event.put("extraData", extra.toString());
|
|
@@ -578,6 +621,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
578
621
|
if (!TextUtils.isEmpty(phone)) extra.put("phone", phone);
|
|
579
622
|
if (!TextUtils.isEmpty(storeName)) extra.put("storeName", storeName);
|
|
580
623
|
if (!TextUtils.isEmpty(userId)) extra.put("userId", userId);
|
|
624
|
+
if (pflag != -1) extra.put("pflag", pflag);
|
|
625
|
+
if (!TextUtils.isEmpty(platformName)) extra.put("platformName", platformName);
|
|
581
626
|
extra.put("platform", "android");
|
|
582
627
|
event.put("extraData", extra.toString());
|
|
583
628
|
return event;
|
|
@@ -714,6 +759,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
714
759
|
body.put("phone", phone != null ? phone : "");
|
|
715
760
|
body.put("storeName", storeName != null ? storeName : "");
|
|
716
761
|
body.put("platform", "android");
|
|
762
|
+
if (pflag != -1) body.put("pflag", pflag);
|
|
763
|
+
if (!TextUtils.isEmpty(platformName)) body.put("platformName", platformName);
|
|
717
764
|
|
|
718
765
|
JSONArray eventsArr = new JSONArray();
|
|
719
766
|
for (EventRecord record : records) {
|
|
@@ -948,6 +995,11 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
948
995
|
private String getPresetTextForElementId(String elementId) {
|
|
949
996
|
if (TextUtils.isEmpty(elementId)) return "";
|
|
950
997
|
String lower = elementId.toLowerCase();
|
|
998
|
+
if (lower.equals("ll_page_one")) return "首页";
|
|
999
|
+
if (lower.equals("ll_page_two")) return "银友圈";
|
|
1000
|
+
if (lower.equals("ll_page_three")) return "小视频";
|
|
1001
|
+
if (lower.equals("ll_page_four")) return "商城";
|
|
1002
|
+
if (lower.equals("ll_page_five")) return "我的";
|
|
951
1003
|
if (lower.contains("to_top") || lower.contains("scroll_top")) return "置顶";
|
|
952
1004
|
if (!lower.contains("background") && !lower.contains("feedback") && !lower.contains("fallback") && !lower.contains("callback")
|
|
953
1005
|
&& (lower.startsWith("back") || lower.endsWith("back") || lower.contains("_back") || lower.contains("back_") || lower.equals("back"))) return "返回";
|
|
@@ -974,10 +1026,16 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
|
|
|
974
1026
|
elementId = target.getClass().getSimpleName();
|
|
975
1027
|
}
|
|
976
1028
|
|
|
977
|
-
String
|
|
1029
|
+
String preset = getPresetTextForElementId(elementId);
|
|
1030
|
+
String extracted = "";
|
|
1031
|
+
// 核心 Tab 优先使用标准预置文案,防止被角标红点(如 tv_video_badge: "待观看")抢先误提取
|
|
1032
|
+
if (!TextUtils.isEmpty(preset) && elementId != null && elementId.startsWith("ll_page_")) {
|
|
1033
|
+
extracted = preset;
|
|
1034
|
+
} else {
|
|
1035
|
+
extracted = extractViewText(target);
|
|
1036
|
+
}
|
|
978
1037
|
if (TextUtils.isEmpty(extracted)) {
|
|
979
1038
|
// 1. 优先使用知名图标 ID 映射(解决置顶、返回、关闭等图标抓取不到或被误抓的问题)
|
|
980
|
-
String preset = getPresetTextForElementId(elementId);
|
|
981
1039
|
if (!TextUtils.isEmpty(preset)) {
|
|
982
1040
|
extracted = preset;
|
|
983
1041
|
} else if (target.getParent() instanceof ViewGroup) {
|