@rk911/tracker-sdk 1.7.5 → 1.7.6
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 +1 -1
- package/index.js +2 -2
- package/package.json +1 -1
- package/plugins/api-watch.js +17 -1
- package/plugins/app-lifecycle.js +9 -2
package/core/session.js
CHANGED
|
@@ -152,7 +152,7 @@ export class SessionManager {
|
|
|
152
152
|
this._createNew()
|
|
153
153
|
}
|
|
154
154
|
if (!this.userId) {
|
|
155
|
-
this.userId = this.adapter.getStorage('userId') || null
|
|
155
|
+
this.userId = this.adapter.getStorage('userId') || this.adapter.getStorage('unionid') || null
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
package/index.js
CHANGED
|
@@ -211,8 +211,8 @@ function _ensureUserId(tracker) {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
var adapter = tracker.getAdapter()
|
|
214
|
-
//
|
|
215
|
-
var uid = adapter.getStorage('userId')
|
|
214
|
+
// 从源头实时读取(支持 userId 与 unionid 双向兼容)
|
|
215
|
+
var uid = adapter.getStorage('userId') || adapter.getStorage('unionid')
|
|
216
216
|
// 降级:从 cookie 读(rkfeb-userId)
|
|
217
217
|
if (!uid && typeof document !== 'undefined') {
|
|
218
218
|
var match = document.cookie.match(/(?:^|;\s*)rkfeb-userId=([^;]+)/)
|
package/package.json
CHANGED
package/plugins/api-watch.js
CHANGED
|
@@ -94,6 +94,21 @@ export class ApiWatchPlugin {
|
|
|
94
94
|
)
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
_extractApiPath(url) {
|
|
98
|
+
if (!url || typeof url !== 'string') return ''
|
|
99
|
+
try {
|
|
100
|
+
var clean = url.split('?')[0]
|
|
101
|
+
var schemeIdx = clean.indexOf('://')
|
|
102
|
+
if (schemeIdx >= 0) {
|
|
103
|
+
var pathIdx = clean.indexOf('/', schemeIdx + 3)
|
|
104
|
+
if (pathIdx >= 0) return clean.substring(pathIdx)
|
|
105
|
+
}
|
|
106
|
+
return clean
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return url
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
97
112
|
_setupWebInterceptors() {
|
|
98
113
|
var self = this
|
|
99
114
|
|
|
@@ -244,8 +259,9 @@ export class ApiWatchPlugin {
|
|
|
244
259
|
data.error = err.errMsg || String(err)
|
|
245
260
|
}
|
|
246
261
|
|
|
262
|
+
var apiPath = this._extractApiPath(data.url)
|
|
247
263
|
this.tracker.track('api_request', {
|
|
248
|
-
eventName: data.url,
|
|
264
|
+
eventName: apiPath || data.url,
|
|
249
265
|
extraData: data,
|
|
250
266
|
})
|
|
251
267
|
}
|
package/plugins/app-lifecycle.js
CHANGED
|
@@ -4,6 +4,7 @@ export class AppLifecyclePlugin {
|
|
|
4
4
|
this.tracker = null
|
|
5
5
|
this._visibilityHandler = null
|
|
6
6
|
this._lastState = 'foreground'
|
|
7
|
+
this._lastToggleTime = 0
|
|
7
8
|
this._debounceTimer = null
|
|
8
9
|
}
|
|
9
10
|
|
|
@@ -26,27 +27,33 @@ export class AppLifecyclePlugin {
|
|
|
26
27
|
this._visibilityHandler = function () {
|
|
27
28
|
var state = document.visibilityState
|
|
28
29
|
if (state === 'hidden') {
|
|
29
|
-
// 延迟
|
|
30
|
+
// 延迟 800ms 上报,防窗口焦点抖动与后台 Tab 惊群
|
|
30
31
|
if (self._debounceTimer) {
|
|
31
32
|
clearTimeout(self._debounceTimer)
|
|
32
33
|
}
|
|
33
34
|
self._debounceTimer = setTimeout(function () {
|
|
34
35
|
self._debounceTimer = null
|
|
36
|
+
var now = Date.now()
|
|
37
|
+
if (now - self._lastToggleTime < 2000) return
|
|
35
38
|
if (self._lastState !== 'background') {
|
|
36
39
|
self._lastState = 'background'
|
|
40
|
+
self._lastToggleTime = now
|
|
37
41
|
self.tracker.track('app_lifecycle', {
|
|
38
42
|
eventName: 'background',
|
|
39
43
|
})
|
|
40
44
|
self.tracker.getQueue().flush()
|
|
41
45
|
}
|
|
42
|
-
},
|
|
46
|
+
}, 800)
|
|
43
47
|
} else if (state === 'visible') {
|
|
44
48
|
if (self._debounceTimer) {
|
|
45
49
|
clearTimeout(self._debounceTimer)
|
|
46
50
|
self._debounceTimer = null
|
|
47
51
|
}
|
|
52
|
+
var now = Date.now()
|
|
53
|
+
if (now - self._lastToggleTime < 2000) return
|
|
48
54
|
if (self._lastState !== 'foreground') {
|
|
49
55
|
self._lastState = 'foreground'
|
|
56
|
+
self._lastToggleTime = now
|
|
50
57
|
self.tracker.track('app_lifecycle', {
|
|
51
58
|
eventName: 'foreground',
|
|
52
59
|
})
|