@datarangers/sdk-javascript 0.1.0 → 0.1.1
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/es/index-base.min.js +1 -6430
- package/es/index.min.js +1 -9936
- package/es/plugin/ab.js +1 -928
- package/es/plugin/autotrack.js +1 -1897
- package/es/plugin/duration.js +1 -117
- package/es/plugin/route.js +1 -363
- package/es/plugin/stay.js +1 -547
- package/lib/index-base.min.js +1 -6435
- package/lib/index.min.js +1 -9941
- package/lib/plugin/ab.js +1 -930
- package/lib/plugin/autotrack.js +1 -1899
- package/lib/plugin/duration.js +1 -119
- package/lib/plugin/route.js +1 -365
- package/lib/plugin/stay.js +1 -549
- package/package.json +3 -4
- package/types/types.d.ts +24 -1
- package/core/es/index.min.js +0 -1
- package/core/lib/index.min.js +0 -1
- package/es/plugin/store.js +0 -151
- package/lib/plugin/store.js +0 -153
package/es/plugin/autotrack.js
CHANGED
|
@@ -1,1897 +1 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
|
|
16
|
-
var __assign = function() {
|
|
17
|
-
__assign = Object.assign || function __assign(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
return __assign.apply(this, arguments);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function __read(o, n) {
|
|
28
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29
|
-
if (!m) return o;
|
|
30
|
-
var i = m.call(o), r, ar = [], e;
|
|
31
|
-
try {
|
|
32
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
33
|
-
}
|
|
34
|
-
catch (error) { e = { error: error }; }
|
|
35
|
-
finally {
|
|
36
|
-
try {
|
|
37
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
38
|
-
}
|
|
39
|
-
finally { if (e) throw e.error; }
|
|
40
|
-
}
|
|
41
|
-
return ar;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** @deprecated */
|
|
45
|
-
function __spread() {
|
|
46
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
47
|
-
ar = ar.concat(__read(arguments[i]));
|
|
48
|
-
return ar;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
52
|
-
var isArray = function isArray(obj) {
|
|
53
|
-
return Array.isArray(obj);
|
|
54
|
-
};
|
|
55
|
-
(function () {
|
|
56
|
-
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
57
|
-
return function () {
|
|
58
|
-
lastEventId += 1;
|
|
59
|
-
return lastEventId;
|
|
60
|
-
};
|
|
61
|
-
})();
|
|
62
|
-
var beforePageUnload = function beforePageUnload(fn) {
|
|
63
|
-
var isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
|
64
|
-
|
|
65
|
-
if (isiOS) {
|
|
66
|
-
window.addEventListener("pagehide", fn, false);
|
|
67
|
-
} else {
|
|
68
|
-
window.addEventListener("beforeunload", fn, false);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var addListener = function addListener(target, type, handler, pop) {
|
|
72
|
-
if (target.addEventListener) {
|
|
73
|
-
target.addEventListener(type, handler, pop);
|
|
74
|
-
} else if (target.attachEven) {
|
|
75
|
-
target.attachEven("on" + type, handler);
|
|
76
|
-
} else {
|
|
77
|
-
target["on" + type] = handler;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var removeListener = function removeListener(target, type, handler, pop) {
|
|
81
|
-
if (target.addEventListener) {
|
|
82
|
-
target.removeEventListener(type, handler, pop);
|
|
83
|
-
} else if (target.attachEven) {
|
|
84
|
-
target.detachEven("on" + type, handler);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
89
|
-
function isNeedElement(element, type) {
|
|
90
|
-
if (type === void 0) {
|
|
91
|
-
type = 'list';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!element) return false;
|
|
95
|
-
|
|
96
|
-
if (type && type === 'list') {
|
|
97
|
-
if (['LI', 'TR', 'DL'].includes(element.nodeName)) return true;
|
|
98
|
-
if (element.dataset && element.dataset.hasOwnProperty('teaIdx')) return true;
|
|
99
|
-
if (element.hasAttribute && element.hasAttribute('data-tea-idx')) return true;
|
|
100
|
-
} else {
|
|
101
|
-
if (['A', 'BUTTON'].includes(element.nodeName)) return true;
|
|
102
|
-
if (element.dataset && element.dataset.hasOwnProperty('teaContainer')) return true;
|
|
103
|
-
if (element.hasAttribute && element.hasAttribute('data-tea-container')) return true;
|
|
104
|
-
if (element.hasAttribute && hasAttributes(element, 'ss')) return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
var isAttrFilter = function isAttrFilter(element, attrs) {
|
|
110
|
-
if (hasAttributes(element, attrs)) return true;
|
|
111
|
-
return false;
|
|
112
|
-
};
|
|
113
|
-
function getContainer(element) {
|
|
114
|
-
var current = element;
|
|
115
|
-
|
|
116
|
-
while (current && !isNeedElement(current, 'container')) {
|
|
117
|
-
if (current.nodeName === 'HTML' || current.nodeName === 'BODY') {
|
|
118
|
-
return element;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
current = current.parentElement;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return current || element;
|
|
125
|
-
}
|
|
126
|
-
function getNodeText(node) {
|
|
127
|
-
var text = '';
|
|
128
|
-
|
|
129
|
-
if (node.nodeType === 3) {
|
|
130
|
-
text = node.textContent.trim();
|
|
131
|
-
} else if (node['dataset'] && node['dataset'].hasOwnProperty('teaTitle')) {
|
|
132
|
-
text = node['getAttribute']('data-tea-title');
|
|
133
|
-
} else if (node['hasAttribute']('ata-tea-title')) {
|
|
134
|
-
text = node['getAttribute']('data-tea-title');
|
|
135
|
-
} else if (node['hasAttribute']('title')) {
|
|
136
|
-
text = node['getAttribute']('title');
|
|
137
|
-
} else if (node.nodeName === 'INPUT' && ['button', 'submit'].includes(node['getAttribute']('type'))) {
|
|
138
|
-
text = node['getAttribute']('value');
|
|
139
|
-
} else if (node.nodeName === 'IMG' && node['getAttribute']('alt')) {
|
|
140
|
-
text = node['getAttribute']('alt');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return text.slice(0, 200);
|
|
144
|
-
}
|
|
145
|
-
function getText(element) {
|
|
146
|
-
var ele = getContainer(element);
|
|
147
|
-
var textArr = [];
|
|
148
|
-
|
|
149
|
-
(function _get(node) {
|
|
150
|
-
var text = getNodeText(node);
|
|
151
|
-
|
|
152
|
-
if (text && textArr.indexOf(text) === -1) {
|
|
153
|
-
textArr.push(text);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (node.childNodes.length > 0) {
|
|
157
|
-
var childNodes = node.childNodes;
|
|
158
|
-
|
|
159
|
-
for (var i = 0; i < childNodes.length; i++) {
|
|
160
|
-
if (childNodes[i].nodeType !== 8) {
|
|
161
|
-
_get(childNodes[i]);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
})(ele);
|
|
166
|
-
|
|
167
|
-
return textArr;
|
|
168
|
-
}
|
|
169
|
-
var getElementText = function getElementText(element) {
|
|
170
|
-
if (!element) return '';
|
|
171
|
-
var elementText = '';
|
|
172
|
-
|
|
173
|
-
if (element.textContent) {
|
|
174
|
-
elementText = element.textContent.trim();
|
|
175
|
-
} else if (element.innerText) {
|
|
176
|
-
elementText = element.innerText.trim();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (element.tagName === 'input' || element.tagName === 'INPUT') {
|
|
180
|
-
elementText = element.value || '';
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return elementText;
|
|
184
|
-
};
|
|
185
|
-
function ignore(element) {
|
|
186
|
-
var _element = element;
|
|
187
|
-
|
|
188
|
-
while (_element && _element.parentNode) {
|
|
189
|
-
if (_element.hasAttribute('data-tea-ignore')) return true;
|
|
190
|
-
if (_element.nodeName === 'HTML' || _element.nodeName === 'body') return false;
|
|
191
|
-
_element = _element.parentNode;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
var hasAttribute = function hasAttribute(ele, attr) {
|
|
197
|
-
if (ele.hasAttribute) {
|
|
198
|
-
return ele.hasAttribute(attr);
|
|
199
|
-
} else if (ele.attributes) {
|
|
200
|
-
return !!(ele.attributes[attr] && ele.attributes[attr].specified);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var hasAttributes = function hasAttributes(ele, attrs) {
|
|
204
|
-
if (typeof attrs === 'string') {
|
|
205
|
-
return hasAttribute(ele, attrs);
|
|
206
|
-
} else if (isArray(attrs)) {
|
|
207
|
-
var result = false;
|
|
208
|
-
|
|
209
|
-
for (var i = 0; i < attrs.length; i++) {
|
|
210
|
-
var testResult = hasAttribute(ele, attrs[i]);
|
|
211
|
-
|
|
212
|
-
if (testResult) {
|
|
213
|
-
result = true;
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return result;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
var getAttributes = function getAttributes(ele, attrs) {
|
|
222
|
-
var result = {};
|
|
223
|
-
|
|
224
|
-
if (typeof attrs === 'string') {
|
|
225
|
-
if (hasAttribute(ele, attrs)) {
|
|
226
|
-
result[attrs] = ele.getAttribute(attrs);
|
|
227
|
-
}
|
|
228
|
-
} else {
|
|
229
|
-
if (isArray(attrs)) {
|
|
230
|
-
for (var i = 0; i < attrs.length; i++) {
|
|
231
|
-
var testResult = hasAttribute(ele, attrs[i]);
|
|
232
|
-
|
|
233
|
-
if (testResult) {
|
|
234
|
-
result[attrs[i]] = ele.getAttribute(attrs[i]);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return result;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
244
|
-
|
|
245
|
-
var elementLevel = function elementLevel(element) {
|
|
246
|
-
if (element.children.length) {
|
|
247
|
-
var childElement = element.children;
|
|
248
|
-
|
|
249
|
-
if ([].slice.call(childElement).some(function (element) {
|
|
250
|
-
return element.children.length > 0;
|
|
251
|
-
})) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return true;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
var isSVG = function isSVG(element) {
|
|
262
|
-
if (element.tagName.toLowerCase() === 'svg') {
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
var parent = element.parentElement;
|
|
267
|
-
var flag = false;
|
|
268
|
-
|
|
269
|
-
while (parent) {
|
|
270
|
-
if (parent.tagName.toLowerCase() === 'svg') {
|
|
271
|
-
parent = null;
|
|
272
|
-
flag = true;
|
|
273
|
-
} else {
|
|
274
|
-
parent = parent.parentElement;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return flag;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
function isTrack(node, options) {
|
|
282
|
-
if (node.nodeType !== 1) {
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (!options.svg && isSVG(node)) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (['HTML', 'BODY'].includes(node.tagName.toUpperCase())) {
|
|
291
|
-
return false;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
var element = node;
|
|
295
|
-
|
|
296
|
-
if (element.style.display === 'none') {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (isNeedElement(element, 'container')) {
|
|
301
|
-
return true;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (options.track_attr) {
|
|
305
|
-
if (isAttrFilter(element, options.track_attr)) {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (!elementLevel(element)) {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
318
|
-
|
|
319
|
-
var Listener =
|
|
320
|
-
/** @class */
|
|
321
|
-
function () {
|
|
322
|
-
function Listener(options, collect, Config) {
|
|
323
|
-
var _this = this;
|
|
324
|
-
|
|
325
|
-
this.clickEvent = function (e) {
|
|
326
|
-
if (isTrack(e['target'], _this.options)) {
|
|
327
|
-
_this.eventHandel({
|
|
328
|
-
eventType: 'dom',
|
|
329
|
-
eventName: 'click'
|
|
330
|
-
}, e);
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
this.changeEvent = function (e) {
|
|
335
|
-
_this.eventHandel({
|
|
336
|
-
eventType: 'dom',
|
|
337
|
-
eventName: 'change'
|
|
338
|
-
}, e);
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
this.submitEvent = function (e) {
|
|
342
|
-
_this.eventHandel({
|
|
343
|
-
eventType: 'dom',
|
|
344
|
-
eventName: 'submit'
|
|
345
|
-
}, e);
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
this.getPageViewEvent = function (eventData, name) {
|
|
349
|
-
if (name && name === 'pushState') {
|
|
350
|
-
_this.eventHandel({
|
|
351
|
-
eventType: 'dom',
|
|
352
|
-
eventName: 'beat'
|
|
353
|
-
}, __assign({
|
|
354
|
-
beat_type: 0
|
|
355
|
-
}, eventData));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
_this.eventHandel({
|
|
359
|
-
eventType: 'dom',
|
|
360
|
-
eventName: 'page_view'
|
|
361
|
-
}, eventData);
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
this.getPageLoadEvent = function (lcp) {
|
|
365
|
-
_this.eventHandel({
|
|
366
|
-
eventType: 'dom',
|
|
367
|
-
eventName: 'page_statistics'
|
|
368
|
-
}, {
|
|
369
|
-
lcp: lcp
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
this.config = Config.getConfig().eventConfig;
|
|
374
|
-
this.collect = collect;
|
|
375
|
-
this.options = options;
|
|
376
|
-
this.beatTime = options.beat;
|
|
377
|
-
this.statistics = false;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
Listener.prototype.init = function (eventHandel) {
|
|
381
|
-
this.eventHandel = eventHandel;
|
|
382
|
-
var mode = this.config.mode;
|
|
383
|
-
this.addListener(mode);
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
Listener.prototype.addListener = function (mode) {
|
|
387
|
-
var _this = this; // 注册事件捕获
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (mode === 'proxy-capturing') {
|
|
391
|
-
if (this.config.click) {
|
|
392
|
-
window.document.addEventListener('click', this.clickEvent, true);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (this.config.change) {
|
|
396
|
-
window.document.addEventListener('change', this.changeEvent, true);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (this.config.submit) {
|
|
400
|
-
window.document.addEventListener('submit', this.submitEvent, true);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (this.config.pv) {
|
|
404
|
-
this.collect.on('route-change', function (info) {
|
|
405
|
-
var config = info.config,
|
|
406
|
-
name = info.name;
|
|
407
|
-
|
|
408
|
-
_this.getPageViewEvent(config, name);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if (this.config.beat) {
|
|
413
|
-
try {
|
|
414
|
-
if (document.readyState === 'complete') {
|
|
415
|
-
this.beatEvent(this.beatTime);
|
|
416
|
-
} else {
|
|
417
|
-
window.addEventListener('load', function () {
|
|
418
|
-
_this.beatEvent(_this.beatTime);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
var t1_1 = 0;
|
|
423
|
-
var t2_1 = 0;
|
|
424
|
-
var timer_1 = null; // 定时器
|
|
425
|
-
|
|
426
|
-
window.addEventListener('scroll', function () {
|
|
427
|
-
clearTimeout(timer_1);
|
|
428
|
-
timer_1 = setTimeout(isScrollEnd_1, 500);
|
|
429
|
-
t1_1 = document.documentElement.scrollTop || document.body.scrollTop;
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
var isScrollEnd_1 = function isScrollEnd_1() {
|
|
433
|
-
t2_1 = document.documentElement.scrollTop || document.body.scrollTop;
|
|
434
|
-
|
|
435
|
-
if (t2_1 == t1_1) {
|
|
436
|
-
_this.eventHandel({
|
|
437
|
-
eventType: 'dom',
|
|
438
|
-
eventName: 'beat'
|
|
439
|
-
}, {
|
|
440
|
-
beat_type: 1
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
} catch (e) {}
|
|
445
|
-
|
|
446
|
-
try {
|
|
447
|
-
var entryList = window.performance && window.performance.getEntriesByType('paint');
|
|
448
|
-
|
|
449
|
-
if (entryList && entryList.length) {
|
|
450
|
-
var observer = new PerformanceObserver(function (entryList) {
|
|
451
|
-
var entries = entryList.getEntries();
|
|
452
|
-
var lastEntry = entries[entries.length - 1];
|
|
453
|
-
var lcp = lastEntry['renderTime'] || lastEntry['loadTime'];
|
|
454
|
-
|
|
455
|
-
if (!_this.statistics) {
|
|
456
|
-
_this.getPageLoadEvent(lcp);
|
|
457
|
-
|
|
458
|
-
_this.statistics = true;
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
observer.observe({
|
|
462
|
-
entryTypes: ['largest-contentful-paint']
|
|
463
|
-
}); // 没触发2S后强制触发
|
|
464
|
-
|
|
465
|
-
setTimeout(function () {
|
|
466
|
-
if (_this.statistics) return;
|
|
467
|
-
|
|
468
|
-
_this.getPageLoadEvent(entryList[0].startTime || 0);
|
|
469
|
-
|
|
470
|
-
_this.statistics = true;
|
|
471
|
-
}, 2000);
|
|
472
|
-
} else {
|
|
473
|
-
this.getPageLoadEvent(0);
|
|
474
|
-
}
|
|
475
|
-
} catch (e) {
|
|
476
|
-
this.getPageLoadEvent(0);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
Listener.prototype.removeListener = function () {
|
|
483
|
-
window.document.removeEventListener('click', this.clickEvent, true);
|
|
484
|
-
window.document.removeEventListener('change', this.changeEvent, true);
|
|
485
|
-
window.document.removeEventListener('submit', this.submitEvent, true);
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
Listener.prototype.beatEvent = function (beatTime) {
|
|
489
|
-
var _this = this;
|
|
490
|
-
|
|
491
|
-
try {
|
|
492
|
-
this.eventHandel({
|
|
493
|
-
eventType: 'dom',
|
|
494
|
-
eventName: 'beat'
|
|
495
|
-
}, {
|
|
496
|
-
beat_type: 3
|
|
497
|
-
});
|
|
498
|
-
var beaInterval_1;
|
|
499
|
-
|
|
500
|
-
if (this.beatTime) {
|
|
501
|
-
beaInterval_1 = setInterval(function () {
|
|
502
|
-
_this.eventHandel({
|
|
503
|
-
eventType: 'dom',
|
|
504
|
-
eventName: 'beat'
|
|
505
|
-
}, {
|
|
506
|
-
beat_type: 2
|
|
507
|
-
});
|
|
508
|
-
}, beatTime);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
beforePageUnload(function () {
|
|
512
|
-
_this.eventHandel({
|
|
513
|
-
eventType: 'dom',
|
|
514
|
-
eventName: 'beat',
|
|
515
|
-
eventSend: 'becon'
|
|
516
|
-
}, {
|
|
517
|
-
beat_type: 0
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
if (_this.beatTime) {
|
|
521
|
-
clearInterval(beaInterval_1);
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
} catch (e) {}
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
return Listener;
|
|
528
|
-
}();
|
|
529
|
-
|
|
530
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
531
|
-
var defaultConfig = {
|
|
532
|
-
eventConfig: {
|
|
533
|
-
mode: "proxy-capturing",
|
|
534
|
-
submit: false,
|
|
535
|
-
click: true,
|
|
536
|
-
change: false,
|
|
537
|
-
pv: true,
|
|
538
|
-
beat: true,
|
|
539
|
-
hashTag: false,
|
|
540
|
-
impr: false
|
|
541
|
-
},
|
|
542
|
-
scoutConfig: {
|
|
543
|
-
mode: "xpath"
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
var Config =
|
|
548
|
-
/** @class */
|
|
549
|
-
function () {
|
|
550
|
-
function Config(config, options) {
|
|
551
|
-
this.config = config;
|
|
552
|
-
this.config.eventConfig = Object.assign(this.config.eventConfig, options);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
Config.prototype.getConfig = function () {
|
|
556
|
-
return this.config;
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
Config.prototype.setConfig = function (config) {
|
|
560
|
-
return this.config = config;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
return Config;
|
|
564
|
-
}();
|
|
565
|
-
|
|
566
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
567
|
-
function getPositionData(target) {
|
|
568
|
-
if (!target) {
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
var rect = target.getBoundingClientRect();
|
|
573
|
-
var width = rect.width,
|
|
574
|
-
height = rect.height,
|
|
575
|
-
left = rect.left,
|
|
576
|
-
top = rect.top;
|
|
577
|
-
return {
|
|
578
|
-
left: left,
|
|
579
|
-
top: top,
|
|
580
|
-
element_width: width,
|
|
581
|
-
element_height: height
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
function getEventData$1(event, extData) {
|
|
585
|
-
if (event === void 0) {
|
|
586
|
-
event = {};
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
if (extData === void 0) {
|
|
590
|
-
extData = {};
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
var clientX = event.clientX,
|
|
594
|
-
clientY = event.clientY;
|
|
595
|
-
var left = extData.left,
|
|
596
|
-
top = extData.top;
|
|
597
|
-
var touchX = clientX - left >= 0 ? clientX - left : 0;
|
|
598
|
-
var touchY = clientY - top >= 0 ? clientY - top : 0;
|
|
599
|
-
return {
|
|
600
|
-
touch_x: Math.floor(touchX),
|
|
601
|
-
touch_y: Math.floor(touchY)
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
function getXpath(target) {
|
|
605
|
-
var targetList = [];
|
|
606
|
-
|
|
607
|
-
while (target.parentElement !== null) {
|
|
608
|
-
targetList.push(target);
|
|
609
|
-
target = target.parentElement;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
var xpathArr = [];
|
|
613
|
-
var positions = [];
|
|
614
|
-
targetList.forEach(function (cur) {
|
|
615
|
-
var _a = getXpathIndex(cur),
|
|
616
|
-
str = _a.str,
|
|
617
|
-
index = _a.index;
|
|
618
|
-
|
|
619
|
-
xpathArr.unshift(str);
|
|
620
|
-
positions.unshift(index);
|
|
621
|
-
});
|
|
622
|
-
return {
|
|
623
|
-
element_path: "/" + xpathArr.join('/'),
|
|
624
|
-
positions: positions
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function getXpathIndex(dom) {
|
|
629
|
-
if (dom === null) {
|
|
630
|
-
return {
|
|
631
|
-
str: '',
|
|
632
|
-
index: 0
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
var index = 0;
|
|
637
|
-
var parent = dom.parentElement;
|
|
638
|
-
|
|
639
|
-
if (parent) {
|
|
640
|
-
var childrens = parent.children;
|
|
641
|
-
|
|
642
|
-
for (var i = 0; i < childrens.length; i++) {
|
|
643
|
-
if (childrens[i] === dom) break;
|
|
644
|
-
|
|
645
|
-
if (childrens[i].nodeName === dom.nodeName) {
|
|
646
|
-
index++;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
var tag = [dom.nodeName.toLowerCase(), isNeedElement(dom, 'list') ? '[]' : ''].join('');
|
|
652
|
-
return {
|
|
653
|
-
str: tag,
|
|
654
|
-
index: index
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
659
|
-
function getElementData(event, element, options, ignore) {
|
|
660
|
-
var elementData = {};
|
|
661
|
-
var positionData = getPositionData(element);
|
|
662
|
-
var eventData = getEventData$1(event, positionData);
|
|
663
|
-
var element_width = positionData.element_width,
|
|
664
|
-
element_height = positionData.element_height;
|
|
665
|
-
var touch_x = eventData.touch_x,
|
|
666
|
-
touch_y = eventData.touch_y;
|
|
667
|
-
|
|
668
|
-
var _a = getXpath(element),
|
|
669
|
-
element_path = _a.element_path,
|
|
670
|
-
positions = _a.positions;
|
|
671
|
-
|
|
672
|
-
var texts = getText(element);
|
|
673
|
-
var page_start_ms = window.performance.timing.navigationStart;
|
|
674
|
-
var since_page_start_ms = Date.now() - page_start_ms;
|
|
675
|
-
|
|
676
|
-
var _position = positions.map(function (item) {
|
|
677
|
-
return "" + item;
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
var elementObj = null;
|
|
681
|
-
|
|
682
|
-
if (window.TEAVisualEditor && window.TEAVisualEditor.getOriginXpath) {
|
|
683
|
-
elementObj = window.TEAVisualEditor.getOriginXpath({
|
|
684
|
-
xpath: element_path,
|
|
685
|
-
positions: _position
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
elementData.element_path = elementObj && elementObj.xpath || element_path;
|
|
690
|
-
elementData.positions = elementObj && elementObj.positions || _position;
|
|
691
|
-
|
|
692
|
-
if (ignore && !ignore.text) {
|
|
693
|
-
elementData.texts = texts;
|
|
694
|
-
elementData.element_title = getElementText(element);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
elementData.element_id = element.getAttribute('id') || '';
|
|
698
|
-
elementData.element_class_name = element.getAttribute('class') || '';
|
|
699
|
-
elementData.element_type = element.nodeType;
|
|
700
|
-
elementData.element_width = Math.floor(element_width);
|
|
701
|
-
elementData.element_height = Math.floor(element_height);
|
|
702
|
-
elementData.touch_x = touch_x;
|
|
703
|
-
elementData.touch_y = touch_y;
|
|
704
|
-
elementData.page_manual_key = '';
|
|
705
|
-
elementData.elememt_manual_key = '';
|
|
706
|
-
elementData.since_page_start_ms = since_page_start_ms;
|
|
707
|
-
elementData.page_start_ms = page_start_ms;
|
|
708
|
-
elementData.page_path = location.pathname;
|
|
709
|
-
elementData.page_host = location.host;
|
|
710
|
-
|
|
711
|
-
if (options.track_attr) {
|
|
712
|
-
if (isAttrFilter(element, options.track_attr)) {
|
|
713
|
-
var attrData = getAttributes(element, options.track_attr);
|
|
714
|
-
|
|
715
|
-
for (var attr in attrData) {
|
|
716
|
-
elementData[attr] = attrData[attr];
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
if (options.custom_attr) {
|
|
722
|
-
try {
|
|
723
|
-
if (isAttrFilter(element, options.custom_attr)) {
|
|
724
|
-
var attrData = getAttributes(element, options.custom_attr);
|
|
725
|
-
var attr = decodeURIComponent(attrData[options.custom_attr]);
|
|
726
|
-
var attrObj = JSON.parse(attr);
|
|
727
|
-
|
|
728
|
-
if (Object.keys(attrObj)) {
|
|
729
|
-
for (var key in attrObj) {
|
|
730
|
-
elementData[key] = attrObj[key];
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
} catch (e) {
|
|
735
|
-
console.log('custom attr error');
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
var containerNoode = getContainer(element);
|
|
740
|
-
|
|
741
|
-
if (containerNoode.tagName === 'A') {
|
|
742
|
-
elementData.href = containerNoode.getAttribute('href');
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (options.src !== false) {
|
|
746
|
-
if (element.tagName === 'IMG' && !element.getAttribute('src').includes('base64')) {
|
|
747
|
-
elementData.src = element.getAttribute('src');
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
return elementData;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
755
|
-
|
|
756
|
-
var getEventData = function getEventData(event, e, element, options, ignore) {
|
|
757
|
-
return __assign({
|
|
758
|
-
event: event
|
|
759
|
-
}, getElementData(e, element, options, ignore), {
|
|
760
|
-
is_html: 1,
|
|
761
|
-
page_key: window.location.href,
|
|
762
|
-
page_title: document.title
|
|
763
|
-
});
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
var getExtraEventData = function getExtraEventData(event, element) {
|
|
767
|
-
try {
|
|
768
|
-
if (event === 'bav2b_change') {
|
|
769
|
-
if (element.hasAttribute('data-tea-track')) {
|
|
770
|
-
return {
|
|
771
|
-
value: element.value
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
return {};
|
|
776
|
-
}
|
|
777
|
-
} catch (err) {
|
|
778
|
-
return {};
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
var EventHandle =
|
|
783
|
-
/** @class */
|
|
784
|
-
function () {
|
|
785
|
-
function EventHandle(initConfig, options) {
|
|
786
|
-
this.ignore = {
|
|
787
|
-
text: false
|
|
788
|
-
};
|
|
789
|
-
this.initConfig = initConfig;
|
|
790
|
-
this.options = options;
|
|
791
|
-
this.eventName = options && options.custom === 'tea' ? {
|
|
792
|
-
click: '__bav_click',
|
|
793
|
-
page: '__bav_page',
|
|
794
|
-
beat: '__bav_beat',
|
|
795
|
-
"static": '__bav_page_statistics',
|
|
796
|
-
exposure: '__bav_page_exposure'
|
|
797
|
-
} : {
|
|
798
|
-
click: 'bav2b_click',
|
|
799
|
-
page: 'bav2b_page',
|
|
800
|
-
beat: 'bav2b_beat',
|
|
801
|
-
"static": 'bav2b_page_statistics',
|
|
802
|
-
exposure: 'bav2b_exposure',
|
|
803
|
-
scroll: '$bav2b_slide'
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
if (options && options.text === false) {
|
|
807
|
-
this.ignore.text = true;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
if (options && options.exposure && options.exposure.eventName) {
|
|
811
|
-
this.eventName['exposure'] = options.exposure.eventName;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
EventHandle.prototype.handleEvent = function (e, eventType) {
|
|
816
|
-
try {
|
|
817
|
-
if (ignore(e.target)) {
|
|
818
|
-
return null;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
var event_1 = 'bav2b_click';
|
|
822
|
-
|
|
823
|
-
switch (eventType) {
|
|
824
|
-
case 'click':
|
|
825
|
-
event_1 = this.eventName['click'];
|
|
826
|
-
return getEventData(event_1, e, e.target, this.options, this.ignore);
|
|
827
|
-
|
|
828
|
-
case 'exposure':
|
|
829
|
-
event_1 = this.eventName['exposure'];
|
|
830
|
-
return getEventData(event_1, e, e.target, this.options, this.ignore);
|
|
831
|
-
|
|
832
|
-
case 'change':
|
|
833
|
-
event_1 = 'bav2b_change';
|
|
834
|
-
return __assign({}, getEventData(event_1, e, e.target, this.options), getExtraEventData(event_1, e.target));
|
|
835
|
-
|
|
836
|
-
case 'submit':
|
|
837
|
-
event_1 = 'bav2b_submit';
|
|
838
|
-
return getEventData(event_1, e, e.target, this.options);
|
|
839
|
-
}
|
|
840
|
-
} catch (err) {
|
|
841
|
-
console.error(err);
|
|
842
|
-
return null;
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
EventHandle.prototype.handleViewEvent = function (data) {
|
|
847
|
-
data.event = this.eventName['page'];
|
|
848
|
-
data.page_title = document.title;
|
|
849
|
-
data.page_total_width = window.innerWidth;
|
|
850
|
-
data.page_total_height = window.innerHeight;
|
|
851
|
-
|
|
852
|
-
try {
|
|
853
|
-
var cache = window.sessionStorage.getItem('_tea_cache_duration');
|
|
854
|
-
|
|
855
|
-
if (cache) {
|
|
856
|
-
var duration = JSON.parse(cache);
|
|
857
|
-
data.refer_page_duration_ms = duration ? duration.duration : '';
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
data.scroll_width = document.documentElement.scrollLeft ? document.documentElement.scrollLeft + window.innerWidth : window.innerWidth;
|
|
861
|
-
data.scroll_height = document.documentElement.scrollTop ? document.documentElement.scrollTop + window.innerHeight : window.innerHeight;
|
|
862
|
-
data.page_start_ms = window.performance.timing.navigationStart;
|
|
863
|
-
} catch (e) {
|
|
864
|
-
console.log("page event error " + JSON.stringify(e));
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
return data;
|
|
868
|
-
};
|
|
869
|
-
|
|
870
|
-
EventHandle.prototype.handleStatisticsEvent = function (data) {
|
|
871
|
-
var _data = {};
|
|
872
|
-
_data['event'] = this.eventName['static'];
|
|
873
|
-
_data['is_html'] = 1;
|
|
874
|
-
_data['page_key'] = location.href;
|
|
875
|
-
_data['refer_page_key'] = document.referrer || '';
|
|
876
|
-
_data['page_title'] = document.title;
|
|
877
|
-
_data['page_manual_key'] = this.initConfig.autotrack.page_manual_key || '';
|
|
878
|
-
_data['refer_page_manual_key'] = '';
|
|
879
|
-
|
|
880
|
-
try {
|
|
881
|
-
var lcp = data.lcp;
|
|
882
|
-
var timing = window.performance.timing;
|
|
883
|
-
var init_cos = timing.loadEventEnd - timing.navigationStart;
|
|
884
|
-
_data['page_init_cost_ms'] = parseInt(lcp || (init_cos > 0 ? init_cos : 0));
|
|
885
|
-
_data['page_start_ms'] = timing.navigationStart;
|
|
886
|
-
} catch (e) {
|
|
887
|
-
console.log("page_statistics event error " + JSON.stringify(e));
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
return _data;
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
EventHandle.prototype.handleBeadtEvent = function (data) {
|
|
894
|
-
data.event = this.eventName['beat'];
|
|
895
|
-
data.page_key = window.location.href;
|
|
896
|
-
data.is_html = 1;
|
|
897
|
-
data.page_title = document.title;
|
|
898
|
-
data.page_manual_key = this.initConfig.autotrack.page_manual_key || '';
|
|
899
|
-
|
|
900
|
-
try {
|
|
901
|
-
data.page_viewport_width = window.innerWidth;
|
|
902
|
-
data.page_viewport_height = window.innerHeight;
|
|
903
|
-
data.page_total_width = document.documentElement.scrollWidth;
|
|
904
|
-
data.page_total_height = document.documentElement.scrollHeight;
|
|
905
|
-
data.scroll_width = document.documentElement.scrollLeft + window.innerWidth;
|
|
906
|
-
data.scroll_height = document.documentElement.scrollTop + window.innerHeight;
|
|
907
|
-
data.since_page_start_ms = Date.now() - window.performance.timing.navigationStart;
|
|
908
|
-
data.page_start_ms = window.performance.timing.navigationStart;
|
|
909
|
-
} catch (e) {
|
|
910
|
-
console.log("beat event error " + JSON.stringify(e));
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
return data;
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
EventHandle.prototype.handleExposureEvent = function (eventInfo, e) {
|
|
917
|
-
if (ignore(e.target)) {
|
|
918
|
-
return null;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
var data = getEventData(eventInfo.event || this.eventName['exposure'], e, e.target || e, this.options, this.ignore);
|
|
922
|
-
data.$exposure_type = eventInfo.exposureType;
|
|
923
|
-
|
|
924
|
-
if (this.options.exposure.callback) {
|
|
925
|
-
var callData = this.options.exposure.callback(data);
|
|
926
|
-
|
|
927
|
-
if (!callData && !Object.keys(callData).length) {
|
|
928
|
-
console.warn('exposure callback must return data!');
|
|
929
|
-
return data;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
return callData;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
return data;
|
|
936
|
-
};
|
|
937
|
-
|
|
938
|
-
EventHandle.prototype.handleScrollEvent = function (eventInfo, e) {
|
|
939
|
-
var data = getEventData(eventInfo.event || this.eventName['scroll'], e, e.target || e, this.options, this.ignore);
|
|
940
|
-
data = Object.assign(data, eventInfo.params);
|
|
941
|
-
|
|
942
|
-
if (this.options.scroll.callback) {
|
|
943
|
-
data = this.options.scroll.callback(data);
|
|
944
|
-
|
|
945
|
-
if (!data && !Object.keys(data).length) {
|
|
946
|
-
console.warn('scroll callback must return data!');
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
return data;
|
|
952
|
-
};
|
|
953
|
-
|
|
954
|
-
return EventHandle;
|
|
955
|
-
}();
|
|
956
|
-
|
|
957
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
958
|
-
var Request =
|
|
959
|
-
/** @class */
|
|
960
|
-
function () {
|
|
961
|
-
function Request(collect) {
|
|
962
|
-
this.collect = collect;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
Request.prototype.send = function (eventInfo, data) {
|
|
966
|
-
var event = data['event'];
|
|
967
|
-
delete data['event'];
|
|
968
|
-
|
|
969
|
-
if (eventInfo && eventInfo.eventSend === 'becon') {
|
|
970
|
-
this.collect.beconEvent(event, data);
|
|
971
|
-
} else {
|
|
972
|
-
this.collect.event(event, data);
|
|
973
|
-
}
|
|
974
|
-
};
|
|
975
|
-
|
|
976
|
-
Request.prototype.get = function (url, options) {
|
|
977
|
-
var reqOptions = {
|
|
978
|
-
headers: {
|
|
979
|
-
'content-type': 'application/json'
|
|
980
|
-
},
|
|
981
|
-
method: 'GET'
|
|
982
|
-
};
|
|
983
|
-
var myOptions = Object.assign(reqOptions, options);
|
|
984
|
-
fetch(url, myOptions);
|
|
985
|
-
};
|
|
986
|
-
|
|
987
|
-
Request.prototype.post = function (url, options) {
|
|
988
|
-
var reqOptions = {
|
|
989
|
-
headers: {
|
|
990
|
-
'content-type': 'application/json'
|
|
991
|
-
},
|
|
992
|
-
method: 'POST'
|
|
993
|
-
};
|
|
994
|
-
var myOptions = Object.assign(reqOptions, options);
|
|
995
|
-
fetch(url, myOptions);
|
|
996
|
-
};
|
|
997
|
-
|
|
998
|
-
return Request;
|
|
999
|
-
}();
|
|
1000
|
-
|
|
1001
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1002
|
-
// 监视曝光的上层类 处理动态dom
|
|
1003
|
-
var Observer =
|
|
1004
|
-
/** @class */
|
|
1005
|
-
function () {
|
|
1006
|
-
function Observer(intersection, config) {
|
|
1007
|
-
this._instance = null;
|
|
1008
|
-
this._intersection = intersection;
|
|
1009
|
-
this.config = config;
|
|
1010
|
-
if (!this._intersection) return;
|
|
1011
|
-
this.init();
|
|
1012
|
-
} // 初始化mutation对象观察动态dom
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
Observer.prototype.init = function () {
|
|
1016
|
-
var _this = this;
|
|
1017
|
-
|
|
1018
|
-
if (window['MutationObserver']) {
|
|
1019
|
-
try {
|
|
1020
|
-
this._instance = new MutationObserver(function (mutations) {
|
|
1021
|
-
mutations.forEach(function (mutation) {
|
|
1022
|
-
// 更新dom节点可能是update,只是属性改变,需要监听
|
|
1023
|
-
if (mutation.type === 'attributes') {
|
|
1024
|
-
_this.attributeChangeObserve(mutation);
|
|
1025
|
-
} // dom节点变化
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
if (mutation.type === 'childList') {
|
|
1029
|
-
_this.modifyNodeObserve(mutation);
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
|
|
1034
|
-
if (!document || !document.body) {
|
|
1035
|
-
console.warn('please use sdk api init after body element');
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
var attributes = this.config.autotrack.exposure.attributes === false ? false : true;
|
|
1040
|
-
|
|
1041
|
-
this._instance.observe(document.body, {
|
|
1042
|
-
childList: true,
|
|
1043
|
-
attributes: attributes,
|
|
1044
|
-
subtree: true,
|
|
1045
|
-
attributeOldValue: false
|
|
1046
|
-
});
|
|
1047
|
-
} catch (e) {
|
|
1048
|
-
console.log('your browser cannot support MutationObserver,so cannot report exposure event, please update');
|
|
1049
|
-
}
|
|
1050
|
-
} else {
|
|
1051
|
-
console.log('your browser cannot support MutationObserver,so cannot report exposure event, please update');
|
|
1052
|
-
}
|
|
1053
|
-
}; // 监听dom属性变化添加或删除节点曝光监听
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
Observer.prototype.attributeChangeObserve = function (mutation) {
|
|
1057
|
-
var dom = mutation.target;
|
|
1058
|
-
|
|
1059
|
-
if (dom.hasAttribute('data-exposure')) {
|
|
1060
|
-
this.exposureAdd(mutation, 'mutation');
|
|
1061
|
-
} else {
|
|
1062
|
-
this.exposureRemove(mutation);
|
|
1063
|
-
}
|
|
1064
|
-
}; // 监听dom变化添加或删除节点曝光监听
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
Observer.prototype.modifyNodeObserve = function (mutation) {
|
|
1068
|
-
var _this = this; // 不能为文本节点&&要有auto-exp属性
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
Array.prototype.forEach.call(mutation.addedNodes, function (node) {
|
|
1072
|
-
if (node.nodeType === 1 && node.hasAttribute('data-exposure')) {
|
|
1073
|
-
_this.exposureAdd(node, 'intersect');
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
_this.mapChild(node, _this.exposureAdd.bind(_this));
|
|
1077
|
-
}); // 遍历子节点的删除
|
|
1078
|
-
|
|
1079
|
-
Array.prototype.forEach.call(mutation.removedNodes, function (node) {
|
|
1080
|
-
if (node.nodeType === 1 && node.hasAttribute('data-exposure')) {
|
|
1081
|
-
_this.exposureRemove(node);
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
_this.mapChild(node, _this.exposureRemove.bind(_this));
|
|
1085
|
-
});
|
|
1086
|
-
}; // 递归后代节点
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
Observer.prototype.mapChild = function (node, action) {
|
|
1090
|
-
var _this = this;
|
|
1091
|
-
|
|
1092
|
-
if (node.nodeType !== 1) {
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if (!node.children.length) {
|
|
1097
|
-
return;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
Array.prototype.forEach.call(node.children, function (item) {
|
|
1101
|
-
if (item.nodeType === 1 && item.hasAttribute('data-exposure')) {
|
|
1102
|
-
action(item);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
_this.mapChild(item, action);
|
|
1106
|
-
});
|
|
1107
|
-
}; // 添加进入曝光队列
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
Observer.prototype.exposureAdd = function (dom, type) {
|
|
1111
|
-
try {
|
|
1112
|
-
this._intersection && this._intersection.exposureAdd(dom, type);
|
|
1113
|
-
} catch (e) {
|
|
1114
|
-
console.log('intersection error', JSON.stringify(e.message));
|
|
1115
|
-
}
|
|
1116
|
-
}; // 从曝光队列中移除
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
Observer.prototype.exposureRemove = function (dom) {
|
|
1120
|
-
try {
|
|
1121
|
-
this._intersection && this._intersection.exposureRemove(dom);
|
|
1122
|
-
} catch (e) {
|
|
1123
|
-
console.log('intersection error', JSON.stringify(e.message));
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
Observer._exposure_observer = null;
|
|
1128
|
-
return Observer;
|
|
1129
|
-
}();
|
|
1130
|
-
|
|
1131
|
-
var b = function b(a) {
|
|
1132
|
-
return a ? (a ^ Math.random() * 16 >> a / 4).toString(10) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
|
|
1133
|
-
};
|
|
1134
|
-
var localWebId = function localWebId() {
|
|
1135
|
-
return b().replace(/-/g, '').slice(0, 19);
|
|
1136
|
-
};
|
|
1137
|
-
|
|
1138
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1139
|
-
var ExposureTypeE;
|
|
1140
|
-
|
|
1141
|
-
(function (ExposureTypeE) {
|
|
1142
|
-
ExposureTypeE[ExposureTypeE["EXPOSURE_ONCE"] = 0] = "EXPOSURE_ONCE";
|
|
1143
|
-
ExposureTypeE[ExposureTypeE["LIFECYCLE_SHOW_NEW"] = 3] = "LIFECYCLE_SHOW_NEW";
|
|
1144
|
-
ExposureTypeE[ExposureTypeE["RESUME_FORM_PAGE"] = 6] = "RESUME_FORM_PAGE";
|
|
1145
|
-
ExposureTypeE[ExposureTypeE["RESUME_FORM_BACK"] = 7] = "RESUME_FORM_BACK";
|
|
1146
|
-
ExposureTypeE[ExposureTypeE["NOT_EXPOSURE"] = -1] = "NOT_EXPOSURE";
|
|
1147
|
-
})(ExposureTypeE || (ExposureTypeE = {}));
|
|
1148
|
-
|
|
1149
|
-
var Intersection =
|
|
1150
|
-
/** @class */
|
|
1151
|
-
function () {
|
|
1152
|
-
function Intersection(collect, config, eventHandle) {
|
|
1153
|
-
var _this = this;
|
|
1154
|
-
|
|
1155
|
-
this.backStatus = false;
|
|
1156
|
-
this.instance = this.buildObserver();
|
|
1157
|
-
this.collect = collect;
|
|
1158
|
-
this.observeMap = Intersection._observer_map;
|
|
1159
|
-
|
|
1160
|
-
if (config.autotrack.exposure.ratio) {
|
|
1161
|
-
this.ratio = config.autotrack.exposure.ratio;
|
|
1162
|
-
} else if (config.autotrack.exposure.ratio === 0) {
|
|
1163
|
-
this.ratio = 0;
|
|
1164
|
-
} else {
|
|
1165
|
-
this.ratio = 0.5;
|
|
1166
|
-
} // 元素出现的时长,有值则等待,无值则立刻曝光
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
this.timeLimit = config.autotrack.exposure.stay || 0;
|
|
1170
|
-
this.exposureType = ExposureTypeE.NOT_EXPOSURE;
|
|
1171
|
-
this.eventHandle = eventHandle;
|
|
1172
|
-
this.hashMap = new Map();
|
|
1173
|
-
this.backStatus = false;
|
|
1174
|
-
this.lastState = null;
|
|
1175
|
-
this.collect.on('re-start-sdk', function () {
|
|
1176
|
-
_this.visibilitychange();
|
|
1177
|
-
});
|
|
1178
|
-
this.addListen();
|
|
1179
|
-
} // dom元素出现在视窗,出现回调;
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
Intersection.prototype.buildObserver = function () {
|
|
1183
|
-
var _this = this;
|
|
1184
|
-
|
|
1185
|
-
if (!Intersection._observer_instance) {
|
|
1186
|
-
if (window['IntersectionObserver']) {
|
|
1187
|
-
var threshold = [];
|
|
1188
|
-
|
|
1189
|
-
for (var i = 0; i <= 1.0; i += 0.01) {
|
|
1190
|
-
threshold.push(i);
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
threshold.push(1);
|
|
1194
|
-
|
|
1195
|
-
try {
|
|
1196
|
-
Intersection._observer_instance = new IntersectionObserver(function (entries) {
|
|
1197
|
-
entries.forEach(function (entry) {
|
|
1198
|
-
var elememtMapKey = entry.target['observeId'];
|
|
1199
|
-
|
|
1200
|
-
var exposureDom = _this.observeMap.get(elememtMapKey);
|
|
1201
|
-
|
|
1202
|
-
var target = entry.target,
|
|
1203
|
-
isIntersecting = entry.isIntersecting,
|
|
1204
|
-
intersectionRatio = entry.intersectionRatio;
|
|
1205
|
-
exposureDom.intersectionRatio = intersectionRatio;
|
|
1206
|
-
|
|
1207
|
-
if (intersectionRatio <= 0.1) {
|
|
1208
|
-
// 离开曝光区
|
|
1209
|
-
entry.target['backStatus'] = false;
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1213
|
-
|
|
1214
|
-
if (intersectionRatio < _this.ratio) {
|
|
1215
|
-
exposureDom.isIntersecting = false;
|
|
1216
|
-
exposureDom.added = false;
|
|
1217
|
-
exposureDom.exposured = false;
|
|
1218
|
-
exposureDom.startTime = Date.now();
|
|
1219
|
-
|
|
1220
|
-
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1221
|
-
|
|
1222
|
-
return;
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
if (!exposureDom.added) {
|
|
1226
|
-
exposureDom.startTime = Date.now(); // 元素交互时处理一次,为false或者undefined的代表没有处理过
|
|
1227
|
-
|
|
1228
|
-
exposureDom.added = true;
|
|
1229
|
-
exposureDom.isIntersecting = true;
|
|
1230
|
-
|
|
1231
|
-
if (_this.timeLimit) {
|
|
1232
|
-
var exposureTimeout = setTimeout(function () {
|
|
1233
|
-
try {
|
|
1234
|
-
if (exposureDom.isIntersecting && !exposureDom.exposured && _this.observeMap.get(elememtMapKey)) {
|
|
1235
|
-
var intersectionRatio_1 = _this.observeMap.get(elememtMapKey).intersectionRatio;
|
|
1236
|
-
|
|
1237
|
-
_this.exposureEvent(entry, intersectionRatio_1, elememtMapKey, exposureDom); // this.eventHandle({ eventType: 'dom', eventName: 'exposure' }, entry)
|
|
1238
|
-
|
|
1239
|
-
}
|
|
1240
|
-
} catch (e) {
|
|
1241
|
-
console.log("IntersectionObserver setTimeout error\uFF0Cmsg: " + JSON.stringify(e));
|
|
1242
|
-
}
|
|
1243
|
-
}, _this.timeLimit);
|
|
1244
|
-
exposureDom.wait = exposureTimeout;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
_this.observeMap.set(elememtMapKey, exposureDom);
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
if (Date.now() - exposureDom.startTime >= _this.timeLimit && !exposureDom.exposured) {
|
|
1251
|
-
_this.exposureEvent(entry, intersectionRatio, elememtMapKey, exposureDom);
|
|
1252
|
-
}
|
|
1253
|
-
});
|
|
1254
|
-
}, {
|
|
1255
|
-
threshold: threshold
|
|
1256
|
-
});
|
|
1257
|
-
} catch (e) {
|
|
1258
|
-
console.log("IntersectionObserver error\uFF0Cmsg: " + JSON.stringify(e));
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
return Intersection._observer_instance;
|
|
1262
|
-
} else {
|
|
1263
|
-
console.log('your browser cannot support IntersectionObserver, so cannot report exposure event, please update');
|
|
1264
|
-
return null;
|
|
1265
|
-
}
|
|
1266
|
-
} else {
|
|
1267
|
-
console.log('your browser cannot support IntersectionObserver, so cannot report exposure event, please update');
|
|
1268
|
-
return null;
|
|
1269
|
-
}
|
|
1270
|
-
}; // 添加进入曝光队列
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
Intersection.prototype.exposureAdd = function (dom, type) {
|
|
1274
|
-
var trueDom = type === 'mutation' ? dom.target : dom;
|
|
1275
|
-
var elememtMapKey = trueDom['observeId'];
|
|
1276
|
-
var domId = localWebId();
|
|
1277
|
-
|
|
1278
|
-
if (!elememtMapKey && !this.observeMap.has(elememtMapKey)) {
|
|
1279
|
-
trueDom['observeId'] = domId;
|
|
1280
|
-
trueDom['visible'] = false;
|
|
1281
|
-
this.observeMap.set(domId, {
|
|
1282
|
-
instance: trueDom.cloneNode(true),
|
|
1283
|
-
isIntersecting: false
|
|
1284
|
-
});
|
|
1285
|
-
this.observe(trueDom);
|
|
1286
|
-
} else {
|
|
1287
|
-
var exposureDom = this.observeMap.get(elememtMapKey);
|
|
1288
|
-
|
|
1289
|
-
if (exposureDom && trueDom !== exposureDom.instance) {
|
|
1290
|
-
// 有id,但实例变了
|
|
1291
|
-
this.unobserve(trueDom);
|
|
1292
|
-
this.observeMap["delete"](elememtMapKey);
|
|
1293
|
-
trueDom['observeId'] = domId;
|
|
1294
|
-
trueDom['visible'] = false;
|
|
1295
|
-
this.observeMap.set(domId, {
|
|
1296
|
-
instance: trueDom.cloneNode(true),
|
|
1297
|
-
isIntersecting: false
|
|
1298
|
-
});
|
|
1299
|
-
this.observe(trueDom);
|
|
1300
|
-
} else {
|
|
1301
|
-
if (trueDom['visible'] === true) return;
|
|
1302
|
-
this.handleBoundingExposure(trueDom);
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
}; // 从曝光队列中移除
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
Intersection.prototype.exposureRemove = function (dom) {
|
|
1309
|
-
if (this.observeMap.has(dom['observeId'])) {
|
|
1310
|
-
this.observeMap["delete"](dom['observeId']);
|
|
1311
|
-
this.unobserve(dom);
|
|
1312
|
-
dom['observeId'] = '';
|
|
1313
|
-
dom['visible'] = false;
|
|
1314
|
-
}
|
|
1315
|
-
};
|
|
1316
|
-
|
|
1317
|
-
Intersection.prototype.exposureEvent = function (entry, intersectionRatio, elememtMapKey, exposureDom) {
|
|
1318
|
-
if (intersectionRatio >= this.ratio) {
|
|
1319
|
-
if (entry.target.style.opacity === '0' || entry.target.style.visibility === 'hidden') return; // if (entry.target.visible === true || exposureDom.exposured === true) return;
|
|
1320
|
-
|
|
1321
|
-
if (exposureDom.exposured === true) return;
|
|
1322
|
-
|
|
1323
|
-
if (exposureDom.startWait) {
|
|
1324
|
-
// 元素有定时器
|
|
1325
|
-
clearTimeout(exposureDom.startWait);
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
var event_1 = entry.target.getAttribute('data-exposure-event');
|
|
1329
|
-
this.eventHandle({
|
|
1330
|
-
eventType: 'dom',
|
|
1331
|
-
eventName: 'exposure',
|
|
1332
|
-
event: event_1,
|
|
1333
|
-
exposureType: this.getExposureType(entry.target)
|
|
1334
|
-
}, entry);
|
|
1335
|
-
entry.target.visible = true;
|
|
1336
|
-
entry.target.hasExposure = true;
|
|
1337
|
-
exposureDom.startTime = Date.now();
|
|
1338
|
-
exposureDom.exposured = true;
|
|
1339
|
-
} else {
|
|
1340
|
-
exposureDom.startTime = Date.now();
|
|
1341
|
-
exposureDom.exposured = false; // entry.target.visible = false;
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
this.observeMap.set(elememtMapKey, exposureDom);
|
|
1345
|
-
};
|
|
1346
|
-
|
|
1347
|
-
Intersection.prototype.observe = function (dom) {
|
|
1348
|
-
this.instance && this.instance.observe(dom);
|
|
1349
|
-
};
|
|
1350
|
-
|
|
1351
|
-
Intersection.prototype.unobserve = function (dom) {
|
|
1352
|
-
this.instance && this.instance.unobserve(dom);
|
|
1353
|
-
};
|
|
1354
|
-
|
|
1355
|
-
Intersection.prototype.getExposureDomToExposure = function () {
|
|
1356
|
-
var _this = this;
|
|
1357
|
-
|
|
1358
|
-
Array.prototype.forEach.call(document.querySelectorAll('[data-exposure]'), function (dom) {
|
|
1359
|
-
_this.handleBoundingExposure(dom);
|
|
1360
|
-
});
|
|
1361
|
-
};
|
|
1362
|
-
|
|
1363
|
-
Intersection.prototype.visibilitychange = function () {
|
|
1364
|
-
var _this = this;
|
|
1365
|
-
|
|
1366
|
-
var visTime = null;
|
|
1367
|
-
|
|
1368
|
-
if (document.visibilityState === 'visible') {
|
|
1369
|
-
// 重置时间
|
|
1370
|
-
if (this.timeLimit) {
|
|
1371
|
-
visTime = setTimeout(function () {
|
|
1372
|
-
_this.getExposureDomToExposure();
|
|
1373
|
-
}, this.timeLimit);
|
|
1374
|
-
} else {
|
|
1375
|
-
this.getExposureDomToExposure();
|
|
1376
|
-
}
|
|
1377
|
-
} else {
|
|
1378
|
-
clearTimeout(visTime); // 页面隐藏了,可能是最小化,新开webview,等等
|
|
1379
|
-
|
|
1380
|
-
this.customType = undefined;
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
|
|
1384
|
-
Intersection.prototype.handleBoundingExposure = function (dom) {
|
|
1385
|
-
// 处理非IntersectionObserver触发条件下的曝光
|
|
1386
|
-
if (this.getBoundingRatio(dom) >= this.ratio) {
|
|
1387
|
-
dom['visible'] = true;
|
|
1388
|
-
var event_2 = dom.getAttribute && dom.getAttribute('data-exposure-event');
|
|
1389
|
-
this.eventHandle({
|
|
1390
|
-
eventType: 'dom',
|
|
1391
|
-
eventName: 'exposure',
|
|
1392
|
-
event: event_2,
|
|
1393
|
-
exposureType: this.customType || ExposureTypeE.RESUME_FORM_BACK
|
|
1394
|
-
}, dom);
|
|
1395
|
-
}
|
|
1396
|
-
};
|
|
1397
|
-
|
|
1398
|
-
Intersection.prototype.getBoundingRatio = function (dom) {
|
|
1399
|
-
var _a = dom.getBoundingClientRect(),
|
|
1400
|
-
top = _a.top,
|
|
1401
|
-
left = _a.left,
|
|
1402
|
-
width = _a.width,
|
|
1403
|
-
height = _a.height;
|
|
1404
|
-
|
|
1405
|
-
var viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
1406
|
-
var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
1407
|
-
var elementArea = width * height;
|
|
1408
|
-
|
|
1409
|
-
if (top >= 0 && left >= 0 && top <= viewportHeight && left <= viewportWidth) {
|
|
1410
|
-
// 首先判断元素是否能看见
|
|
1411
|
-
var viewWidth = width > viewportWidth ? viewportWidth : width;
|
|
1412
|
-
var viewHeight = viewportHeight - top;
|
|
1413
|
-
var viewArea = viewWidth * viewHeight;
|
|
1414
|
-
return viewArea / elementArea;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
return 0;
|
|
1418
|
-
};
|
|
1419
|
-
|
|
1420
|
-
Intersection.prototype.getExposureType = function (target) {
|
|
1421
|
-
if (target.visible) {
|
|
1422
|
-
// 多页面的重复曝光
|
|
1423
|
-
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1424
|
-
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1425
|
-
} else {
|
|
1426
|
-
this.exposureType = ExposureTypeE.LIFECYCLE_SHOW_NEW;
|
|
1427
|
-
}
|
|
1428
|
-
} else {
|
|
1429
|
-
if (target.hasExposure) {
|
|
1430
|
-
// 单页面的重复
|
|
1431
|
-
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1432
|
-
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1433
|
-
} else {
|
|
1434
|
-
this.exposureType = ExposureTypeE.EXPOSURE_ONCE;
|
|
1435
|
-
}
|
|
1436
|
-
} else {
|
|
1437
|
-
if (target.backStatus !== false && (this.backStatus || this.customType || window.performance.navigation.type === 2)) {
|
|
1438
|
-
this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1439
|
-
} else {
|
|
1440
|
-
this.exposureType = ExposureTypeE.EXPOSURE_ONCE;
|
|
1441
|
-
}
|
|
1442
|
-
} // this.exposureType = ExposureTypeE.EXPOSURE_ONCE
|
|
1443
|
-
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
return this.exposureType;
|
|
1447
|
-
};
|
|
1448
|
-
|
|
1449
|
-
Intersection.prototype.addListen = function () {
|
|
1450
|
-
var _this = this;
|
|
1451
|
-
|
|
1452
|
-
this.collect.on('set-exposure-type', function (type) {
|
|
1453
|
-
_this.customType = type;
|
|
1454
|
-
});
|
|
1455
|
-
var change = this.visibilitychange.bind(this);
|
|
1456
|
-
addListener(document, 'visibilitychange', change, false);
|
|
1457
|
-
window.addEventListener("hashchange", function (hash) {
|
|
1458
|
-
var current = _this.hashMap.get(hash.oldURL);
|
|
1459
|
-
|
|
1460
|
-
if (current && location.href === current.prev) {
|
|
1461
|
-
_this.backStatus = true;
|
|
1462
|
-
_this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1463
|
-
} else {
|
|
1464
|
-
_this.backStatus = false;
|
|
1465
|
-
|
|
1466
|
-
_this.hashMap.set(location.href, {
|
|
1467
|
-
current: hash.newURL,
|
|
1468
|
-
prev: hash.oldURL
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
});
|
|
1472
|
-
|
|
1473
|
-
if (this.collect.bridgeReport) {
|
|
1474
|
-
var oldPushState_1 = window.history.pushState;
|
|
1475
|
-
|
|
1476
|
-
history.pushState = function (state) {
|
|
1477
|
-
var args = [];
|
|
1478
|
-
|
|
1479
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1480
|
-
args[_i - 1] = arguments[_i];
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
if (typeof history['onpushstate'] === 'function') {
|
|
1484
|
-
history['onpushstate']({
|
|
1485
|
-
state: state
|
|
1486
|
-
});
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
var ret = oldPushState_1.call.apply(oldPushState_1, __spread([history, state], args));
|
|
1490
|
-
_this.lastState = state;
|
|
1491
|
-
return ret;
|
|
1492
|
-
};
|
|
1493
|
-
|
|
1494
|
-
var oldReplaceState_1 = history.replaceState;
|
|
1495
|
-
|
|
1496
|
-
history.replaceState = function (state) {
|
|
1497
|
-
var args = [];
|
|
1498
|
-
|
|
1499
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
1500
|
-
args[_i - 1] = arguments[_i];
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
if (typeof history['onreplacestate'] === 'function') {
|
|
1504
|
-
history['onreplacestate']({
|
|
1505
|
-
state: state
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
var ret = oldReplaceState_1.call.apply(oldReplaceState_1, __spread([history, state], args));
|
|
1510
|
-
_this.lastState = state;
|
|
1511
|
-
return ret;
|
|
1512
|
-
};
|
|
1513
|
-
} else {
|
|
1514
|
-
this.collect.on('STATE_CHANGE', function (state) {
|
|
1515
|
-
_this.lastState = state;
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
window.addEventListener('popstate', function (state) {
|
|
1520
|
-
var currentState = state.state;
|
|
1521
|
-
|
|
1522
|
-
if (currentState && currentState.current && _this.lastState && _this.lastState.back && currentState.current === _this.lastState.back) {
|
|
1523
|
-
// 用户点击了“退回”按钮
|
|
1524
|
-
_this.backStatus = true;
|
|
1525
|
-
_this.exposureType = ExposureTypeE.RESUME_FORM_PAGE;
|
|
1526
|
-
} else {
|
|
1527
|
-
_this.backStatus = false;
|
|
1528
|
-
}
|
|
1529
|
-
});
|
|
1530
|
-
return function () {
|
|
1531
|
-
removeListener(document, 'visibilitychange', change, false);
|
|
1532
|
-
};
|
|
1533
|
-
};
|
|
1534
|
-
|
|
1535
|
-
Intersection._observer_instance = null;
|
|
1536
|
-
Intersection._observer_map = new Map();
|
|
1537
|
-
return Intersection;
|
|
1538
|
-
}();
|
|
1539
|
-
|
|
1540
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1541
|
-
|
|
1542
|
-
var Exposure =
|
|
1543
|
-
/** @class */
|
|
1544
|
-
function () {
|
|
1545
|
-
function Exposure(collect, config, eventHandle) {
|
|
1546
|
-
if (!config.autotrack || !config.autotrack.exposure) return;
|
|
1547
|
-
this._intersection = new Intersection(collect, config, eventHandle);
|
|
1548
|
-
this._observer = new Observer(this._intersection, config);
|
|
1549
|
-
|
|
1550
|
-
if (this._intersection && this._observer) {
|
|
1551
|
-
this.initObserver();
|
|
1552
|
-
} else {
|
|
1553
|
-
console.log('your browser version cannot support exposure event, please update~');
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
Exposure.prototype.initObserver = function () {
|
|
1558
|
-
var self = this;
|
|
1559
|
-
Array.prototype.forEach.call(document.querySelectorAll('[data-exposure]'), function (dom) {
|
|
1560
|
-
self._intersection.exposureAdd(dom, 'intersect');
|
|
1561
|
-
});
|
|
1562
|
-
};
|
|
1563
|
-
|
|
1564
|
-
return Exposure;
|
|
1565
|
-
}();
|
|
1566
|
-
|
|
1567
|
-
var ScrollTypeE;
|
|
1568
|
-
|
|
1569
|
-
(function (ScrollTypeE) {
|
|
1570
|
-
ScrollTypeE[ScrollTypeE["SCROLL_UP"] = 1] = "SCROLL_UP";
|
|
1571
|
-
ScrollTypeE[ScrollTypeE["SCROLL_DOWN"] = 2] = "SCROLL_DOWN";
|
|
1572
|
-
ScrollTypeE[ScrollTypeE["SCROLL_LEFT"] = 3] = "SCROLL_LEFT";
|
|
1573
|
-
ScrollTypeE[ScrollTypeE["SCROLL_RIGHT"] = 4] = "SCROLL_RIGHT";
|
|
1574
|
-
ScrollTypeE[ScrollTypeE["NOT_SCROLL"] = -1] = "NOT_SCROLL";
|
|
1575
|
-
})(ScrollTypeE || (ScrollTypeE = {}));
|
|
1576
|
-
|
|
1577
|
-
var ScrollSlide =
|
|
1578
|
-
/** @class */
|
|
1579
|
-
function () {
|
|
1580
|
-
function ScrollSlide(config, eventHandle) {
|
|
1581
|
-
this.distance = 30;
|
|
1582
|
-
if (!config.autotrack || !config.autotrack.scroll) return;
|
|
1583
|
-
|
|
1584
|
-
if (config.autotrack.scroll.distance) {
|
|
1585
|
-
this.distance = config.autotrack.scroll.distance;
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
this.eventHandle = eventHandle;
|
|
1589
|
-
this.addLinstenr();
|
|
1590
|
-
this.mutation();
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
ScrollSlide.prototype.addLinstenr = function () {
|
|
1594
|
-
var _this = this;
|
|
1595
|
-
|
|
1596
|
-
Array.prototype.forEach.call(document.querySelectorAll('[data-scroll]'), function (dom) {
|
|
1597
|
-
_this.scrollHandle(dom);
|
|
1598
|
-
});
|
|
1599
|
-
};
|
|
1600
|
-
|
|
1601
|
-
ScrollSlide.prototype.mutation = function () {
|
|
1602
|
-
var _this = this;
|
|
1603
|
-
|
|
1604
|
-
if (window['MutationObserver']) {
|
|
1605
|
-
try {
|
|
1606
|
-
var instance = new MutationObserver(function (mutations) {
|
|
1607
|
-
mutations.forEach(function (mutation) {
|
|
1608
|
-
// 更新dom节点可能是update,只是属性改变,需要监听
|
|
1609
|
-
// if (mutation.type === 'attributes') {
|
|
1610
|
-
// this.attributeChangeObserve(mutation);
|
|
1611
|
-
// }
|
|
1612
|
-
// dom节点变化
|
|
1613
|
-
if (mutation.type === 'childList') {
|
|
1614
|
-
_this.modifyNodeObserve(mutation);
|
|
1615
|
-
}
|
|
1616
|
-
});
|
|
1617
|
-
});
|
|
1618
|
-
|
|
1619
|
-
if (!document || !document.body) {
|
|
1620
|
-
console.warn('please use sdk api init after body element');
|
|
1621
|
-
return;
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
instance.observe(document.body, {
|
|
1625
|
-
childList: true,
|
|
1626
|
-
attributes: true,
|
|
1627
|
-
subtree: true,
|
|
1628
|
-
attributeOldValue: false
|
|
1629
|
-
});
|
|
1630
|
-
} catch (e) {
|
|
1631
|
-
console.log('your browser cannot support MutationObserver');
|
|
1632
|
-
}
|
|
1633
|
-
} else {
|
|
1634
|
-
console.log('your browser cannot support MutationObserver');
|
|
1635
|
-
}
|
|
1636
|
-
}; // 监听dom属性变化添加或删除节点曝光监听
|
|
1637
|
-
// attributeChangeObserve(mutation) {
|
|
1638
|
-
// const dom = mutation.target;
|
|
1639
|
-
// if (dom.hasAttribute('data-scroll')) {
|
|
1640
|
-
// this.scrollHandle(mutation);
|
|
1641
|
-
// }
|
|
1642
|
-
// }
|
|
1643
|
-
// 监听dom变化添加或删除节点曝光监听
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
ScrollSlide.prototype.modifyNodeObserve = function (mutation) {
|
|
1647
|
-
var _this = this; // 不能为文本节点&&要有auto-exp属性
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
Array.prototype.forEach.call(mutation.addedNodes, function (node) {
|
|
1651
|
-
if (node.nodeType === 1 && node.hasAttribute('data-scroll')) {
|
|
1652
|
-
_this.scrollHandle(node);
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
_this.mapChild(node, _this.scrollHandle.bind(_this));
|
|
1656
|
-
}); // 遍历子节点的删除
|
|
1657
|
-
|
|
1658
|
-
Array.prototype.forEach.call(mutation.removedNodes, function (node) {
|
|
1659
|
-
if (node.nodeType === 1 && node.hasAttribute('data-scroll')) {
|
|
1660
|
-
_this.scrollHandle(node, 'remove');
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
_this.mapChild(node, _this.scrollHandle.bind(_this));
|
|
1664
|
-
});
|
|
1665
|
-
}; // 递归后代节点
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
ScrollSlide.prototype.mapChild = function (node, action) {
|
|
1669
|
-
var _this = this;
|
|
1670
|
-
|
|
1671
|
-
if (node.nodeType !== 1) {
|
|
1672
|
-
return;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
if (!node.children.length) {
|
|
1676
|
-
return;
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
Array.prototype.forEach.call(node.children, function (item) {
|
|
1680
|
-
if (item.nodeType === 1 && item.hasAttribute('data-scroll')) {
|
|
1681
|
-
action(item);
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
_this.mapChild(item, action);
|
|
1685
|
-
});
|
|
1686
|
-
};
|
|
1687
|
-
|
|
1688
|
-
ScrollSlide.prototype.scrollHandle = function (dom, type) {
|
|
1689
|
-
var _this = this;
|
|
1690
|
-
|
|
1691
|
-
try {
|
|
1692
|
-
var preScrollTop_1 = dom.scrollTop;
|
|
1693
|
-
var preScrollLeft_1 = dom.scrollLeft;
|
|
1694
|
-
var timer_1 = null;
|
|
1695
|
-
var $offsetX_1 = 0;
|
|
1696
|
-
var $offsetY_1 = 0;
|
|
1697
|
-
|
|
1698
|
-
var scrollFn_1 = function scrollFn_1(e) {
|
|
1699
|
-
clearTimeout(timer_1);
|
|
1700
|
-
timer_1 = setTimeout(function () {
|
|
1701
|
-
var finalScrollTop = dom.scrollTop;
|
|
1702
|
-
var finalScrollLeft = dom.scrollLeft;
|
|
1703
|
-
var event = e.target && e.target['getAttribute']('data-scroll-event') || '';
|
|
1704
|
-
|
|
1705
|
-
if (scrollDirection === 1 || scrollDirection === 2) {
|
|
1706
|
-
if (finalScrollTop === currentScrollTop) {
|
|
1707
|
-
// 滚动停止了
|
|
1708
|
-
$offsetY_1 = currentScrollTop - preScrollTop_1;
|
|
1709
|
-
|
|
1710
|
-
if (Math.abs($offsetY_1) >= _this.distance && _this.distance) {
|
|
1711
|
-
_this.eventHandle({
|
|
1712
|
-
eventType: 'dom',
|
|
1713
|
-
eventName: 'scroll',
|
|
1714
|
-
event: event,
|
|
1715
|
-
params: {
|
|
1716
|
-
$direction: scrollDirection,
|
|
1717
|
-
$offsetY: $offsetY_1,
|
|
1718
|
-
$offsetX: $offsetX_1
|
|
1719
|
-
}
|
|
1720
|
-
}, e);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
} else if (scrollDirection === 3 || scrollDirection === 4) {
|
|
1724
|
-
if (finalScrollLeft === currentScrollLeft) {
|
|
1725
|
-
// 滚动停止了
|
|
1726
|
-
$offsetX_1 = currentScrollLeft - preScrollLeft_1;
|
|
1727
|
-
|
|
1728
|
-
if (Math.abs($offsetX_1) >= _this.distance && _this.distance) {
|
|
1729
|
-
_this.eventHandle({
|
|
1730
|
-
eventType: 'dom',
|
|
1731
|
-
eventName: 'scroll',
|
|
1732
|
-
event: event,
|
|
1733
|
-
params: {
|
|
1734
|
-
$direction: scrollDirection,
|
|
1735
|
-
$offsetY: $offsetY_1,
|
|
1736
|
-
$offsetX: $offsetX_1
|
|
1737
|
-
}
|
|
1738
|
-
}, e);
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
preScrollTop_1 = currentScrollTop;
|
|
1744
|
-
preScrollLeft_1 = currentScrollLeft;
|
|
1745
|
-
}, 100);
|
|
1746
|
-
var currentScrollTop = dom.scrollTop;
|
|
1747
|
-
var currentScrollLeft = dom.scrollLeft;
|
|
1748
|
-
var scrollDirection = ScrollTypeE.NOT_SCROLL;
|
|
1749
|
-
|
|
1750
|
-
if (currentScrollTop > preScrollTop_1) {
|
|
1751
|
-
scrollDirection = ScrollTypeE.SCROLL_DOWN;
|
|
1752
|
-
} else if (currentScrollTop < preScrollTop_1) {
|
|
1753
|
-
scrollDirection = ScrollTypeE.SCROLL_UP;
|
|
1754
|
-
} else {
|
|
1755
|
-
if (currentScrollLeft > preScrollLeft_1) {
|
|
1756
|
-
scrollDirection = ScrollTypeE.SCROLL_LEFT;
|
|
1757
|
-
} else if (currentScrollLeft < preScrollLeft_1) {
|
|
1758
|
-
scrollDirection = ScrollTypeE.SCROLL_RIGHT;
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
};
|
|
1762
|
-
|
|
1763
|
-
if (type === 'remove') {
|
|
1764
|
-
dom.removeEventListener('scroll', scrollFn_1, false);
|
|
1765
|
-
} else {
|
|
1766
|
-
dom.addEventListener('scroll', scrollFn_1, false);
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
return function () {
|
|
1770
|
-
dom.removeEventListener('scroll', scrollFn_1, false);
|
|
1771
|
-
};
|
|
1772
|
-
} catch (e) {
|
|
1773
|
-
console.warn('scroll event error', JSON.stringify(e));
|
|
1774
|
-
}
|
|
1775
|
-
};
|
|
1776
|
-
|
|
1777
|
-
return ScrollSlide;
|
|
1778
|
-
}();
|
|
1779
|
-
|
|
1780
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
1781
|
-
var defaultOpt = {
|
|
1782
|
-
hashTag: false,
|
|
1783
|
-
impr: false
|
|
1784
|
-
};
|
|
1785
|
-
|
|
1786
|
-
var AutoTrack =
|
|
1787
|
-
/** @class */
|
|
1788
|
-
function () {
|
|
1789
|
-
function AutoTrack() {}
|
|
1790
|
-
|
|
1791
|
-
AutoTrack.prototype.apply = function (collect, config) {
|
|
1792
|
-
this.autoTrackStart = false;
|
|
1793
|
-
this.collect = collect;
|
|
1794
|
-
this.config = config;
|
|
1795
|
-
if (!config.autotrack) return;
|
|
1796
|
-
|
|
1797
|
-
if (config.autotrack && config.autotrack.collect_url) {
|
|
1798
|
-
if (!config.autotrack.collect_url()) return;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
var Types = collect.Types;
|
|
1802
|
-
this.ready(Types.Autotrack);
|
|
1803
|
-
this.collect.emit(Types.AutotrackReady);
|
|
1804
|
-
};
|
|
1805
|
-
|
|
1806
|
-
AutoTrack.prototype.ready = function (name) {
|
|
1807
|
-
this.collect.set(name);
|
|
1808
|
-
var options = this.config.autotrack;
|
|
1809
|
-
options = typeof options === 'object' ? options : {};
|
|
1810
|
-
options = Object.assign(defaultOpt, options);
|
|
1811
|
-
this.destroyed = false;
|
|
1812
|
-
this.options = options;
|
|
1813
|
-
this.Config = new Config(defaultConfig, this.options);
|
|
1814
|
-
this.Exposure = new Exposure(this.collect, this.config, this.handle.bind(this));
|
|
1815
|
-
this.Scroll = new ScrollSlide(this.config, this.handle.bind(this));
|
|
1816
|
-
this.Listener = new Listener(options, this.collect, this.Config);
|
|
1817
|
-
this.EventHandle = new EventHandle(this.config, options);
|
|
1818
|
-
this.Request = new Request(this.collect);
|
|
1819
|
-
this.autoTrackStart = true;
|
|
1820
|
-
this.init(); // readyToLoadEditor(this, this.config)
|
|
1821
|
-
};
|
|
1822
|
-
|
|
1823
|
-
AutoTrack.prototype.init = function () {
|
|
1824
|
-
this.Listener.init(this.handle.bind(this));
|
|
1825
|
-
};
|
|
1826
|
-
|
|
1827
|
-
AutoTrack.prototype.handle = function (eventInfo, data) {
|
|
1828
|
-
try {
|
|
1829
|
-
if (this.config.autotrack.collect_url) {
|
|
1830
|
-
if (!this.config.autotrack.collect_url()) return;
|
|
1831
|
-
}
|
|
1832
|
-
} catch (e) {}
|
|
1833
|
-
|
|
1834
|
-
if (this.collect.sdkStop) return;
|
|
1835
|
-
|
|
1836
|
-
if (eventInfo.eventType === 'dom') {
|
|
1837
|
-
this.handleDom(eventInfo, data);
|
|
1838
|
-
}
|
|
1839
|
-
};
|
|
1840
|
-
|
|
1841
|
-
AutoTrack.prototype.handleDom = function (eventInfo, data) {
|
|
1842
|
-
try {
|
|
1843
|
-
var eventName = eventInfo.eventName;
|
|
1844
|
-
|
|
1845
|
-
if (eventName === 'click' || eventName === 'change' || eventName === 'submit') {
|
|
1846
|
-
var handleResult = this.EventHandle.handleEvent(data, eventName);
|
|
1847
|
-
handleResult && this.Request.send({
|
|
1848
|
-
eventType: 'custom'
|
|
1849
|
-
}, handleResult);
|
|
1850
|
-
} else if (eventName === 'page_view' || eventName === 'page_statistics') {
|
|
1851
|
-
var pageData = void 0;
|
|
1852
|
-
|
|
1853
|
-
if (eventName === 'page_view') {
|
|
1854
|
-
pageData = this.EventHandle.handleViewEvent(data);
|
|
1855
|
-
} else {
|
|
1856
|
-
pageData = this.EventHandle.handleStatisticsEvent(data);
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
pageData && this.Request.send({
|
|
1860
|
-
eventType: 'custom'
|
|
1861
|
-
}, pageData);
|
|
1862
|
-
} else if (eventName === 'beat') {
|
|
1863
|
-
var beatData = this.EventHandle.handleBeadtEvent(data);
|
|
1864
|
-
var eventSend = eventInfo.eventSend;
|
|
1865
|
-
beatData && this.Request.send({
|
|
1866
|
-
eventType: 'custom',
|
|
1867
|
-
eventSend: eventSend
|
|
1868
|
-
}, beatData);
|
|
1869
|
-
} else if (eventName === 'exposure') {
|
|
1870
|
-
var handleResult = this.EventHandle.handleExposureEvent(eventInfo, data);
|
|
1871
|
-
handleResult && this.Request.send({
|
|
1872
|
-
eventType: 'custom'
|
|
1873
|
-
}, handleResult);
|
|
1874
|
-
} else if (eventName === 'scroll') {
|
|
1875
|
-
var handleResult = this.EventHandle.handleScrollEvent(eventInfo, data);
|
|
1876
|
-
handleResult && this.Request.send({
|
|
1877
|
-
eventType: 'custom'
|
|
1878
|
-
}, handleResult);
|
|
1879
|
-
}
|
|
1880
|
-
} catch (e) {
|
|
1881
|
-
console.log("handel dom event error " + JSON.stringify(e));
|
|
1882
|
-
}
|
|
1883
|
-
};
|
|
1884
|
-
|
|
1885
|
-
AutoTrack.prototype.destroy = function () {
|
|
1886
|
-
if (!this.autoTrackStart) {
|
|
1887
|
-
return console.warn('engine is undefined, make sure you have called autoTrack.start()');
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
|
-
this.autoTrackStart = false;
|
|
1891
|
-
this.Listener.removeListener();
|
|
1892
|
-
};
|
|
1893
|
-
|
|
1894
|
-
return AutoTrack;
|
|
1895
|
-
}();
|
|
1896
|
-
|
|
1897
|
-
export { AutoTrack as default };
|
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,i,r=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(o=r.next()).done;)a.push(o.value)}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return a}function n(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(e(arguments[n]));return t}var o=function(t){return Array.isArray(t)};Date.now(),Number((""+Math.random()).slice(2,8));function i(t,e){if(void 0===e&&(e="list"),!t)return!1;if(e&&"list"===e){if(["LI","TR","DL"].includes(t.nodeName))return!0;if(t.dataset&&t.dataset.hasOwnProperty("teaIdx"))return!0;if(t.hasAttribute&&t.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(t.nodeName))return!0;if(t.dataset&&t.dataset.hasOwnProperty("teaContainer"))return!0;if(t.hasAttribute&&t.hasAttribute("data-tea-container"))return!0;if(t.hasAttribute&&u(t,"ss"))return!0}return!1}var r=function(t,e){return!!u(t,e)};function a(t){for(var e=t;e&&!i(e,"container");){if("HTML"===e.nodeName||"BODY"===e.nodeName)return t;e=e.parentElement}return e||t}function s(t){for(var e=t;e&&e.parentNode;){if(e.hasAttribute("data-tea-ignore"))return!0;if("HTML"===e.nodeName||"body"===e.nodeName)return!1;e=e.parentNode}return!1}var c=function(t,e){return t.hasAttribute?t.hasAttribute(e):t.attributes?!(!t.attributes[e]||!t.attributes[e].specified):void 0},u=function(t,e){if("string"==typeof e)return c(t,e);if(o(e)){for(var n=!1,i=0;i<e.length;i++){if(c(t,e[i])){n=!0;break}}return n}},l=function(t,e){var n={};if("string"==typeof e)c(t,e)&&(n[e]=t.getAttribute(e));else if(o(e))for(var i=0;i<e.length;i++){c(t,e[i])&&(n[e[i]]=t.getAttribute(e[i]))}return n};var p=function(){function e(e,n,o){var a=this;this.clickEvent=function(t){(function(t,e){if(1!==t.nodeType)return!1;if(!e.svg&&function(t){if("svg"===t.tagName.toLowerCase())return!0;for(var e=t.parentElement,n=!1;e;)"svg"===e.tagName.toLowerCase()?(e=null,n=!0):e=e.parentElement;return n}(t))return!1;if(["HTML","BODY"].includes(t.tagName.toUpperCase()))return!1;var n=t;return!!("none"!==n.style.display&&(i(n,"container")||e.track_attr&&r(n,e.track_attr)||function(t){if(t.children.length){var e=t.children;return![].slice.call(e).some(function(t){return t.children.length>0})}return!0}(n)))})(t.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},t)},this.changeEvent=function(t){a.eventHandel({eventType:"dom",eventName:"change"},t)},this.submitEvent=function(t){a.eventHandel({eventType:"dom",eventName:"submit"},t)},this.getPageViewEvent=function(e,n){n&&"pushState"===n&&a.eventHandel({eventType:"dom",eventName:"beat"},t({beat_type:0},e)),a.eventHandel({eventType:"dom",eventName:"page_view"},e)},this.getPageLoadEvent=function(t){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:t})},this.config=o.getConfig().eventConfig,this.collect=n,this.options=e,this.beatTime=e.beat,this.statistics=!1}return e.prototype.init=function(t){this.eventHandel=t;var e=this.config.mode;this.addListener(e)},e.prototype.addListener=function(t){var e=this;if("proxy-capturing"===t&&(this.config.click&&window.document.addEventListener("click",this.clickEvent,!0),this.config.change&&window.document.addEventListener("change",this.changeEvent,!0),this.config.submit&&window.document.addEventListener("submit",this.submitEvent,!0),this.config.pv&&this.collect.on("route-change",function(t){var n=t.config,o=t.name;e.getPageViewEvent(n,o)}),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",function(){e.beatEvent(e.beatTime)});var n=0,o=null;window.addEventListener("scroll",function(){clearTimeout(o),o=setTimeout(i,500),n=document.documentElement.scrollTop||document.body.scrollTop});var i=function(){(document.documentElement.scrollTop||document.body.scrollTop)==n&&e.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(t){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver(function(t){var n=t.getEntries(),o=n[n.length-1],i=o.renderTime||o.loadTime;e.statistics||(e.getPageLoadEvent(i),e.statistics=!0)});a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout(function(){e.statistics||(e.getPageLoadEvent(r[0].startTime||0),e.statistics=!0)},2e3)}else this.getPageLoadEvent(0)}catch(t){this.getPageLoadEvent(0)}}},e.prototype.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},e.prototype.beatEvent=function(t){var e,n=this;try{var o;this.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:3}),this.beatTime&&(o=setInterval(function(){n.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:2})},t)),e=function(){n.eventHandel({eventType:"dom",eventName:"beat",eventSend:"becon"},{beat_type:0}),n.beatTime&&clearInterval(o)},navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",e,!1):window.addEventListener("beforeunload",e,!1)}catch(t){}},e}(),h={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function t(t,e){this.config=t,this.config.eventConfig=Object.assign(this.config.eventConfig,e)}return t.prototype.getConfig=function(){return this.config},t.prototype.setConfig=function(t){return this.config=t},t}();function v(t){for(var e=[];null!==t.parentElement;)e.push(t),t=t.parentElement;var n=[],o=[];return e.forEach(function(t){var e=function(t){if(null===t)return{str:"",index:0};var e=0,n=t.parentElement;if(n)for(var o=n.children,r=0;r<o.length&&o[r]!==t;r++)o[r].nodeName===t.nodeName&&e++;return{str:[t.nodeName.toLowerCase(),i(t,"list")?"[]":""].join(""),index:e}}(t),r=e.str,a=e.index;n.unshift(r),o.unshift(a)}),{element_path:"/"+n.join("/"),positions:o}}function f(t,e,n,o){var i={},s=function(t){if(t){var e=t.getBoundingClientRect(),n=e.width,o=e.height;return{left:e.left,top:e.top,element_width:n,element_height:o}}}(e),c=function(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=t.clientX,o=t.clientY,i=e.left,r=e.top,a=n-i>=0?n-i:0,s=o-r>=0?o-r:0;return{touch_x:Math.floor(a),touch_y:Math.floor(s)}}(t,s),u=s.element_width,p=s.element_height,h=c.touch_x,d=c.touch_y,f=v(e),m=f.element_path,g=f.positions,b=function(t){var e=a(t),n=[];return function t(e){var o=function(t){var e="";return 3===t.nodeType?e=t.textContent.trim():t.dataset&&t.dataset.hasOwnProperty("teaTitle")||t.hasAttribute("ata-tea-title")?e=t.getAttribute("data-tea-title"):t.hasAttribute("title")?e=t.getAttribute("title"):"INPUT"===t.nodeName&&["button","submit"].includes(t.getAttribute("type"))?e=t.getAttribute("value"):"IMG"===t.nodeName&&t.getAttribute("alt")&&(e=t.getAttribute("alt")),e.slice(0,200)}(e);if(o&&-1===n.indexOf(o)&&n.push(o),e.childNodes.length>0)for(var i=e.childNodes,r=0;r<i.length;r++)8!==i[r].nodeType&&t(i[r])}(e),n}(e),y=window.performance.timing.navigationStart,_=Date.now()-y,E=g.map(function(t){return""+t}),w=null;if(window.TEAVisualEditor&&window.TEAVisualEditor.getOriginXpath&&(w=window.TEAVisualEditor.getOriginXpath({xpath:m,positions:E})),i.element_path=w&&w.xpath||m,i.positions=w&&w.positions||E,o&&!o.text&&(i.texts=b,i.element_title=function(t){if(!t)return"";var e="";return t.textContent?e=t.textContent.trim():t.innerText&&(e=t.innerText.trim()),"input"!==t.tagName&&"INPUT"!==t.tagName||(e=t.value||""),e}(e)),i.element_id=e.getAttribute("id")||"",i.element_class_name=e.getAttribute("class")||"",i.element_type=e.nodeType,i.element_width=Math.floor(u),i.element_height=Math.floor(p),i.touch_x=h,i.touch_y=d,i.page_manual_key="",i.elememt_manual_key="",i.since_page_start_ms=_,i.page_start_ms=y,i.page_path=location.pathname,i.page_host=location.host,n.track_attr&&r(e,n.track_attr)){var T=l(e,n.track_attr);for(var x in T)i[x]=T[x]}if(n.custom_attr)try{if(r(e,n.custom_attr)){T=l(e,n.custom_attr),x=decodeURIComponent(T[n.custom_attr]);var O=JSON.parse(x);if(Object.keys(O))for(var L in O)i[L]=O[L]}}catch(t){console.log("custom attr error")}var S=a(e);return"A"===S.tagName&&(i.href=S.getAttribute("href")),!1!==n.src&&("IMG"!==e.tagName||e.getAttribute("src").includes("base64")||(i.src=e.getAttribute("src"))),i}var m,g=function(e,n,o,i,r){return t({event:e},f(n,o,i,r),{is_html:1,page_key:window.location.href,page_title:document.title})},b=function(){function e(t,e){this.ignore={text:!1},this.initConfig=t,this.options=e,this.eventName=e&&"tea"===e.custom?{click:"__bav_click",page:"__bav_page",beat:"__bav_beat",static:"__bav_page_statistics",exposure:"__bav_page_exposure"}:{click:"bav2b_click",page:"bav2b_page",beat:"bav2b_beat",static:"bav2b_page_statistics",exposure:"bav2b_exposure",scroll:"$bav2b_slide"},e&&!1===e.text&&(this.ignore.text=!0),e&&e.exposure&&e.exposure.eventName&&(this.eventName.exposure=e.exposure.eventName)}return e.prototype.handleEvent=function(e,n){try{if(s(e.target))return null;var o="bav2b_click";switch(n){case"click":return o=this.eventName.click,g(o,e,e.target,this.options,this.ignore);case"exposure":return o=this.eventName.exposure,g(o,e,e.target,this.options,this.ignore);case"change":return t({},g(o="bav2b_change",e,e.target,this.options),function(t,e){try{if("bav2b_change"===t)return e.hasAttribute("data-tea-track")?{value:e.value}:{}}catch(t){return{}}}(o,e.target));case"submit":return g(o="bav2b_submit",e,e.target,this.options)}}catch(t){return console.error(t),null}},e.prototype.handleViewEvent=function(t){t.event=this.eventName.page,t.page_title=document.title,t.page_total_width=window.innerWidth,t.page_total_height=window.innerHeight;try{var e=window.sessionStorage.getItem("_tea_cache_duration");if(e){var n=JSON.parse(e);t.refer_page_duration_ms=n?n.duration:""}t.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,t.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,t.page_start_ms=window.performance.timing.navigationStart}catch(t){console.log("page event error "+JSON.stringify(t))}return t},e.prototype.handleStatisticsEvent=function(t){var e={};e.event=this.eventName.static,e.is_html=1,e.page_key=location.href,e.refer_page_key=document.referrer||"",e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"",e.refer_page_manual_key="";try{var n=t.lcp,o=window.performance.timing,i=o.loadEventEnd-o.navigationStart;e.page_init_cost_ms=parseInt(n||(i>0?i:0)),e.page_start_ms=o.navigationStart}catch(t){console.log("page_statistics event error "+JSON.stringify(t))}return e},e.prototype.handleBeadtEvent=function(t){t.event=this.eventName.beat,t.page_key=window.location.href,t.is_html=1,t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{t.page_viewport_width=window.innerWidth,t.page_viewport_height=window.innerHeight,t.page_total_width=document.documentElement.scrollWidth,t.page_total_height=document.documentElement.scrollHeight,t.scroll_width=document.documentElement.scrollLeft+window.innerWidth,t.scroll_height=document.documentElement.scrollTop+window.innerHeight,t.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,t.page_start_ms=window.performance.timing.navigationStart}catch(t){console.log("beat event error "+JSON.stringify(t))}return t},e.prototype.handleExposureEvent=function(t,e){if(s(e.target))return null;var n=g(t.event||this.eventName.exposure,e,e.target||e,this.options,this.ignore);if(n.$exposure_type=t.exposureType,this.options.exposure.callback){var o=this.options.exposure.callback(n);return o||Object.keys(o).length?o:(console.warn("exposure callback must return data!"),n)}return n},e.prototype.handleScrollEvent=function(t,e){var n=g(t.event||this.eventName.scroll,e,e.target||e,this.options,this.ignore);if(n=Object.assign(n,t.params),!this.options.scroll.callback||(n=this.options.scroll.callback(n))||Object.keys(n).length)return n;console.warn("scroll callback must return data!")},e}(),y=function(){function t(t){this.collect=t}return t.prototype.send=function(t,e){var n=e.event;delete e.event,t&&"becon"===t.eventSend?this.collect.beconEvent(n,e):this.collect.event(n,e)},t.prototype.get=function(t,e){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},e);fetch(t,n)},t.prototype.post=function(t,e){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},e);fetch(t,n)},t}(),_=function(){function t(t,e){this._instance=null,this._intersection=t,this.config=e,this._intersection&&this.init()}return t.prototype.init=function(){var t=this;if(window.MutationObserver)try{if(this._instance=new MutationObserver(function(e){e.forEach(function(e){"attributes"===e.type&&t.attributeChangeObserve(e),"childList"===e.type&&t.modifyNodeObserve(e)})}),!document||!document.body)return void console.warn("please use sdk api init after body element");var e=!1!==this.config.autotrack.exposure.attributes;this._instance.observe(document.body,{childList:!0,attributes:e,subtree:!0,attributeOldValue:!1})}catch(t){console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")}else console.log("your browser cannot support MutationObserver,so cannot report exposure event, please update")},t.prototype.attributeChangeObserve=function(t){t.target.hasAttribute("data-exposure")?this.exposureAdd(t,"mutation"):this.exposureRemove(t)},t.prototype.modifyNodeObserve=function(t){var e=this;Array.prototype.forEach.call(t.addedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e.exposureAdd(t,"intersect"),e.mapChild(t,e.exposureAdd.bind(e))}),Array.prototype.forEach.call(t.removedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e.exposureRemove(t),e.mapChild(t,e.exposureRemove.bind(e))})},t.prototype.mapChild=function(t,e){var n=this;1===t.nodeType&&t.children.length&&Array.prototype.forEach.call(t.children,function(t){1===t.nodeType&&t.hasAttribute("data-exposure")&&e(t),n.mapChild(t,e)})},t.prototype.exposureAdd=function(t,e){try{this._intersection&&this._intersection.exposureAdd(t,e)}catch(t){console.log("intersection error",JSON.stringify(t.message))}},t.prototype.exposureRemove=function(t){try{this._intersection&&this._intersection.exposureRemove(t)}catch(t){console.log("intersection error",JSON.stringify(t.message))}},t._exposure_observer=null,t}(),E=function t(e){return e?(e^16*Math.random()>>e/4).toString(10):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t)},w=function(){return E().replace(/-/g,"").slice(0,19)};!function(t){t[t.EXPOSURE_ONCE=0]="EXPOSURE_ONCE",t[t.LIFECYCLE_SHOW_NEW=3]="LIFECYCLE_SHOW_NEW",t[t.RESUME_FORM_PAGE=6]="RESUME_FORM_PAGE",t[t.RESUME_FORM_BACK=7]="RESUME_FORM_BACK",t[t.NOT_EXPOSURE=-1]="NOT_EXPOSURE"}(m||(m={}));var T,x=function(){function t(e,n,o){var i=this;this.backStatus=!1,this.instance=this.buildObserver(),this.collect=e,this.observeMap=t._observer_map,n.autotrack.exposure.ratio?this.ratio=n.autotrack.exposure.ratio:0===n.autotrack.exposure.ratio?this.ratio=0:this.ratio=.5,this.timeLimit=n.autotrack.exposure.stay||0,this.exposureType=m.NOT_EXPOSURE,this.eventHandle=o,this.hashMap=new Map,this.backStatus=!1,this.lastState=null,this.collect.on("re-start-sdk",function(){i.visibilitychange()}),this.addListen()}return t.prototype.buildObserver=function(){var e=this;if(t._observer_instance)return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null;if(window.IntersectionObserver){for(var n=[],o=0;o<=1;o+=.01)n.push(o);n.push(1);try{t._observer_instance=new IntersectionObserver(function(t){t.forEach(function(t){var n=t.target.observeId,o=e.observeMap.get(n),i=(t.target,t.isIntersecting,t.intersectionRatio);if(o.intersectionRatio=i,i<=.1&&(t.target.backStatus=!1),e.observeMap.set(n,o),i<e.ratio)return o.isIntersecting=!1,o.added=!1,o.exposured=!1,o.startTime=Date.now(),void e.observeMap.set(n,o);if(!o.added){if(o.startTime=Date.now(),o.added=!0,o.isIntersecting=!0,e.timeLimit){var r=setTimeout(function(){try{if(o.isIntersecting&&!o.exposured&&e.observeMap.get(n)){var i=e.observeMap.get(n).intersectionRatio;e.exposureEvent(t,i,n,o)}}catch(t){console.log("IntersectionObserver setTimeout error,msg: "+JSON.stringify(t))}},e.timeLimit);o.wait=r}e.observeMap.set(n,o)}Date.now()-o.startTime>=e.timeLimit&&!o.exposured&&e.exposureEvent(t,i,n,o)})},{threshold:n})}catch(t){console.log("IntersectionObserver error,msg: "+JSON.stringify(t))}return t._observer_instance}return console.log("your browser cannot support IntersectionObserver, so cannot report exposure event, please update"),null},t.prototype.exposureAdd=function(t,e){var n="mutation"===e?t.target:t,o=n.observeId,i=w();if(o||this.observeMap.has(o)){var r=this.observeMap.get(o);if(r&&n!==r.instance)this.unobserve(n),this.observeMap.delete(o),n.observeId=i,n.visible=!1,this.observeMap.set(i,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n);else{if(!0===n.visible)return;this.handleBoundingExposure(n)}}else n.observeId=i,n.visible=!1,this.observeMap.set(i,{instance:n.cloneNode(!0),isIntersecting:!1}),this.observe(n)},t.prototype.exposureRemove=function(t){this.observeMap.has(t.observeId)&&(this.observeMap.delete(t.observeId),this.unobserve(t),t.observeId="",t.visible=!1)},t.prototype.exposureEvent=function(t,e,n,o){if(e>=this.ratio){if("0"===t.target.style.opacity||"hidden"===t.target.style.visibility)return;if(!0===o.exposured)return;o.startWait&&clearTimeout(o.startWait);var i=t.target.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:i,exposureType:this.getExposureType(t.target)},t),t.target.visible=!0,t.target.hasExposure=!0,o.startTime=Date.now(),o.exposured=!0}else o.startTime=Date.now(),o.exposured=!1;this.observeMap.set(n,o)},t.prototype.observe=function(t){this.instance&&this.instance.observe(t)},t.prototype.unobserve=function(t){this.instance&&this.instance.unobserve(t)},t.prototype.getExposureDomToExposure=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(e){t.handleBoundingExposure(e)})},t.prototype.visibilitychange=function(){var t=this,e=null;"visible"===document.visibilityState?this.timeLimit?e=setTimeout(function(){t.getExposureDomToExposure()},this.timeLimit):this.getExposureDomToExposure():(clearTimeout(e),this.customType=void 0)},t.prototype.handleBoundingExposure=function(t){if(this.getBoundingRatio(t)>=this.ratio){t.visible=!0;var e=t.getAttribute&&t.getAttribute("data-exposure-event");this.eventHandle({eventType:"dom",eventName:"exposure",event:e,exposureType:this.customType||m.RESUME_FORM_BACK},t)}},t.prototype.getBoundingRatio=function(t){var e=t.getBoundingClientRect(),n=e.top,o=e.left,i=e.width,r=e.height,a=window.innerWidth||document.documentElement.clientWidth,s=window.innerHeight||document.documentElement.clientHeight;return n>=0&&o>=0&&n<=s&&o<=a?(i>a?a:i)*(s-n)/(i*r):0},t.prototype.getExposureType=function(t){return t.visible?!1!==t.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=m.RESUME_FORM_PAGE:this.exposureType=m.LIFECYCLE_SHOW_NEW:(t.hasExposure,!1!==t.backStatus&&(this.backStatus||this.customType||2===window.performance.navigation.type)?this.exposureType=m.RESUME_FORM_PAGE:this.exposureType=m.EXPOSURE_ONCE),this.exposureType},t.prototype.addListen=function(){var t=this;this.collect.on("set-exposure-type",function(e){t.customType=e});var e,o,i,r,a=this.visibilitychange.bind(this);if(e=document,o="visibilitychange",i=a,r=!1,e.addEventListener?e.addEventListener(o,i,r):e.attachEven?e.attachEven("on"+o,i):e["on"+o]=i,window.addEventListener("hashchange",function(e){var n=t.hashMap.get(e.oldURL);n&&location.href===n.prev?(t.backStatus=!0,t.exposureType=m.RESUME_FORM_PAGE):(t.backStatus=!1,t.hashMap.set(location.href,{current:e.newURL,prev:e.oldURL}))}),this.collect.bridgeReport){var s=window.history.pushState;history.pushState=function(e){for(var o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];"function"==typeof history.onpushstate&&history.onpushstate({state:e});var r=s.call.apply(s,n([history,e],o));return t.lastState=e,r};var c=history.replaceState;history.replaceState=function(e){for(var o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];"function"==typeof history.onreplacestate&&history.onreplacestate({state:e});var r=c.call.apply(c,n([history,e],o));return t.lastState=e,r}}else this.collect.on("STATE_CHANGE",function(e){t.lastState=e});return window.addEventListener("popstate",function(e){var n=e.state;n&&n.current&&t.lastState&&t.lastState.back&&n.current===t.lastState.back?(t.backStatus=!0,t.exposureType=m.RESUME_FORM_PAGE):t.backStatus=!1}),function(){!function(t,e,n,o){t.addEventListener?t.removeEventListener(e,n,o):t.attachEven&&t.detachEven("on"+e,n)}(document,"visibilitychange",a,!1)}},t._observer_instance=null,t._observer_map=new Map,t}(),O=function(){function t(t,e,n){e.autotrack&&e.autotrack.exposure&&(this._intersection=new x(t,e,n),this._observer=new _(this._intersection,e),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure event, please update~"))}return t.prototype.initObserver=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),function(e){t._intersection.exposureAdd(e,"intersect")})},t}();!function(t){t[t.SCROLL_UP=1]="SCROLL_UP",t[t.SCROLL_DOWN=2]="SCROLL_DOWN",t[t.SCROLL_LEFT=3]="SCROLL_LEFT",t[t.SCROLL_RIGHT=4]="SCROLL_RIGHT",t[t.NOT_SCROLL=-1]="NOT_SCROLL"}(T||(T={}));var L=function(){function t(t,e){this.distance=30,t.autotrack&&t.autotrack.scroll&&(t.autotrack.scroll.distance&&(this.distance=t.autotrack.scroll.distance),this.eventHandle=e,this.addLinstenr(),this.mutation())}return t.prototype.addLinstenr=function(){var t=this;Array.prototype.forEach.call(document.querySelectorAll("[data-scroll]"),function(e){t.scrollHandle(e)})},t.prototype.mutation=function(){var t=this;if(window.MutationObserver)try{var e=new MutationObserver(function(e){e.forEach(function(e){"childList"===e.type&&t.modifyNodeObserve(e)})});if(!document||!document.body)return void console.warn("please use sdk api init after body element");e.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})}catch(t){console.log("your browser cannot support MutationObserver")}else console.log("your browser cannot support MutationObserver")},t.prototype.modifyNodeObserve=function(t){var e=this;Array.prototype.forEach.call(t.addedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e.scrollHandle(t),e.mapChild(t,e.scrollHandle.bind(e))}),Array.prototype.forEach.call(t.removedNodes,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e.scrollHandle(t,"remove"),e.mapChild(t,e.scrollHandle.bind(e))})},t.prototype.mapChild=function(t,e){var n=this;1===t.nodeType&&t.children.length&&Array.prototype.forEach.call(t.children,function(t){1===t.nodeType&&t.hasAttribute("data-scroll")&&e(t),n.mapChild(t,e)})},t.prototype.scrollHandle=function(t,e){var n=this;try{var o=t.scrollTop,i=t.scrollLeft,r=null,a=0,s=0,c=function(e){clearTimeout(r),r=setTimeout(function(){var r=t.scrollTop,p=t.scrollLeft,h=e.target&&e.target.getAttribute("data-scroll-event")||"";1===l||2===l?r===c&&(s=c-o,Math.abs(s)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},e)):3!==l&&4!==l||p===u&&(a=u-i,Math.abs(a)>=n.distance&&n.distance&&n.eventHandle({eventType:"dom",eventName:"scroll",event:h,params:{$direction:l,$offsetY:s,$offsetX:a}},e)),o=c,i=u},100);var c=t.scrollTop,u=t.scrollLeft,l=T.NOT_SCROLL;c>o?l=T.SCROLL_DOWN:c<o?l=T.SCROLL_UP:u>i?l=T.SCROLL_LEFT:u<i&&(l=T.SCROLL_RIGHT)};return"remove"===e?t.removeEventListener("scroll",c,!1):t.addEventListener("scroll",c,!1),function(){t.removeEventListener("scroll",c,!1)}}catch(t){console.warn("scroll event error",JSON.stringify(t))}},t}(),S={hashTag:!1,impr:!1},N=function(){function t(){}return t.prototype.apply=function(t,e){if(this.autoTrackStart=!1,this.collect=t,this.config=e,e.autotrack&&(!e.autotrack||!e.autotrack.collect_url||e.autotrack.collect_url())){var n=t.Types;this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady)}},t.prototype.ready=function(t){this.collect.set(t);var e=this.config.autotrack;e="object"==typeof e?e:{},e=Object.assign(S,e),this.destroyed=!1,this.options=e,this.Config=new d(h,this.options),this.Exposure=new O(this.collect,this.config,this.handle.bind(this)),this.Scroll=new L(this.config,this.handle.bind(this)),this.Listener=new p(e,this.collect,this.Config),this.EventHandle=new b(this.config,e),this.Request=new y(this.collect),this.autoTrackStart=!0,this.init()},t.prototype.init=function(){this.Listener.init(this.handle.bind(this))},t.prototype.handle=function(t,e){try{if(this.config.autotrack.collect_url&&!this.config.autotrack.collect_url())return}catch(t){}this.collect.sdkStop||"dom"===t.eventType&&this.handleDom(t,e)},t.prototype.handleDom=function(t,e){try{var n=t.eventName;if("click"===n||"change"===n||"submit"===n)(a=this.EventHandle.handleEvent(e,n))&&this.Request.send({eventType:"custom"},a);else if("page_view"===n||"page_statistics"===n){var o=void 0;(o="page_view"===n?this.EventHandle.handleViewEvent(e):this.EventHandle.handleStatisticsEvent(e))&&this.Request.send({eventType:"custom"},o)}else if("beat"===n){var i=this.EventHandle.handleBeadtEvent(e),r=t.eventSend;i&&this.Request.send({eventType:"custom",eventSend:r},i)}else if("exposure"===n){(a=this.EventHandle.handleExposureEvent(t,e))&&this.Request.send({eventType:"custom"},a)}else if("scroll"===n){var a;(a=this.EventHandle.handleScrollEvent(t,e))&&this.Request.send({eventType:"custom"},a)}}catch(t){console.log("handel dom event error "+JSON.stringify(t))}},t.prototype.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},t}();export{N as default};
|