hina-cloud-js-sdk 3.1.8 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/hina.cjs.js +1 -0
- package/dist/hina.esm.full.js +1 -0
- package/dist/hina.esm.js +1 -0
- package/dist/hina.full.js +1 -0
- package/dist/hina.iife.js +1 -0
- package/dist/index.d.ts +411 -0
- package/package.json +27 -37
- package/readme.md +1 -0
- package/.eslintrc.js +0 -12
- package/.gitlab-ci.yml +0 -16
- package/.vscode/settings.json +0 -5
- package/build/hina.cjs.min.js +0 -1
- package/build/hina.esm.min.js +0 -1
- package/build/hina.min.js +0 -1
- package/build/hotAnalyse.min.js +0 -1
- package/packages/core/dist/index.cjs.js +0 -64
- package/packages/core/dist/index.cjs.js.map +0 -1
- package/packages/core/dist/index.d.ts +0 -45
- package/packages/core/dist/index.esm.js +0 -62
- package/packages/core/dist/index.esm.js.map +0 -1
- package/packages/core/dist/index.global.js +0 -1199
- package/packages/core/dist/index.global.js.map +0 -1
- package/packages/core/dist/index.js +0 -1200
- package/packages/core/dist/index.js.map +0 -1
- package/packages/monitor/dist/index.cjs.js +0 -150
- package/packages/monitor/dist/index.cjs.js.map +0 -1
- package/packages/monitor/dist/index.d.ts +0 -35
- package/packages/monitor/dist/index.esm.js +0 -145
- package/packages/monitor/dist/index.esm.js.map +0 -1
- package/packages/monitor/dist/index.global.js +0 -1343
- package/packages/monitor/dist/index.global.js.map +0 -1
- package/packages/monitor/dist/index.js +0 -1344
- package/packages/monitor/dist/index.js.map +0 -1
- package/packages/track/dist/index.cjs.js +0 -1930
- package/packages/track/dist/index.cjs.js.map +0 -1
- package/packages/track/dist/index.d.ts +0 -212
- package/packages/track/dist/index.esm.js +0 -1925
- package/packages/track/dist/index.esm.js.map +0 -1
- package/packages/track/dist/index.global.js +0 -4259
- package/packages/track/dist/index.global.js.map +0 -1
- package/packages/track/dist/index.js +0 -4260
- package/packages/track/dist/index.js.map +0 -1
- package/packages/types/dist/index.d.ts +0 -603
- package/packages/types/dist/index.esm.js +0 -25
- package/packages/types/dist/index.esm.js.map +0 -1
- package/packages/utils/dist/index.cjs.js +0 -1535
- package/packages/utils/dist/index.cjs.js.map +0 -1
- package/packages/utils/dist/index.d.ts +0 -394
- package/packages/utils/dist/index.esm.js +0 -1465
- package/packages/utils/dist/index.esm.js.map +0 -1
- package/packages/utils/dist/index.global.js +0 -2507
- package/packages/utils/dist/index.global.js.map +0 -1
- package/packages/utils/dist/index.js +0 -2508
- package/packages/utils/dist/index.js.map +0 -1
- package/report.json +0 -101
- package/rollup.config.epm.js +0 -42
- package/rollup.config.sdk.js +0 -42
- package/sonar-project.properties +0 -3
@@ -1,1925 +0,0 @@
|
|
1
|
-
import { BaseCore } from 'hina-cloud-core';
|
2
|
-
import { ReportType, ConsoleTypes, PluginBase } from 'hina-cloud-types';
|
3
|
-
import { safeJSONParse, isArray, nowStamp, AjaxRequest, base64Encode, getRandom, isFunction, isObject, merge, getElementParents, isElement, isString, getScrollLeft, getScrollTop, formatDecimal, getElementProperties, ListenPageState, mitt, getURL, getReferrer, getHostname, isBoolean, handleDecodeURLComponent, handleEncodeURLComponent, supportHistory, replaceOld, isNumber, getCurrentDomain, isReferralTraffic, SearchKeyword, getUmtsParams, State, BeaconRequest, ImageRequest, isEmptyObject, getPageProperties, getBrowserInfo, MAX_STRING_LENGTH, noop } from 'hina-cloud-utils';
|
4
|
-
|
5
|
-
/******************************************************************************
|
6
|
-
Copyright (c) Microsoft Corporation.
|
7
|
-
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
9
|
-
purpose with or without fee is hereby granted.
|
10
|
-
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
18
|
-
***************************************************************************** */
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
20
|
-
|
21
|
-
var extendStatics = function(d, b) {
|
22
|
-
extendStatics = Object.setPrototypeOf ||
|
23
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
24
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
25
|
-
return extendStatics(d, b);
|
26
|
-
};
|
27
|
-
|
28
|
-
function __extends(d, b) {
|
29
|
-
if (typeof b !== "function" && b !== null)
|
30
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
31
|
-
extendStatics(d, b);
|
32
|
-
function __() { this.constructor = d; }
|
33
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
34
|
-
}
|
35
|
-
|
36
|
-
var __assign = function() {
|
37
|
-
__assign = Object.assign || function __assign(t) {
|
38
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
39
|
-
s = arguments[i];
|
40
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
41
|
-
}
|
42
|
-
return t;
|
43
|
-
};
|
44
|
-
return __assign.apply(this, arguments);
|
45
|
-
};
|
46
|
-
|
47
|
-
function __values(o) {
|
48
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
49
|
-
if (m) return m.call(o);
|
50
|
-
if (o && typeof o.length === "number") return {
|
51
|
-
next: function () {
|
52
|
-
if (o && i >= o.length) o = void 0;
|
53
|
-
return { value: o && o[i++], done: !o };
|
54
|
-
}
|
55
|
-
};
|
56
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
57
|
-
}
|
58
|
-
|
59
|
-
function __read(o, n) {
|
60
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
61
|
-
if (!m) return o;
|
62
|
-
var i = m.call(o), r, ar = [], e;
|
63
|
-
try {
|
64
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
65
|
-
}
|
66
|
-
catch (error) { e = { error: error }; }
|
67
|
-
finally {
|
68
|
-
try {
|
69
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
70
|
-
}
|
71
|
-
finally { if (e) throw e.error; }
|
72
|
-
}
|
73
|
-
return ar;
|
74
|
-
}
|
75
|
-
|
76
|
-
function __spreadArray(to, from, pack) {
|
77
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
78
|
-
if (ar || !(i in from)) {
|
79
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
80
|
-
ar[i] = from[i];
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
84
|
-
}
|
85
|
-
|
86
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
87
|
-
var e = new Error(message);
|
88
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
89
|
-
};
|
90
|
-
|
91
|
-
var GET_DEFAULT_OPTIONS = function () {
|
92
|
-
return {
|
93
|
-
name: '',
|
94
|
-
serverUrl: '',
|
95
|
-
showLog: false,
|
96
|
-
autoTrackConfig: {
|
97
|
-
clickAutoTrack: true,
|
98
|
-
stayAutoTrack: true,
|
99
|
-
isCollectUrl: function () { return true; },
|
100
|
-
isCollectElement: function () { return true; },
|
101
|
-
isCollectInput: function () { return false; },
|
102
|
-
addCustomProperty: function () { },
|
103
|
-
stayDelayTime: 4000,
|
104
|
-
maxStayPageDuration: 18000,
|
105
|
-
collectTags: {
|
106
|
-
div: false
|
107
|
-
},
|
108
|
-
trackAttr: ['hn-click'],
|
109
|
-
pageviewAutoTrack: false,
|
110
|
-
pageLeaveAutoTrack: false
|
111
|
-
},
|
112
|
-
stayAutoTrackConfig: {
|
113
|
-
isCollectUrl: function () { return true; }
|
114
|
-
},
|
115
|
-
imgUseCrossOrigin: false,
|
116
|
-
isSinglePage: false,
|
117
|
-
batchSend: false,
|
118
|
-
appJsBridge: false,
|
119
|
-
sendType: ReportType.IMAGE,
|
120
|
-
dataSendTimeout: 3000,
|
121
|
-
presetProperties: {
|
122
|
-
latest_utm: true,
|
123
|
-
latest_utm_source: true,
|
124
|
-
latest_traffic_source_type: true,
|
125
|
-
latest_search_keyword: true,
|
126
|
-
latest_referrer: true,
|
127
|
-
url: true,
|
128
|
-
title: true
|
129
|
-
}
|
130
|
-
};
|
131
|
-
};
|
132
|
-
var ignoreTags = [
|
133
|
-
'mark',
|
134
|
-
'/mark',
|
135
|
-
'strong',
|
136
|
-
'b',
|
137
|
-
'em',
|
138
|
-
'i',
|
139
|
-
'u',
|
140
|
-
'abbr',
|
141
|
-
'ins',
|
142
|
-
'del',
|
143
|
-
's',
|
144
|
-
'sup'
|
145
|
-
];
|
146
|
-
var defaultTags = ['a', 'input', 'button', 'textarea'];
|
147
|
-
|
148
|
-
/**
|
149
|
-
* @description 批量发送数据
|
150
|
-
*/
|
151
|
-
var BatchSend = /** @class */ (function () {
|
152
|
-
function BatchSend(context) {
|
153
|
-
this.context = context;
|
154
|
-
this.batchKey = 'hinasdk_tab';
|
155
|
-
this.batchDataKey = 'hinasdk_data_';
|
156
|
-
this.batchInterval();
|
157
|
-
}
|
158
|
-
BatchSend.prototype.getBatchConfig = function () {
|
159
|
-
var batchSend = this.context.options.batchSend;
|
160
|
-
return batchSend;
|
161
|
-
};
|
162
|
-
BatchSend.prototype.getStorageList = function () {
|
163
|
-
var _a;
|
164
|
-
var list = [];
|
165
|
-
var tabStorage = (_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.get(this.batchKey);
|
166
|
-
if (tabStorage) {
|
167
|
-
list = safeJSONParse(tabStorage);
|
168
|
-
if (!isArray(list)) {
|
169
|
-
list = [];
|
170
|
-
}
|
171
|
-
}
|
172
|
-
return list;
|
173
|
-
};
|
174
|
-
BatchSend.prototype.batchInterval = function () {
|
175
|
-
var _this = this;
|
176
|
-
var sendInterval = this.getBatchConfig().sendInterval;
|
177
|
-
setTimeout(function () {
|
178
|
-
_this.send().then(function () {
|
179
|
-
_this.batchInterval();
|
180
|
-
});
|
181
|
-
}, sendInterval);
|
182
|
-
};
|
183
|
-
BatchSend.prototype.send = function () {
|
184
|
-
var _this = this;
|
185
|
-
return new Promise(function (resolve) {
|
186
|
-
var _a;
|
187
|
-
var tabStorageList = _this.getStorageList();
|
188
|
-
if (tabStorageList.length > 0) {
|
189
|
-
var _b = _this.getBatchConfig(), storageLimit = _b.storageLimit, dataSendTimeout = _b.dataSendTimeout;
|
190
|
-
var now = nowStamp();
|
191
|
-
var list = [];
|
192
|
-
var removeKeys_1 = [];
|
193
|
-
var len = tabStorageList.length;
|
194
|
-
for (var i = 0; i < len; i++) {
|
195
|
-
var _c = tabStorageList[i], dataKey = _c.dataKey, expireTime = _c.expireTime;
|
196
|
-
removeKeys_1.push(dataKey);
|
197
|
-
if (expireTime >= now) {
|
198
|
-
var data = (_a = _this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.get(dataKey);
|
199
|
-
if (data) {
|
200
|
-
list.push(safeJSONParse(data));
|
201
|
-
}
|
202
|
-
}
|
203
|
-
}
|
204
|
-
list = list.filter(Boolean);
|
205
|
-
if (list.length > storageLimit) {
|
206
|
-
list = list.slice(0, storageLimit);
|
207
|
-
}
|
208
|
-
if (list.length === 0) {
|
209
|
-
resolve();
|
210
|
-
}
|
211
|
-
else {
|
212
|
-
var serverUrl = _this.context.options.serverUrl;
|
213
|
-
var listStr = JSON.stringify(list);
|
214
|
-
new AjaxRequest({
|
215
|
-
url: serverUrl,
|
216
|
-
data: "data_list=".concat(base64Encode(listStr)),
|
217
|
-
timeout: dataSendTimeout
|
218
|
-
})
|
219
|
-
.run()
|
220
|
-
.then(function (res) {
|
221
|
-
if (res.type === 'success') {
|
222
|
-
_this.remove(removeKeys_1);
|
223
|
-
}
|
224
|
-
resolve();
|
225
|
-
});
|
226
|
-
}
|
227
|
-
}
|
228
|
-
});
|
229
|
-
};
|
230
|
-
BatchSend.prototype.remove = function (removeKeys) {
|
231
|
-
var _this = this;
|
232
|
-
var _a;
|
233
|
-
var firstKey = removeKeys[0];
|
234
|
-
var tabStorageList = this.getStorageList();
|
235
|
-
// 删除hinasdk_data_开头的数据
|
236
|
-
removeKeys.forEach(function (key) {
|
237
|
-
var _a;
|
238
|
-
(_a = _this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.remove(key);
|
239
|
-
});
|
240
|
-
// 删除hinasdk_tab数据
|
241
|
-
var index = tabStorageList.findIndex(function (item) { return item.dataKey === firstKey; });
|
242
|
-
if (index >= 0) {
|
243
|
-
var list = tabStorageList.slice(0, index);
|
244
|
-
(_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.set(this.batchKey, JSON.stringify(list));
|
245
|
-
}
|
246
|
-
};
|
247
|
-
BatchSend.prototype.add = function (data) {
|
248
|
-
var _a, _b;
|
249
|
-
var _c = this.getBatchConfig(), sendInterval = _c.sendInterval, storageLimit = _c.storageLimit;
|
250
|
-
var dataKey = this.batchDataKey + getRandom();
|
251
|
-
var tabStorage = this.getStorageList();
|
252
|
-
tabStorage.unshift({
|
253
|
-
dataKey: dataKey,
|
254
|
-
expireTime: nowStamp() + sendInterval * 2
|
255
|
-
});
|
256
|
-
(_a = this.context.store.localStorage) === null || _a === void 0 ? void 0 : _a.set(this.batchKey, JSON.stringify(tabStorage));
|
257
|
-
(_b = this.context.store.localStorage) === null || _b === void 0 ? void 0 : _b.set(dataKey, JSON.stringify(data));
|
258
|
-
/**
|
259
|
-
* 满足以下条件,则发送数据
|
260
|
-
* 1. localStorage 条数超过最大限制
|
261
|
-
* 2. 发送类型为 track_signup 或 H_pageview
|
262
|
-
*/
|
263
|
-
if (tabStorage.length > storageLimit ||
|
264
|
-
data.type === 'track_signup' ||
|
265
|
-
data.event === 'H_pageview') {
|
266
|
-
this.send();
|
267
|
-
}
|
268
|
-
};
|
269
|
-
return BatchSend;
|
270
|
-
}());
|
271
|
-
|
272
|
-
var ClickTrackPlugin = /** @class */ (function (_super) {
|
273
|
-
__extends(ClickTrackPlugin, _super);
|
274
|
-
function ClickTrackPlugin(options, context) {
|
275
|
-
var _this = _super.call(this, options, context) || this;
|
276
|
-
_this.options = options;
|
277
|
-
_this.context = context;
|
278
|
-
/**
|
279
|
-
* 插件名
|
280
|
-
*/
|
281
|
-
_this.name = 'ClickTrackPlugin';
|
282
|
-
/**
|
283
|
-
* 默认采集标签
|
284
|
-
*/
|
285
|
-
_this.isTrackList = {
|
286
|
-
a: true,
|
287
|
-
button: true
|
288
|
-
};
|
289
|
-
return _this;
|
290
|
-
}
|
291
|
-
ClickTrackPlugin.prototype.init = function (notify) {
|
292
|
-
var _this = this;
|
293
|
-
var _a = this.options.autoTrackConfig, clickAutoTrack = _a.clickAutoTrack, isCollectUrl = _a.isCollectUrl, isCollectElement = _a.isCollectElement, addCustomProperty = _a.addCustomProperty;
|
294
|
-
if (clickAutoTrack !== true)
|
295
|
-
return;
|
296
|
-
document.addEventListener('click', function (e) {
|
297
|
-
if (!isCollectUrl())
|
298
|
-
return;
|
299
|
-
var event = e || window.event;
|
300
|
-
if (!event)
|
301
|
-
return;
|
302
|
-
var eventTarget = event.target || event.srcElement;
|
303
|
-
var target = _this.getTargetElement(eventTarget, event);
|
304
|
-
if (target) {
|
305
|
-
// 判断是否要上报此元素的点击事件
|
306
|
-
if (isFunction(isCollectElement) && !isCollectElement(target)) {
|
307
|
-
return false;
|
308
|
-
}
|
309
|
-
var props = _this.getClickElementInfo(target);
|
310
|
-
var _a = _this.getPageXYInfo(event, target), H_page_x = _a.H_page_x, H_page_y = _a.H_page_y;
|
311
|
-
props.H_page_x = H_page_x;
|
312
|
-
props.H_page_y = H_page_y;
|
313
|
-
if (isFunction(addCustomProperty)) {
|
314
|
-
var customProperty = addCustomProperty(target);
|
315
|
-
if (isObject(customProperty)) {
|
316
|
-
props = merge(props, customProperty);
|
317
|
-
}
|
318
|
-
}
|
319
|
-
notify(props);
|
320
|
-
}
|
321
|
-
}, true);
|
322
|
-
};
|
323
|
-
ClickTrackPlugin.prototype.transform = function (data) {
|
324
|
-
var props = this.context.getReportData('track', 'H_WebClick', data);
|
325
|
-
return props;
|
326
|
-
};
|
327
|
-
ClickTrackPlugin.prototype.hasAttribute = function (element, attrName) {
|
328
|
-
var _a;
|
329
|
-
if (element.hasAttribute) {
|
330
|
-
return element.hasAttribute(attrName);
|
331
|
-
}
|
332
|
-
if (element.attributes) {
|
333
|
-
return !!((_a = element.attributes[attrName]) === null || _a === void 0 ? void 0 : _a.value);
|
334
|
-
}
|
335
|
-
};
|
336
|
-
ClickTrackPlugin.prototype.hasAttributes = function (element, attrNames) {
|
337
|
-
if (isArray(attrNames)) {
|
338
|
-
for (var i = 0; i < attrNames.length; i++) {
|
339
|
-
if (this.hasAttribute(element, attrNames[i])) {
|
340
|
-
return true;
|
341
|
-
}
|
342
|
-
}
|
343
|
-
}
|
344
|
-
return false;
|
345
|
-
};
|
346
|
-
ClickTrackPlugin.prototype.hasElement = function (element) {
|
347
|
-
var e_1, _a;
|
348
|
-
var _b;
|
349
|
-
var paths = getElementParents(element);
|
350
|
-
var trackAttr = this.options.autoTrackConfig.trackAttr || [];
|
351
|
-
if (isArray(paths) && paths.length > 0) {
|
352
|
-
try {
|
353
|
-
for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
|
354
|
-
var path = paths_1_1.value;
|
355
|
-
var tagName = (_b = path.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
356
|
-
if (isElement(path) &&
|
357
|
-
(this.isTrackList[tagName] || this.hasAttributes(path, trackAttr))) {
|
358
|
-
return path;
|
359
|
-
}
|
360
|
-
}
|
361
|
-
}
|
362
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
363
|
-
finally {
|
364
|
-
try {
|
365
|
-
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
|
366
|
-
}
|
367
|
-
finally { if (e_1) throw e_1.error; }
|
368
|
-
}
|
369
|
-
}
|
370
|
-
};
|
371
|
-
ClickTrackPlugin.prototype.getDivMaxLevel = function () {
|
372
|
-
var _a;
|
373
|
-
var collectTags = this.options.autoTrackConfig.collectTags;
|
374
|
-
return ((_a = collectTags.div) === null || _a === void 0 ? void 0 : _a.maxLevel) || 1;
|
375
|
-
};
|
376
|
-
/**
|
377
|
-
* 针对div标签,判断是否是忽略的样式标签
|
378
|
-
* @param tagName
|
379
|
-
*/
|
380
|
-
ClickTrackPlugin.prototype.isStyleTag = function (tagName) {
|
381
|
-
var _a;
|
382
|
-
var collectTags = this.options.autoTrackConfig.collectTags;
|
383
|
-
var ignoreTags = ((_a = collectTags.div) === null || _a === void 0 ? void 0 : _a.ignoreTags) || [];
|
384
|
-
return ignoreTags === null || ignoreTags === void 0 ? void 0 : ignoreTags.includes(tagName);
|
385
|
-
};
|
386
|
-
/**
|
387
|
-
* 获取可采集元素的父元素
|
388
|
-
* @param target
|
389
|
-
*/
|
390
|
-
ClickTrackPlugin.prototype.getCollectableParent = function (target) {
|
391
|
-
var _a;
|
392
|
-
try {
|
393
|
-
var parentNode = target.parentNode;
|
394
|
-
var parentTagName = parentNode ? (_a = parentNode.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase() : '';
|
395
|
-
if (parentTagName === 'body') {
|
396
|
-
return false;
|
397
|
-
}
|
398
|
-
var maxLevel = this.getDivMaxLevel();
|
399
|
-
if (parentTagName === 'div' &&
|
400
|
-
(maxLevel > 1 || this.isCollectableDiv(parentNode))) {
|
401
|
-
return parentNode;
|
402
|
-
}
|
403
|
-
if (parentNode && this.isStyleTag(parentTagName)) {
|
404
|
-
return this.getCollectableParent(parentNode);
|
405
|
-
}
|
406
|
-
}
|
407
|
-
catch (error) {
|
408
|
-
this.context.log(error, ConsoleTypes.ERROR);
|
409
|
-
}
|
410
|
-
return false;
|
411
|
-
};
|
412
|
-
/**
|
413
|
-
* 是否是可以收集的div
|
414
|
-
* @param element
|
415
|
-
*/
|
416
|
-
ClickTrackPlugin.prototype.isCollectableDiv = function (element) {
|
417
|
-
var _a;
|
418
|
-
try {
|
419
|
-
var children = element.children || [];
|
420
|
-
if (children.length === 0) {
|
421
|
-
return true;
|
422
|
-
}
|
423
|
-
for (var i = 0; i < children.length; i++) {
|
424
|
-
var child = children[i];
|
425
|
-
if (isElement(child)) {
|
426
|
-
var tagName = (_a = child.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
427
|
-
var maxLevel = this.getDivMaxLevel();
|
428
|
-
if ((tagName === 'div' && maxLevel > 1) || this.isStyleTag(tagName)) {
|
429
|
-
if (!this.isCollectableDiv(child)) {
|
430
|
-
return false;
|
431
|
-
}
|
432
|
-
}
|
433
|
-
else {
|
434
|
-
return false;
|
435
|
-
}
|
436
|
-
}
|
437
|
-
}
|
438
|
-
return true;
|
439
|
-
}
|
440
|
-
catch (error) {
|
441
|
-
this.context.log(error, ConsoleTypes.ERROR);
|
442
|
-
}
|
443
|
-
return false;
|
444
|
-
};
|
445
|
-
/**
|
446
|
-
* 判断div的层级是否有效
|
447
|
-
* @param rootElement
|
448
|
-
*/
|
449
|
-
ClickTrackPlugin.prototype.isDivLevelValid = function (rootElement) {
|
450
|
-
var maxLevel = this.getDivMaxLevel();
|
451
|
-
var htmlCollection = rootElement.getElementsByTagName('div');
|
452
|
-
for (var i = htmlCollection.length - 1; i >= 0; i--) {
|
453
|
-
if (this.getDivLevels(htmlCollection[i], rootElement) > maxLevel) {
|
454
|
-
return false;
|
455
|
-
}
|
456
|
-
}
|
457
|
-
return true;
|
458
|
-
};
|
459
|
-
/**
|
460
|
-
* 获取指定元素的路径
|
461
|
-
* @param element 当前元素
|
462
|
-
* @param ignoreId 是否忽略id
|
463
|
-
* @param rootElement 根元素
|
464
|
-
*/
|
465
|
-
ClickTrackPlugin.prototype.getElementPath = function (element, ignoreId, rootElement) {
|
466
|
-
var _a, _b;
|
467
|
-
var names = [];
|
468
|
-
while (isElement(element) && element.parentNode) {
|
469
|
-
if (element.id &&
|
470
|
-
!ignoreId &&
|
471
|
-
/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.id)) {
|
472
|
-
var tagName = element.tagName || '';
|
473
|
-
names.unshift("".concat(tagName.toLowerCase(), "#").concat(element.id));
|
474
|
-
break;
|
475
|
-
}
|
476
|
-
else {
|
477
|
-
if (rootElement && element === rootElement) {
|
478
|
-
names.unshift((_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
479
|
-
break;
|
480
|
-
}
|
481
|
-
else if (element === document.body) {
|
482
|
-
names.unshift('body');
|
483
|
-
break;
|
484
|
-
}
|
485
|
-
else {
|
486
|
-
names.unshift((_b = element.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase());
|
487
|
-
}
|
488
|
-
element = element.parentNode;
|
489
|
-
}
|
490
|
-
}
|
491
|
-
return names.join(' > ');
|
492
|
-
};
|
493
|
-
ClickTrackPlugin.prototype.getDivLevels = function (element, rootElement) {
|
494
|
-
var path = this.getElementPath(element, true, rootElement);
|
495
|
-
var pathArr = path.split(' > ');
|
496
|
-
var level = 0;
|
497
|
-
pathArr.forEach(function (tag) {
|
498
|
-
if (tag === 'div') {
|
499
|
-
level++;
|
500
|
-
}
|
501
|
-
});
|
502
|
-
return level;
|
503
|
-
};
|
504
|
-
ClickTrackPlugin.prototype.getTargetElement = function (eventTarget, event) {
|
505
|
-
var _a;
|
506
|
-
if (!isElement(eventTarget)) {
|
507
|
-
return null;
|
508
|
-
}
|
509
|
-
var tagName = (_a = eventTarget.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
510
|
-
if (!isString(tagName)) {
|
511
|
-
return null;
|
512
|
-
}
|
513
|
-
if (['body', 'html'].includes(tagName)) {
|
514
|
-
return null;
|
515
|
-
}
|
516
|
-
if (this.context.trackTags.includes(tagName) && tagName !== 'div') {
|
517
|
-
return eventTarget;
|
518
|
-
}
|
519
|
-
/**
|
520
|
-
* div处理情况
|
521
|
-
* 1.div为子结点(无子元素)时采集 div 的点击;
|
522
|
-
* 2.div中有且只有样式标签([‘mark’,’strong’,’b’,’em’,’i’,’u’,’abbr’,’ins’,’del’,’s’,’sup’])时,点击 div 或者样式标签都采集 div 的点击。
|
523
|
-
* 3.div 通过配置最多可以采集3层嵌套情况
|
524
|
-
*/
|
525
|
-
if (tagName === 'div') {
|
526
|
-
if (this.isDivLevelValid(eventTarget)) {
|
527
|
-
var maxLevel = this.getDivMaxLevel();
|
528
|
-
if (maxLevel > 1 || this.isCollectableDiv(eventTarget)) {
|
529
|
-
return eventTarget;
|
530
|
-
}
|
531
|
-
}
|
532
|
-
}
|
533
|
-
if (this.isStyleTag(tagName) &&
|
534
|
-
this.options.autoTrackConfig.collectTags.div) {
|
535
|
-
var parentTrackDiv = this.getCollectableParent(eventTarget);
|
536
|
-
if (parentTrackDiv && this.isDivLevelValid(parentTrackDiv)) {
|
537
|
-
return parentTrackDiv;
|
538
|
-
}
|
539
|
-
}
|
540
|
-
return this.hasElement(eventTarget) || null;
|
541
|
-
};
|
542
|
-
ClickTrackPlugin.prototype.getPageXYInfo = function (event, target) {
|
543
|
-
if (!event) {
|
544
|
-
return {};
|
545
|
-
}
|
546
|
-
var scrollLeft = getScrollLeft();
|
547
|
-
var scrollTop = getScrollTop();
|
548
|
-
var rect = target.getBoundingClientRect();
|
549
|
-
var pageX = event.pageX ||
|
550
|
-
event.clientX + scrollLeft ||
|
551
|
-
event.offsetX + ((rect === null || rect === void 0 ? void 0 : rect.left) || 0) + scrollLeft;
|
552
|
-
var pageY = event.pageY ||
|
553
|
-
event.clientY + scrollTop ||
|
554
|
-
event.offsetY + ((rect === null || rect === void 0 ? void 0 : rect.top) || 0) + scrollTop;
|
555
|
-
return {
|
556
|
-
H_page_x: formatDecimal(pageX, 3),
|
557
|
-
H_page_y: formatDecimal(pageY, 3)
|
558
|
-
};
|
559
|
-
};
|
560
|
-
ClickTrackPlugin.prototype.getClickElementInfo = function (element) {
|
561
|
-
var isCollectInput = this.options.autoTrackConfig.isCollectInput;
|
562
|
-
var isCollectInputValue = false;
|
563
|
-
if (isFunction(isCollectInput)) {
|
564
|
-
isCollectInputValue = isCollectInput(element);
|
565
|
-
}
|
566
|
-
var selector = this.getDomSelector(element);
|
567
|
-
var props = getElementProperties(element, isCollectInputValue);
|
568
|
-
props.H_element_selector = selector;
|
569
|
-
props.H_element_path = this.getElementPath(element, false);
|
570
|
-
return props;
|
571
|
-
};
|
572
|
-
ClickTrackPlugin.prototype.getDomSelector = function (element) {
|
573
|
-
var _a;
|
574
|
-
var paths = [];
|
575
|
-
while (element) {
|
576
|
-
var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
577
|
-
if (tagName === 'body' || !isElement(element)) {
|
578
|
-
paths.unshift('body');
|
579
|
-
break;
|
580
|
-
}
|
581
|
-
paths.unshift(this.getSelector(element));
|
582
|
-
if ((element === null || element === void 0 ? void 0 : element.getAttribute('id')) &&
|
583
|
-
/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(element.getAttribute('id'))) {
|
584
|
-
break;
|
585
|
-
}
|
586
|
-
element = element.parentNode;
|
587
|
-
}
|
588
|
-
return paths.join(' > ');
|
589
|
-
};
|
590
|
-
ClickTrackPlugin.prototype.getSelector = function (element) {
|
591
|
-
var _a, _b;
|
592
|
-
var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
593
|
-
var i = -1;
|
594
|
-
if (((_b = element.parentNode) === null || _b === void 0 ? void 0 : _b.nodeType) !== 9) {
|
595
|
-
i = this.getDomIndex(element);
|
596
|
-
}
|
597
|
-
var idValue = element.getAttribute('id');
|
598
|
-
if (idValue && /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(idValue)) {
|
599
|
-
return "#".concat(idValue);
|
600
|
-
}
|
601
|
-
return tagName + (i > -1 ? ":nth-of-type(".concat(i + 1, ")") : '');
|
602
|
-
};
|
603
|
-
ClickTrackPlugin.prototype.getDomIndex = function (element) {
|
604
|
-
var _a, _b;
|
605
|
-
if (element.parentNode) {
|
606
|
-
var index = 0;
|
607
|
-
var tagName = (_a = element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
608
|
-
var children = element.parentNode.children;
|
609
|
-
for (var i = 0; i < children.length; i++) {
|
610
|
-
var child = children[i];
|
611
|
-
var childTagName = (_b = child.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
612
|
-
if (childTagName === tagName) {
|
613
|
-
if (child === element) {
|
614
|
-
return index;
|
615
|
-
}
|
616
|
-
index++;
|
617
|
-
}
|
618
|
-
}
|
619
|
-
}
|
620
|
-
return -1;
|
621
|
-
};
|
622
|
-
return ClickTrackPlugin;
|
623
|
-
}(PluginBase));
|
624
|
-
|
625
|
-
var StayTrackPlugin = /** @class */ (function (_super) {
|
626
|
-
__extends(StayTrackPlugin, _super);
|
627
|
-
function StayTrackPlugin(options, context) {
|
628
|
-
var _this = _super.call(this, options, context) || this;
|
629
|
-
_this.options = options;
|
630
|
-
_this.context = context;
|
631
|
-
_this.name = 'StayTrackPlugin';
|
632
|
-
_this.timer = null;
|
633
|
-
_this.previousTime = nowStamp();
|
634
|
-
_this.previousOffsetTop = 0;
|
635
|
-
return _this;
|
636
|
-
}
|
637
|
-
StayTrackPlugin.prototype.init = function (notify) {
|
638
|
-
var _this = this;
|
639
|
-
var _a = this.options, autoTrackConfig = _a.autoTrackConfig, stayAutoTrackConfig = _a.stayAutoTrackConfig;
|
640
|
-
if (autoTrackConfig.stayAutoTrack !== true) {
|
641
|
-
return;
|
642
|
-
}
|
643
|
-
var isCollectUrl = stayAutoTrackConfig.isCollectUrl;
|
644
|
-
if (!isFunction(isCollectUrl)) {
|
645
|
-
isCollectUrl = function () { return true; };
|
646
|
-
}
|
647
|
-
if (this.timer) {
|
648
|
-
clearTimeout(this.timer);
|
649
|
-
this.timer = null;
|
650
|
-
}
|
651
|
-
this.previousTime = nowStamp();
|
652
|
-
window.addEventListener('load', function () {
|
653
|
-
_this.previousOffsetTop = getScrollTop();
|
654
|
-
});
|
655
|
-
window.addEventListener('scroll', function () {
|
656
|
-
if (!isCollectUrl())
|
657
|
-
return;
|
658
|
-
if (_this.timer)
|
659
|
-
return;
|
660
|
-
_this.timer = setTimeout(function () {
|
661
|
-
_this.run(notify);
|
662
|
-
clearTimeout(_this.timer);
|
663
|
-
_this.timer = null;
|
664
|
-
}, 1000);
|
665
|
-
});
|
666
|
-
window.addEventListener('unload', function () {
|
667
|
-
if (!isCollectUrl())
|
668
|
-
return;
|
669
|
-
_this.run(notify, true);
|
670
|
-
});
|
671
|
-
};
|
672
|
-
StayTrackPlugin.prototype.transform = function (data) {
|
673
|
-
var props = this.context.getReportData('track', 'H_WebStay', data);
|
674
|
-
return props;
|
675
|
-
};
|
676
|
-
StayTrackPlugin.prototype.run = function (notify, isClosePage) {
|
677
|
-
if (isClosePage === void 0) { isClosePage = false; }
|
678
|
-
var autoTrackConfig = this.options.autoTrackConfig;
|
679
|
-
var stayDelayTime = autoTrackConfig.stayDelayTime, maxStayPageDuration = autoTrackConfig.maxStayPageDuration;
|
680
|
-
var offsetTop = getScrollTop();
|
681
|
-
var nowTime = nowStamp();
|
682
|
-
var duration = nowTime - this.previousTime;
|
683
|
-
if (isClosePage ||
|
684
|
-
(duration > stayDelayTime && offsetTop !== this.previousOffsetTop)) {
|
685
|
-
var props = {
|
686
|
-
H_viewport_position: this.previousOffsetTop,
|
687
|
-
event_duration: Math.min(duration / 1000, maxStayPageDuration)
|
688
|
-
};
|
689
|
-
notify(props);
|
690
|
-
}
|
691
|
-
this.previousTime = nowTime;
|
692
|
-
this.previousOffsetTop = offsetTop;
|
693
|
-
};
|
694
|
-
return StayTrackPlugin;
|
695
|
-
}(PluginBase));
|
696
|
-
|
697
|
-
var PageLeavePluginName = 'PageLeavePlugin';
|
698
|
-
var PageLeavePlugin = /** @class */ (function (_super) {
|
699
|
-
__extends(PageLeavePlugin, _super);
|
700
|
-
function PageLeavePlugin(options, context) {
|
701
|
-
var _this = _super.call(this, options, context) || this;
|
702
|
-
_this.options = options;
|
703
|
-
_this.context = context;
|
704
|
-
_this.name = PageLeavePluginName;
|
705
|
-
_this.pageId = Number(String(getRandom()).slice(2, 5) +
|
706
|
-
String(getRandom()).slice(2, 4) +
|
707
|
-
String(nowStamp()).slice(-4));
|
708
|
-
_this.storageName = 'hinasdk_pageleave_';
|
709
|
-
_this.heartbeatIntervalTime = 5000; // 5s
|
710
|
-
_this.maxDuration = 432000; // 5天
|
711
|
-
_this.heartbeatIntervalTimer = null;
|
712
|
-
_this.startTime = nowStamp();
|
713
|
-
/**
|
714
|
-
* 页面url
|
715
|
-
*/
|
716
|
-
_this.url = window.location.href;
|
717
|
-
/**
|
718
|
-
* 上一个页面url
|
719
|
-
*/
|
720
|
-
_this.previousUrl = document.referrer;
|
721
|
-
/**
|
722
|
-
* 页面显示状态
|
723
|
-
*/
|
724
|
-
_this.pageShowStatus = true;
|
725
|
-
return _this;
|
726
|
-
}
|
727
|
-
PageLeavePlugin.prototype.init = function () {
|
728
|
-
var pageLeaveAutoTrack = this.options.autoTrackConfig.pageLeaveAutoTrack;
|
729
|
-
if (!pageLeaveAutoTrack)
|
730
|
-
return;
|
731
|
-
var _a = this.normalizePageLeaveAutoTrack(), heartbeat_interval_time = _a.heartbeat_interval_time, max_duration = _a.max_duration;
|
732
|
-
if (heartbeat_interval_time && heartbeat_interval_time > 0) {
|
733
|
-
this.heartbeatIntervalTime = heartbeat_interval_time * 1000;
|
734
|
-
}
|
735
|
-
if (max_duration && max_duration > 0) {
|
736
|
-
this.maxDuration = Number(max_duration);
|
737
|
-
}
|
738
|
-
this.startTime = nowStamp();
|
739
|
-
this.addPageLeaveEventListener();
|
740
|
-
if (document.hidden) {
|
741
|
-
this.pageShowStatus = false;
|
742
|
-
}
|
743
|
-
else {
|
744
|
-
this.addHeartBeatInterval();
|
745
|
-
}
|
746
|
-
};
|
747
|
-
PageLeavePlugin.prototype.transform = function (data) {
|
748
|
-
return undefined;
|
749
|
-
};
|
750
|
-
PageLeavePlugin.prototype.normalizePageLeaveAutoTrack = function () {
|
751
|
-
var pageLeaveAutoTrack = this.options.autoTrackConfig.pageLeaveAutoTrack;
|
752
|
-
return isObject(pageLeaveAutoTrack)
|
753
|
-
? pageLeaveAutoTrack
|
754
|
-
: {};
|
755
|
-
};
|
756
|
-
PageLeavePlugin.prototype.addPageLeaveEventListener = function () {
|
757
|
-
this.addPageStartListener();
|
758
|
-
this.addPageSwitchListener();
|
759
|
-
this.addSinglePageListener();
|
760
|
-
this.addPageEndListener();
|
761
|
-
};
|
762
|
-
PageLeavePlugin.prototype.addPageStartListener = function () {
|
763
|
-
var _this = this;
|
764
|
-
if ('onpageshow' in window) {
|
765
|
-
window.addEventListener('pageshow', function () {
|
766
|
-
_this.pageStartHandler();
|
767
|
-
});
|
768
|
-
}
|
769
|
-
};
|
770
|
-
PageLeavePlugin.prototype.addPageSwitchListener = function () {
|
771
|
-
var _this = this;
|
772
|
-
new ListenPageState({
|
773
|
-
visible: function () {
|
774
|
-
_this.pageStartHandler();
|
775
|
-
_this.addHeartBeatInterval();
|
776
|
-
},
|
777
|
-
hidden: function () {
|
778
|
-
_this.url = window.location.href;
|
779
|
-
_this.pageEndHandler();
|
780
|
-
_this.stopHeartBeatInterval();
|
781
|
-
}
|
782
|
-
});
|
783
|
-
};
|
784
|
-
PageLeavePlugin.prototype.addSinglePageListener = function () {
|
785
|
-
var _this = this;
|
786
|
-
mitt.on('urlChange', function (params) {
|
787
|
-
var fromHref = params.fromHref;
|
788
|
-
if (fromHref !== window.location.href) {
|
789
|
-
_this.url = fromHref;
|
790
|
-
_this.pageEndHandler();
|
791
|
-
_this.stopHeartBeatInterval();
|
792
|
-
_this.pageStartHandler();
|
793
|
-
_this.addHeartBeatInterval();
|
794
|
-
}
|
795
|
-
});
|
796
|
-
};
|
797
|
-
PageLeavePlugin.prototype.addPageEndListener = function () {
|
798
|
-
var _this = this;
|
799
|
-
var events = ['pagehide', 'beforeunload', 'unload'];
|
800
|
-
events.forEach(function (event) {
|
801
|
-
if ("on".concat(events) in window) {
|
802
|
-
window.addEventListener(event, function () {
|
803
|
-
_this.pageEndHandler();
|
804
|
-
_this.stopHeartBeatInterval();
|
805
|
-
});
|
806
|
-
}
|
807
|
-
});
|
808
|
-
};
|
809
|
-
PageLeavePlugin.prototype.pageStartHandler = function () {
|
810
|
-
this.startTime = nowStamp();
|
811
|
-
this.pageShowStatus = !document.hidden;
|
812
|
-
this.url = window.location.href;
|
813
|
-
};
|
814
|
-
PageLeavePlugin.prototype.pageEndHandler = function () {
|
815
|
-
if (!this.pageShowStatus)
|
816
|
-
return;
|
817
|
-
this.pageShowStatus = false;
|
818
|
-
if (this.isCollectUrl()) {
|
819
|
-
var properties = this.getPageLeaveProperties();
|
820
|
-
var data = this.context.getReportData('track', 'H_WebPageLeave', properties);
|
821
|
-
this.context.report(data);
|
822
|
-
}
|
823
|
-
this.delHeartBeatData();
|
824
|
-
};
|
825
|
-
PageLeavePlugin.prototype.addHeartBeatInterval = function () {
|
826
|
-
if (!this.context.store.localStorage)
|
827
|
-
return;
|
828
|
-
this.startHeartBeatInterval();
|
829
|
-
};
|
830
|
-
PageLeavePlugin.prototype.startHeartBeatInterval = function () {
|
831
|
-
var _this = this;
|
832
|
-
if (this.heartbeatIntervalTimer) {
|
833
|
-
this.stopHeartBeatInterval();
|
834
|
-
}
|
835
|
-
if (this.isCollectUrl()) {
|
836
|
-
this.heartbeatIntervalTimer = setInterval(function () {
|
837
|
-
_this.saveHeartBeatData();
|
838
|
-
}, this.heartbeatIntervalTime);
|
839
|
-
this.saveHeartBeatData('first_heartbeat');
|
840
|
-
}
|
841
|
-
this.reissueHeartBeatData();
|
842
|
-
};
|
843
|
-
PageLeavePlugin.prototype.reissueHeartBeatData = function () {
|
844
|
-
var localStorage = this.context.store.localStorage;
|
845
|
-
var storageLen = localStorage.length();
|
846
|
-
for (var i = 0; i < storageLen; i++) {
|
847
|
-
var itemKey = localStorage.key(i);
|
848
|
-
if (itemKey &&
|
849
|
-
itemKey !== this.storageName + this.pageId &&
|
850
|
-
itemKey.includes(this.storageName)) {
|
851
|
-
var value = localStorage.get(itemKey);
|
852
|
-
var result = safeJSONParse(value);
|
853
|
-
if (isObject(result) &&
|
854
|
-
nowStamp() - result.time > result.heartbeat_interval_time + 5000) {
|
855
|
-
delete result.heartbeat_interval_time;
|
856
|
-
this.context.report(result);
|
857
|
-
}
|
858
|
-
this.delHeartBeatData(itemKey);
|
859
|
-
}
|
860
|
-
}
|
861
|
-
};
|
862
|
-
PageLeavePlugin.prototype.stopHeartBeatInterval = function () {
|
863
|
-
if (this.heartbeatIntervalTimer) {
|
864
|
-
clearInterval(this.heartbeatIntervalTimer);
|
865
|
-
this.heartbeatIntervalTimer = null;
|
866
|
-
}
|
867
|
-
};
|
868
|
-
PageLeavePlugin.prototype.delHeartBeatData = function (storageKey) {
|
869
|
-
if (this.context.store.localStorage) {
|
870
|
-
this.context.store.localStorage.remove(storageKey || this.storageName + this.pageId);
|
871
|
-
}
|
872
|
-
};
|
873
|
-
PageLeavePlugin.prototype.isCollectUrl = function () {
|
874
|
-
var isCollectUrl = this.normalizePageLeaveAutoTrack().isCollectUrl;
|
875
|
-
if (isFunction(isCollectUrl)) {
|
876
|
-
return isCollectUrl(this.url);
|
877
|
-
}
|
878
|
-
return true;
|
879
|
-
};
|
880
|
-
PageLeavePlugin.prototype.saveHeartBeatData = function (type) {
|
881
|
-
var properties = this.getPageLeaveProperties();
|
882
|
-
properties.H_time = nowStamp();
|
883
|
-
if (type === 'first_heartbeat') {
|
884
|
-
properties.event_duration = 3;
|
885
|
-
}
|
886
|
-
var props = this.context.getReportData('track', 'H_WebPageLeave', properties);
|
887
|
-
props.heartbeat_interval_time = this.heartbeatIntervalTime;
|
888
|
-
this.context.store.localStorage.set(this.storageName + this.pageId, JSON.stringify(props));
|
889
|
-
};
|
890
|
-
PageLeavePlugin.prototype.getPageLeaveProperties = function () {
|
891
|
-
var duration = (nowStamp() - this.startTime) / 1000;
|
892
|
-
if (duration <= 0 || duration > this.maxDuration) {
|
893
|
-
duration = 0;
|
894
|
-
}
|
895
|
-
else {
|
896
|
-
duration = formatDecimal(duration, 3);
|
897
|
-
}
|
898
|
-
var _a = getURL(this.url), pathname = _a.pathname, hash = _a.hash;
|
899
|
-
var referrer = getReferrer(this.previousUrl);
|
900
|
-
var properties = {
|
901
|
-
H_url: this.url,
|
902
|
-
H_url_path: pathname,
|
903
|
-
H_url_hash: hash,
|
904
|
-
H_referrer: referrer,
|
905
|
-
H_referrer_host: referrer ? getHostname(referrer) : ''
|
906
|
-
};
|
907
|
-
if (duration) {
|
908
|
-
properties.event_duration = duration;
|
909
|
-
}
|
910
|
-
var custom_props = this.normalizePageLeaveAutoTrack().custom_props;
|
911
|
-
if (isObject(custom_props)) {
|
912
|
-
properties = __assign(__assign({}, properties), (custom_props || {}));
|
913
|
-
}
|
914
|
-
return properties;
|
915
|
-
};
|
916
|
-
return PageLeavePlugin;
|
917
|
-
}(PluginBase));
|
918
|
-
|
919
|
-
var SiteLinkerPluginName = 'SiteLinkerPlugin';
|
920
|
-
var SiteLinkerPlugin = /** @class */ (function (_super) {
|
921
|
-
__extends(SiteLinkerPlugin, _super);
|
922
|
-
function SiteLinkerPlugin(options, context) {
|
923
|
-
var _this = _super.call(this, options, context) || this;
|
924
|
-
_this.options = options;
|
925
|
-
_this.context = context;
|
926
|
-
_this.name = SiteLinkerPluginName;
|
927
|
-
_this.linker = [];
|
928
|
-
return _this;
|
929
|
-
}
|
930
|
-
SiteLinkerPlugin.prototype.init = function () {
|
931
|
-
var linker = this.getLinkerConfig().linker;
|
932
|
-
if (!(isArray(linker) && linker.length > 0)) {
|
933
|
-
this.context.log('siteLinker plugin: Please configure the linker parameter', ConsoleTypes.WARN);
|
934
|
-
return;
|
935
|
-
}
|
936
|
-
// 处理配置
|
937
|
-
this.resolveOption();
|
938
|
-
this.setRefferId();
|
939
|
-
this.addClickListen();
|
940
|
-
};
|
941
|
-
SiteLinkerPlugin.prototype.transform = function () {
|
942
|
-
return undefined;
|
943
|
-
};
|
944
|
-
SiteLinkerPlugin.prototype.getLinkerConfig = function () {
|
945
|
-
var _a = this.options.siteLinkerConfig || {}, _b = _a.linker, linker = _b === void 0 ? [] : _b, re_login = _a.re_login;
|
946
|
-
return {
|
947
|
-
linker: linker || [],
|
948
|
-
re_login: re_login
|
949
|
-
};
|
950
|
-
};
|
951
|
-
SiteLinkerPlugin.prototype.resolveOption = function () {
|
952
|
-
var linker = this.getLinkerConfig().linker;
|
953
|
-
var len = linker.length;
|
954
|
-
var arr = [];
|
955
|
-
for (var i = 0; i < len; i++) {
|
956
|
-
var _a = linker[i], part_url = _a.part_url, after_hash = _a.after_hash;
|
957
|
-
if (/[A-Za-z0-9]+\./.test(part_url) && isBoolean(after_hash)) {
|
958
|
-
arr.push({
|
959
|
-
part_url: part_url,
|
960
|
-
after_hash: after_hash
|
961
|
-
});
|
962
|
-
}
|
963
|
-
else {
|
964
|
-
this.context.log("The configuration of linker ".concat(i + 1, " is not supported.Please check format"), ConsoleTypes.WARN);
|
965
|
-
}
|
966
|
-
}
|
967
|
-
this.linker = arr;
|
968
|
-
};
|
969
|
-
/**
|
970
|
-
* 多域名打通设置
|
971
|
-
*/
|
972
|
-
SiteLinkerPlugin.prototype.setRefferId = function () {
|
973
|
-
var re_login = this.getLinkerConfig().re_login;
|
974
|
-
var urlId = this.getUrlId();
|
975
|
-
var isAnonymousId = urlId.startsWith('a');
|
976
|
-
urlId = urlId.substring(1);
|
977
|
-
if (urlId === '')
|
978
|
-
return;
|
979
|
-
var anonymousId = this.context.store.getAnonymousId();
|
980
|
-
var accountId = this.context.store.getAccountId();
|
981
|
-
if (isAnonymousId) {
|
982
|
-
if (urlId !== anonymousId) {
|
983
|
-
this.context.store.state.anonymousId = urlId;
|
984
|
-
this.context.store.save();
|
985
|
-
}
|
986
|
-
if (accountId) {
|
987
|
-
var props = this.context.getReportData('track_signup', 'H_SignUp', {});
|
988
|
-
this.context.report(props);
|
989
|
-
}
|
990
|
-
}
|
991
|
-
else if (!accountId || (re_login && accountId !== urlId)) {
|
992
|
-
this.context.setUserUId(urlId);
|
993
|
-
}
|
994
|
-
};
|
995
|
-
/**
|
996
|
-
* 获取链接上的id
|
997
|
-
*/
|
998
|
-
SiteLinkerPlugin.prototype.getUrlId = function () {
|
999
|
-
/**
|
1000
|
-
* 匿名ID:a 登录ID:u
|
1001
|
-
* 如果是匿名ID:返回的是a+匿名ID 如果是登录ID:返回的是u+登录ID
|
1002
|
-
*/
|
1003
|
-
var hnId = window.location.href.match(/_hnsdk=([au][^\?\#\&\=]+)/);
|
1004
|
-
if (isArray(hnId) && hnId[1]) {
|
1005
|
-
return handleDecodeURLComponent(hnId[1]);
|
1006
|
-
}
|
1007
|
-
return '';
|
1008
|
-
};
|
1009
|
-
/**
|
1010
|
-
* 判断url链接是否包含part_url
|
1011
|
-
* @param url
|
1012
|
-
*/
|
1013
|
-
SiteLinkerPlugin.prototype.getPartUrl = function (url) {
|
1014
|
-
var len = this.linker.length;
|
1015
|
-
for (var i = 0; i < len; i++) {
|
1016
|
-
if (url.includes(this.linker[i].part_url)) {
|
1017
|
-
return true;
|
1018
|
-
}
|
1019
|
-
}
|
1020
|
-
return false;
|
1021
|
-
};
|
1022
|
-
/**
|
1023
|
-
* 获取url链接对应的linker配置中after_hash的值
|
1024
|
-
* @param url
|
1025
|
-
*/
|
1026
|
-
SiteLinkerPlugin.prototype.getPartHash = function (url) {
|
1027
|
-
var len = this.linker.length;
|
1028
|
-
for (var i = 0; i < len; i++) {
|
1029
|
-
if (url.includes(this.linker[i].part_url)) {
|
1030
|
-
return this.linker[i].after_hash;
|
1031
|
-
}
|
1032
|
-
}
|
1033
|
-
return false;
|
1034
|
-
};
|
1035
|
-
/**
|
1036
|
-
* 获取当前的匿名ID和当前的登录ID
|
1037
|
-
*/
|
1038
|
-
SiteLinkerPlugin.prototype.getCurrentId = function () {
|
1039
|
-
var accountId = this.context.store.getAccountId();
|
1040
|
-
var anonymousId = this.context.store.getAnonymousId();
|
1041
|
-
var hnId = accountId ? "u".concat(accountId) : "a".concat(anonymousId);
|
1042
|
-
return handleEncodeURLComponent(hnId);
|
1043
|
-
};
|
1044
|
-
/**
|
1045
|
-
* 重写a 标签的href链接
|
1046
|
-
* @param url
|
1047
|
-
* @param dom
|
1048
|
-
*/
|
1049
|
-
SiteLinkerPlugin.prototype.rewriteUrl = function (url, dom) {
|
1050
|
-
/**
|
1051
|
-
* ([^?#]+):匹配直到遇到 ? 或 # 之前的任何字符,并将这部分捕获为第一组。
|
1052
|
-
* (\?[^#]*)?:可选地匹配 ? 后面直到遇到 # 之前的任何字符,并将这部分捕获为第二组。
|
1053
|
-
* (#.*)?:可选地匹配 # 后面的任何字符,并将这部分捕获为第三组。
|
1054
|
-
*/
|
1055
|
-
var reg = /([^?#]+)(\?[^#]*)?(#.*)?/;
|
1056
|
-
var arr = reg.exec(url);
|
1057
|
-
var normalizeUrl = '';
|
1058
|
-
if (!arr)
|
1059
|
-
return;
|
1060
|
-
var host = arr[1] || ''; // 'http://www.xx.com'
|
1061
|
-
var search = arr[2] || ''; // '?xxx=xxx'
|
1062
|
-
var hash = arr[3] || ''; // '#xxx=xxx'
|
1063
|
-
var hnId = "_hnsdk=".concat(this.getCurrentId());
|
1064
|
-
var changeHnId = function (str) {
|
1065
|
-
var list = str.split('&');
|
1066
|
-
var result = [];
|
1067
|
-
list.forEach(function (value) {
|
1068
|
-
if (value.includes('_hnsdk')) {
|
1069
|
-
result.push(hnId);
|
1070
|
-
}
|
1071
|
-
else {
|
1072
|
-
result.push(value);
|
1073
|
-
}
|
1074
|
-
});
|
1075
|
-
return result.join('&');
|
1076
|
-
};
|
1077
|
-
if (this.getPartHash(url)) {
|
1078
|
-
var hasQuery = hash.includes('?'); // 判断是#xxx?xxx=xxx的格式
|
1079
|
-
var index = hash.indexOf('_hnsdk');
|
1080
|
-
if (hasQuery) {
|
1081
|
-
if (index >= 0) {
|
1082
|
-
normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1, index)).concat(changeHnId(hash.substring(index, hash.length)));
|
1083
|
-
}
|
1084
|
-
else {
|
1085
|
-
normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1), "&").concat(hnId);
|
1086
|
-
}
|
1087
|
-
}
|
1088
|
-
else {
|
1089
|
-
normalizeUrl = "".concat(host).concat(search, "#").concat(hash.substring(1), "?").concat(hnId);
|
1090
|
-
}
|
1091
|
-
}
|
1092
|
-
else {
|
1093
|
-
var hasQuery = /^\?(\w)+/.test(search); // 判断是否有?xxx=xxx的格式
|
1094
|
-
if (hasQuery) {
|
1095
|
-
if (search.includes('_hnsdk')) {
|
1096
|
-
normalizeUrl = "".concat(host, "?").concat(changeHnId(search.substring(1))).concat(hash);
|
1097
|
-
}
|
1098
|
-
else {
|
1099
|
-
normalizeUrl = "".concat(host).concat(search, "&").concat(hnId).concat(hash);
|
1100
|
-
}
|
1101
|
-
}
|
1102
|
-
else {
|
1103
|
-
normalizeUrl = "".concat(host, "?").concat(hnId).concat(hash);
|
1104
|
-
}
|
1105
|
-
}
|
1106
|
-
if (dom) {
|
1107
|
-
dom.href = normalizeUrl;
|
1108
|
-
}
|
1109
|
-
return normalizeUrl;
|
1110
|
-
};
|
1111
|
-
SiteLinkerPlugin.prototype.addClickListen = function () {
|
1112
|
-
var _this = this;
|
1113
|
-
var handleClick = function (event) {
|
1114
|
-
var _a, _b;
|
1115
|
-
var target = event.target;
|
1116
|
-
if (!target)
|
1117
|
-
return;
|
1118
|
-
var tagName = (_a = target.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
1119
|
-
var parentNode = target.parentNode;
|
1120
|
-
var parentTagName = (_b = parentNode === null || parentNode === void 0 ? void 0 : parentNode.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
1121
|
-
if ((tagName === 'a' && target.href) ||
|
1122
|
-
(parentTagName === 'a' && parentNode.href)) {
|
1123
|
-
var sdkUrl = void 0;
|
1124
|
-
var sdkTarget = void 0;
|
1125
|
-
if (tagName === 'a' && target.href) {
|
1126
|
-
sdkUrl = target.href;
|
1127
|
-
sdkTarget = target;
|
1128
|
-
}
|
1129
|
-
else {
|
1130
|
-
sdkUrl = parentNode.href;
|
1131
|
-
sdkTarget = parentNode;
|
1132
|
-
}
|
1133
|
-
var protocol = getURL(sdkUrl).protocol;
|
1134
|
-
if (protocol === 'http:' || protocol === 'https:') {
|
1135
|
-
if (_this.getPartUrl(sdkUrl)) {
|
1136
|
-
_this.rewriteUrl(sdkUrl, sdkTarget);
|
1137
|
-
}
|
1138
|
-
}
|
1139
|
-
}
|
1140
|
-
};
|
1141
|
-
if ('PointerEvent' in window) {
|
1142
|
-
document.addEventListener('pointerdown', handleClick);
|
1143
|
-
}
|
1144
|
-
else {
|
1145
|
-
document.addEventListener('mousedown', handleClick);
|
1146
|
-
}
|
1147
|
-
};
|
1148
|
-
return SiteLinkerPlugin;
|
1149
|
-
}(PluginBase));
|
1150
|
-
|
1151
|
-
var HistoryPlugin = /** @class */ (function (_super) {
|
1152
|
-
__extends(HistoryPlugin, _super);
|
1153
|
-
function HistoryPlugin(options, context) {
|
1154
|
-
var _this = _super.call(this, options, context) || this;
|
1155
|
-
_this.options = options;
|
1156
|
-
_this.context = context;
|
1157
|
-
_this.name = 'HistoryPlugin';
|
1158
|
-
/**
|
1159
|
-
* 上一次页面url
|
1160
|
-
*/
|
1161
|
-
_this.lastHref = window.location.href;
|
1162
|
-
/**
|
1163
|
-
* 上一次路由path
|
1164
|
-
*/
|
1165
|
-
_this.lastPath = window.location.pathname;
|
1166
|
-
return _this;
|
1167
|
-
}
|
1168
|
-
HistoryPlugin.prototype.init = function (notify) {
|
1169
|
-
if (!supportHistory())
|
1170
|
-
return;
|
1171
|
-
var _a = this.options, isSinglePage = _a.isSinglePage, pageviewAutoTrack = _a.autoTrackConfig.pageviewAutoTrack;
|
1172
|
-
var self = this;
|
1173
|
-
var originalOnpopstate = window.onpopstate;
|
1174
|
-
var handleRouterChange = function (currentPath, currentHref) {
|
1175
|
-
var params = {
|
1176
|
-
fromPath: self.lastPath,
|
1177
|
-
fromHref: self.lastHref,
|
1178
|
-
toPath: currentPath,
|
1179
|
-
toHref: currentHref
|
1180
|
-
};
|
1181
|
-
self.lastPath = currentPath;
|
1182
|
-
self.lastHref = currentHref;
|
1183
|
-
mitt.emit('urlChange', __assign(__assign({}, params), { mode: 'history' }));
|
1184
|
-
if (isSinglePage || pageviewAutoTrack === 'singlePage') {
|
1185
|
-
if (isFunction(isSinglePage)) {
|
1186
|
-
var extra = isSinglePage();
|
1187
|
-
if (isObject(extra)) {
|
1188
|
-
params = __assign(__assign({}, params), extra);
|
1189
|
-
}
|
1190
|
-
}
|
1191
|
-
notify(__assign(__assign({}, params), { H_referrer: self.lastHref }));
|
1192
|
-
}
|
1193
|
-
};
|
1194
|
-
window.onpopstate = function () {
|
1195
|
-
var args = [];
|
1196
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
1197
|
-
args[_i] = arguments[_i];
|
1198
|
-
}
|
1199
|
-
var currentPath = window.location.pathname;
|
1200
|
-
var currentHref = window.location.href;
|
1201
|
-
handleRouterChange(currentPath, currentHref);
|
1202
|
-
originalOnpopstate && originalOnpopstate.apply(this, args);
|
1203
|
-
};
|
1204
|
-
function historyReplaceFn(originalHistoryFn) {
|
1205
|
-
return function () {
|
1206
|
-
var args = [];
|
1207
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
1208
|
-
args[_i] = arguments[_i];
|
1209
|
-
}
|
1210
|
-
var currentPath = args[2];
|
1211
|
-
originalHistoryFn.apply(this, args);
|
1212
|
-
var currentHref = window.location.href;
|
1213
|
-
handleRouterChange(currentPath, currentHref);
|
1214
|
-
};
|
1215
|
-
}
|
1216
|
-
replaceOld(window.history, 'pushState', historyReplaceFn);
|
1217
|
-
replaceOld(window.history, 'replaceState', historyReplaceFn);
|
1218
|
-
};
|
1219
|
-
HistoryPlugin.prototype.transform = function (data) {
|
1220
|
-
this.context.autoTrack(data);
|
1221
|
-
return undefined;
|
1222
|
-
};
|
1223
|
-
return HistoryPlugin;
|
1224
|
-
}(PluginBase));
|
1225
|
-
|
1226
|
-
var HashPlugin = /** @class */ (function (_super) {
|
1227
|
-
__extends(HashPlugin, _super);
|
1228
|
-
function HashPlugin(options, context) {
|
1229
|
-
var _this = _super.call(this, options, context) || this;
|
1230
|
-
_this.options = options;
|
1231
|
-
_this.context = context;
|
1232
|
-
_this.name = 'HashPlugin';
|
1233
|
-
/**
|
1234
|
-
* 上一次页面url
|
1235
|
-
*/
|
1236
|
-
_this.lastHref = window.location.href;
|
1237
|
-
/**
|
1238
|
-
* 上一次路由path
|
1239
|
-
*/
|
1240
|
-
_this.lastPath = window.location.hash;
|
1241
|
-
return _this;
|
1242
|
-
}
|
1243
|
-
HashPlugin.prototype.init = function (notify) {
|
1244
|
-
var _this = this;
|
1245
|
-
var _a = this.options, isSinglePage = _a.isSinglePage, pageviewAutoTrack = _a.autoTrackConfig.pageviewAutoTrack;
|
1246
|
-
window.addEventListener('hashchange', function (event) {
|
1247
|
-
var newURL = event.newURL;
|
1248
|
-
var currentPath = getURL(newURL).hash;
|
1249
|
-
var params = {
|
1250
|
-
fromPath: _this.lastPath,
|
1251
|
-
fromHref: _this.lastHref,
|
1252
|
-
toPath: currentPath,
|
1253
|
-
toHref: newURL
|
1254
|
-
};
|
1255
|
-
mitt.emit('urlChange', __assign(__assign({}, params), { mode: 'history' }));
|
1256
|
-
_this.lastHref = newURL;
|
1257
|
-
_this.lastPath = currentPath;
|
1258
|
-
if (isSinglePage || pageviewAutoTrack === 'singlePage') {
|
1259
|
-
if (isFunction(isSinglePage)) {
|
1260
|
-
var extra = isSinglePage();
|
1261
|
-
if (isObject(extra)) {
|
1262
|
-
params = __assign(__assign({}, params), extra);
|
1263
|
-
}
|
1264
|
-
}
|
1265
|
-
notify(__assign(__assign({}, params), { H_referrer: _this.lastHref }));
|
1266
|
-
}
|
1267
|
-
});
|
1268
|
-
};
|
1269
|
-
HashPlugin.prototype.transform = function (data) {
|
1270
|
-
this.context.autoTrack(data);
|
1271
|
-
return undefined;
|
1272
|
-
};
|
1273
|
-
return HashPlugin;
|
1274
|
-
}(PluginBase));
|
1275
|
-
|
1276
|
-
var HinaTrack = /** @class */ (function (_super) {
|
1277
|
-
__extends(HinaTrack, _super);
|
1278
|
-
function HinaTrack(options, useInstancing) {
|
1279
|
-
if (useInstancing === void 0) { useInstancing = true; }
|
1280
|
-
var _this = _super.call(this, options, useInstancing) || this;
|
1281
|
-
/**
|
1282
|
-
* 上报数据的dom元素 默认有 'a', 'input', 'button', 'textarea'
|
1283
|
-
*/
|
1284
|
-
_this.trackTags = defaultTags;
|
1285
|
-
/**
|
1286
|
-
* 事件静态公共属性
|
1287
|
-
*/
|
1288
|
-
_this.presetProps = {};
|
1289
|
-
/**
|
1290
|
-
* 插件列表
|
1291
|
-
*/
|
1292
|
-
_this.plugins = [];
|
1293
|
-
_this.consolePrefix = '埋点SDK';
|
1294
|
-
// 使用new的方式初始化SDK,需要默认调用init方法进行初始化
|
1295
|
-
if (_this.useInstancing) {
|
1296
|
-
_this.init(options);
|
1297
|
-
}
|
1298
|
-
return _this;
|
1299
|
-
}
|
1300
|
-
/**
|
1301
|
-
* 注册/初始化SDK
|
1302
|
-
* @param options
|
1303
|
-
*/
|
1304
|
-
HinaTrack.prototype.init = function (options) {
|
1305
|
-
if (this.isReady) {
|
1306
|
-
this.log('hinaSDK has been initialized', ConsoleTypes.ERROR);
|
1307
|
-
return;
|
1308
|
-
}
|
1309
|
-
// 默认配置项
|
1310
|
-
var default_config = GET_DEFAULT_OPTIONS();
|
1311
|
-
// 将用户配置项和默认配置项合并
|
1312
|
-
this.options = merge(default_config, options);
|
1313
|
-
// 处理配置信息
|
1314
|
-
this.normalizeConfig();
|
1315
|
-
// 初始化state
|
1316
|
-
this.initState();
|
1317
|
-
// 处理广告参数
|
1318
|
-
this.initAdvProps();
|
1319
|
-
// 插件初始化
|
1320
|
-
this.initPlugins();
|
1321
|
-
// SDK初始化成功,一切准备就绪
|
1322
|
-
this.isReady = true;
|
1323
|
-
this.log('hinaSDK initialized successfully');
|
1324
|
-
};
|
1325
|
-
/**
|
1326
|
-
* 处理配置信息
|
1327
|
-
*/
|
1328
|
-
HinaTrack.prototype.normalizeConfig = function () {
|
1329
|
-
var _a = this.options, serverUrl = _a.serverUrl, sendType = _a.sendType, batchSend = _a.batchSend, _b = _a.autoTrackConfig, _c = _b === void 0 ? {} : _b, _d = _c.trackAttr, trackAttr = _d === void 0 ? [] : _d, collectTags = _c.collectTags, pageLeaveAutoTrack = _c.pageLeaveAutoTrack, pageviewAutoTrack = _c.pageviewAutoTrack;
|
1330
|
-
serverUrl = serverUrl || '';
|
1331
|
-
serverUrl = serverUrl.trim();
|
1332
|
-
if (serverUrl === '') {
|
1333
|
-
this.log('当前 serverUrl 为空或不正确,network 中不会发数据,请配置正确的 serverUrl!', ConsoleTypes.WARN);
|
1334
|
-
}
|
1335
|
-
else {
|
1336
|
-
var href = window.location.href;
|
1337
|
-
var currentProtocol = getURL(href).protocol || '';
|
1338
|
-
var serverProtocol = getURL(serverUrl).protocol || '';
|
1339
|
-
if (serverProtocol !== currentProtocol) {
|
1340
|
-
this.log('SDK 检测到您的数据发送地址和当前页面地址的协议不一致,建议您修改成一致的协议。因为:https 下面发送 http 的图片请求会失败。', ConsoleTypes.WARN);
|
1341
|
-
}
|
1342
|
-
}
|
1343
|
-
if (![ReportType.IMAGE, ReportType.AJAX, ReportType.BEACON].includes(sendType)) {
|
1344
|
-
this.setConfig({
|
1345
|
-
sendType: ReportType.IMAGE
|
1346
|
-
});
|
1347
|
-
}
|
1348
|
-
// 处理pageLeaveAutoTrack
|
1349
|
-
if (pageLeaveAutoTrack === true) {
|
1350
|
-
this.options.autoTrackConfig.pageLeaveAutoTrack = {
|
1351
|
-
heartbeat_interval_time: 5000,
|
1352
|
-
max_duration: 432000
|
1353
|
-
};
|
1354
|
-
}
|
1355
|
-
// 处理trackAttr
|
1356
|
-
if (isArray(trackAttr)) {
|
1357
|
-
trackAttr = trackAttr.filter(function (v) { return isString(v); });
|
1358
|
-
if (!trackAttr.includes('hn-click'))
|
1359
|
-
trackAttr.push('hn-click');
|
1360
|
-
}
|
1361
|
-
else {
|
1362
|
-
trackAttr = ['hn-click'];
|
1363
|
-
}
|
1364
|
-
this.options.autoTrackConfig.trackAttr = trackAttr;
|
1365
|
-
// 处理collectTags
|
1366
|
-
if (isObject(collectTags)) {
|
1367
|
-
if (collectTags.div === true) {
|
1368
|
-
this.options.autoTrackConfig.collectTags.div = {
|
1369
|
-
ignoreTags: ignoreTags,
|
1370
|
-
maxLevel: 1
|
1371
|
-
};
|
1372
|
-
}
|
1373
|
-
else if (isObject(collectTags.div)) {
|
1374
|
-
var maxLevel = 1;
|
1375
|
-
var oDiv = collectTags.div;
|
1376
|
-
if (isNumber(oDiv.maxLevel) && [1, 2, 3].includes(oDiv.maxLevel)) {
|
1377
|
-
maxLevel = oDiv.maxLevel;
|
1378
|
-
}
|
1379
|
-
this.options.autoTrackConfig.collectTags.div = {
|
1380
|
-
ignoreTags: ignoreTags,
|
1381
|
-
maxLevel: maxLevel
|
1382
|
-
};
|
1383
|
-
}
|
1384
|
-
else {
|
1385
|
-
this.options.autoTrackConfig.collectTags.div = false;
|
1386
|
-
}
|
1387
|
-
}
|
1388
|
-
else {
|
1389
|
-
this.options.autoTrackConfig.collectTags = {
|
1390
|
-
div: false
|
1391
|
-
};
|
1392
|
-
}
|
1393
|
-
this.updateTrackTags();
|
1394
|
-
// 处理批量发送
|
1395
|
-
if (batchSend === true || isObject(batchSend)) {
|
1396
|
-
this.options.batchSend = __assign({ dataSendTimeout: 6000, sendInterval: 6000, storageLimit: 200 }, batchSend);
|
1397
|
-
this.batchSender = new BatchSend(this);
|
1398
|
-
}
|
1399
|
-
// 处理pageviewAutoTrack
|
1400
|
-
if (pageviewAutoTrack === 'auto') {
|
1401
|
-
this.autoTrack();
|
1402
|
-
}
|
1403
|
-
};
|
1404
|
-
/**
|
1405
|
-
* 初始化广告参数
|
1406
|
-
*/
|
1407
|
-
HinaTrack.prototype.initAdvProps = function () {
|
1408
|
-
var advProps = {};
|
1409
|
-
var presetProperties = this.options.presetProperties || {};
|
1410
|
-
Object.keys(presetProperties).forEach(function (key) {
|
1411
|
-
var value = presetProperties[key];
|
1412
|
-
if (key.includes('latest_')) {
|
1413
|
-
key = key.slice(7);
|
1414
|
-
if (value) {
|
1415
|
-
var url_domain = getCurrentDomain();
|
1416
|
-
if (key !== 'utm' && url_domain === 'url解析失败') {
|
1417
|
-
advProps["H_latest_".concat(key)] = 'url的domain解析失败';
|
1418
|
-
}
|
1419
|
-
else if (isReferralTraffic()) {
|
1420
|
-
switch (key) {
|
1421
|
-
case 'traffic_source_type':
|
1422
|
-
advProps.H_latest_traffic_source_type =
|
1423
|
-
SearchKeyword.getSourceFromReferrer();
|
1424
|
-
break;
|
1425
|
-
case 'search_keyword':
|
1426
|
-
var searchKeyword = SearchKeyword.getKeywordFromReferrer();
|
1427
|
-
if (searchKeyword) {
|
1428
|
-
advProps.H_latest_search_keyword = searchKeyword;
|
1429
|
-
}
|
1430
|
-
break;
|
1431
|
-
case 'referrer': // todo 这块似乎没有什么用
|
1432
|
-
advProps.H_latest_referrer = '';
|
1433
|
-
break;
|
1434
|
-
}
|
1435
|
-
}
|
1436
|
-
}
|
1437
|
-
}
|
1438
|
-
});
|
1439
|
-
this.store.state.props = advProps;
|
1440
|
-
if (presetProperties.latest_utm) {
|
1441
|
-
this.getUmtsParams('H_latest_');
|
1442
|
-
}
|
1443
|
-
this.getUmtsParams('H_');
|
1444
|
-
this.store.setProps(this.store.state.props);
|
1445
|
-
};
|
1446
|
-
/**
|
1447
|
-
* 处理广告参数
|
1448
|
-
* @param prefix
|
1449
|
-
*/
|
1450
|
-
HinaTrack.prototype.getUmtsParams = function (prefix) {
|
1451
|
-
if (prefix === void 0) { prefix = ''; }
|
1452
|
-
var allUtms = getUmtsParams(prefix);
|
1453
|
-
if (this.store.state.props && this.store.state.props.H_latest_utm_source) {
|
1454
|
-
this.store.state.props = __assign(__assign({}, this.store.state.props), allUtms);
|
1455
|
-
}
|
1456
|
-
return allUtms;
|
1457
|
-
};
|
1458
|
-
/**
|
1459
|
-
* 初始化共享数据
|
1460
|
-
*/
|
1461
|
-
HinaTrack.prototype.initState = function () {
|
1462
|
-
this.store = new State(this.options);
|
1463
|
-
this.store.init();
|
1464
|
-
};
|
1465
|
-
/**
|
1466
|
-
* 更新采集的dom元素
|
1467
|
-
*/
|
1468
|
-
HinaTrack.prototype.updateTrackTags = function () {
|
1469
|
-
var collectTags = this.options.autoTrackConfig.collectTags;
|
1470
|
-
var tags = __spreadArray([], __read(defaultTags), false);
|
1471
|
-
Object.keys(collectTags || {}).forEach(function (key) {
|
1472
|
-
var value = collectTags[key];
|
1473
|
-
if ((value === true || isObject(value)) && !tags.includes(key)) {
|
1474
|
-
tags.push(key);
|
1475
|
-
}
|
1476
|
-
});
|
1477
|
-
this.trackTags = tags;
|
1478
|
-
};
|
1479
|
-
/**
|
1480
|
-
* 应用插件
|
1481
|
-
*/
|
1482
|
-
HinaTrack.prototype.initPlugins = function () {
|
1483
|
-
var _this = this;
|
1484
|
-
var _a = this.options.plugins, plugins = _a === void 0 ? [] : _a;
|
1485
|
-
plugins = plugins || [];
|
1486
|
-
var clickCrackPlugin = new ClickTrackPlugin(this.options, this);
|
1487
|
-
var stayTrackPlugin = new StayTrackPlugin(this.options, this);
|
1488
|
-
var pageLeavePlugin = new PageLeavePlugin(this.options, this);
|
1489
|
-
var siteLinkerPlugin = new SiteLinkerPlugin(this.options, this);
|
1490
|
-
var historyPlugin = new HistoryPlugin(this.options, this);
|
1491
|
-
var hashPlugin = new HashPlugin(this.options, this);
|
1492
|
-
this.plugins = [
|
1493
|
-
clickCrackPlugin,
|
1494
|
-
stayTrackPlugin,
|
1495
|
-
pageLeavePlugin,
|
1496
|
-
siteLinkerPlugin,
|
1497
|
-
historyPlugin,
|
1498
|
-
hashPlugin
|
1499
|
-
];
|
1500
|
-
plugins.forEach(function (Plugin) {
|
1501
|
-
var instance = new Plugin(_this.options, _this);
|
1502
|
-
_this.plugins.push(instance);
|
1503
|
-
});
|
1504
|
-
this.runPlugins(this.plugins);
|
1505
|
-
};
|
1506
|
-
/**
|
1507
|
-
* @deprecated
|
1508
|
-
* 启动内置插件,v4版本后不建议使用该方法启动插件
|
1509
|
-
* 建议通过配置项的方式启动内置插件
|
1510
|
-
*/
|
1511
|
-
HinaTrack.prototype.use = function (pluginName, options) {
|
1512
|
-
var _this = this;
|
1513
|
-
var _a = this.options, autoTrackConfig = _a.autoTrackConfig, siteLinkerConfig = _a.siteLinkerConfig;
|
1514
|
-
var pageLeaveAutoTrack = autoTrackConfig.pageLeaveAutoTrack;
|
1515
|
-
var startPlugin = function (pluginName) {
|
1516
|
-
var pluginInstance = _this.plugins.find(function (plugin) { return plugin.name === pluginName; });
|
1517
|
-
if (pluginInstance)
|
1518
|
-
pluginInstance.init();
|
1519
|
-
};
|
1520
|
-
if (!isObject(options)) {
|
1521
|
-
this.log("".concat(pluginName, "\u63D2\u4EF6\u914D\u7F6E\u9879\u5FC5\u987B\u662F\u4E00\u4E2A\u5BF9\u8C61\u7C7B\u578B"), ConsoleTypes.WARN);
|
1522
|
-
return;
|
1523
|
-
}
|
1524
|
-
if (pluginName === 'PageLeave') {
|
1525
|
-
if (isObject(pageLeaveAutoTrack)) {
|
1526
|
-
this.log('PageLeave插件已通过pageLeaveAutoTrack的配置参数启动,不可重复启动,如果想通过use方式启动,请删除配置项中的pageLeaveAutoTrack', ConsoleTypes.WARN);
|
1527
|
-
}
|
1528
|
-
else {
|
1529
|
-
this.options.autoTrackConfig.pageLeaveAutoTrack =
|
1530
|
-
options;
|
1531
|
-
startPlugin(PageLeavePluginName);
|
1532
|
-
}
|
1533
|
-
}
|
1534
|
-
else if (pluginName === 'SiteLinker') {
|
1535
|
-
if (isObject(siteLinkerConfig)) {
|
1536
|
-
this.log('SiteLinker插件已通过siteLinkerConfig的配置参数启动,不可重复启动,如果想通过use方式启动,请删除配置项中的siteLinkerConfig', ConsoleTypes.WARN);
|
1537
|
-
}
|
1538
|
-
else {
|
1539
|
-
this.options.siteLinkerConfig = options;
|
1540
|
-
startPlugin(SiteLinkerPluginName);
|
1541
|
-
}
|
1542
|
-
}
|
1543
|
-
};
|
1544
|
-
/**
|
1545
|
-
* 设置配置选项
|
1546
|
-
* @param options 配置对象
|
1547
|
-
*/
|
1548
|
-
HinaTrack.prototype.setConfig = function (options) {
|
1549
|
-
this.options = merge(this.options, options);
|
1550
|
-
this.normalizeConfig();
|
1551
|
-
};
|
1552
|
-
/**
|
1553
|
-
* 获取配置选项 参数为空时 返回整个配置对象
|
1554
|
-
* @param key
|
1555
|
-
*/
|
1556
|
-
HinaTrack.prototype.getConfig = function (key) {
|
1557
|
-
if (!key) {
|
1558
|
-
return this.options;
|
1559
|
-
}
|
1560
|
-
return this.options[key];
|
1561
|
-
};
|
1562
|
-
/**
|
1563
|
-
* 上报数据
|
1564
|
-
* @param data
|
1565
|
-
* @param callback
|
1566
|
-
* @param type
|
1567
|
-
*/
|
1568
|
-
HinaTrack.prototype.report = function (data, callback, type) {
|
1569
|
-
console.log('report', data);
|
1570
|
-
var _a = this.options, batchSend = _a.batchSend, globalCallback = _a.globalCallback, serverUrl = _a.serverUrl, dataSendTimeout = _a.dataSendTimeout, sendType = _a.sendType, imgUseCrossOrigin = _a.imgUseCrossOrigin;
|
1571
|
-
sendType = type || sendType;
|
1572
|
-
// 批量发送
|
1573
|
-
if (batchSend) {
|
1574
|
-
this.batchSender.add(data);
|
1575
|
-
}
|
1576
|
-
else {
|
1577
|
-
var dataStr_1 = data;
|
1578
|
-
if (!isString(data)) {
|
1579
|
-
dataStr_1 = JSON.stringify(data);
|
1580
|
-
}
|
1581
|
-
var base64Data = base64Encode(dataStr_1);
|
1582
|
-
var params = {
|
1583
|
-
data: "data=".concat(base64Data),
|
1584
|
-
url: serverUrl,
|
1585
|
-
timeout: dataSendTimeout,
|
1586
|
-
imgUseCrossOrigin: imgUseCrossOrigin
|
1587
|
-
};
|
1588
|
-
var request = void 0;
|
1589
|
-
if (sendType === ReportType.BEACON && navigator.sendBeacon) {
|
1590
|
-
request = new BeaconRequest(params);
|
1591
|
-
}
|
1592
|
-
else if (sendType === ReportType.IMAGE && params.data.length < 2048) {
|
1593
|
-
request = new ImageRequest(params);
|
1594
|
-
}
|
1595
|
-
else {
|
1596
|
-
request = new AjaxRequest(params);
|
1597
|
-
}
|
1598
|
-
return request.run().then(function (res) {
|
1599
|
-
if (isFunction(globalCallback)) {
|
1600
|
-
globalCallback(serverUrl, dataStr_1, res.type, res.msg);
|
1601
|
-
}
|
1602
|
-
if (isFunction(callback)) {
|
1603
|
-
callback(serverUrl, dataStr_1, res.type, res.msg);
|
1604
|
-
}
|
1605
|
-
return res;
|
1606
|
-
});
|
1607
|
-
}
|
1608
|
-
};
|
1609
|
-
/**
|
1610
|
-
* 设置用户登录的唯一标识
|
1611
|
-
* @param uid
|
1612
|
-
* @param callback
|
1613
|
-
*/
|
1614
|
-
HinaTrack.prototype.setUserUId = function (uid, callback) {
|
1615
|
-
uid = uid !== null && uid !== void 0 ? uid : '';
|
1616
|
-
if (isNumber(uid) || isString(uid)) {
|
1617
|
-
uid = String(uid).trim();
|
1618
|
-
if (!uid) {
|
1619
|
-
this.log('setUserUId: uid is empty', ConsoleTypes.WARN);
|
1620
|
-
}
|
1621
|
-
var accountId = this.store.getAccountId();
|
1622
|
-
if (accountId !== uid) {
|
1623
|
-
this.store.setAccountId(uid);
|
1624
|
-
var props = this.getReportData('track_signup', 'H_SignUp', {});
|
1625
|
-
this.report(props, callback);
|
1626
|
-
}
|
1627
|
-
else {
|
1628
|
-
this.log('setUserUId: uid is equal to account_id, , failed to execute setUserUId', ConsoleTypes.WARN);
|
1629
|
-
}
|
1630
|
-
}
|
1631
|
-
else {
|
1632
|
-
this.log('setUserUId: uid must be string or number', ConsoleTypes.WARN);
|
1633
|
-
}
|
1634
|
-
};
|
1635
|
-
/**
|
1636
|
-
* 设置设备ID
|
1637
|
-
* @param uid
|
1638
|
-
*/
|
1639
|
-
HinaTrack.prototype.setDeviceUId = function (uid) {
|
1640
|
-
this.store.setDeviceId(uid);
|
1641
|
-
};
|
1642
|
-
/**
|
1643
|
-
* 获取设备ID
|
1644
|
-
*/
|
1645
|
-
HinaTrack.prototype.getDeviceUId = function () {
|
1646
|
-
return this.store.getDeviceId();
|
1647
|
-
};
|
1648
|
-
/**
|
1649
|
-
* 自定义埋点事件
|
1650
|
-
* @param event
|
1651
|
-
* @param properties
|
1652
|
-
* @param callback
|
1653
|
-
*/
|
1654
|
-
HinaTrack.prototype.track = function (event, properties, callback) {
|
1655
|
-
callback = callback || (function () { });
|
1656
|
-
if (isString(event)) {
|
1657
|
-
properties = isObject(properties) ? properties : {};
|
1658
|
-
var props = this.getReportData('track', event, properties);
|
1659
|
-
this.report(props, callback);
|
1660
|
-
}
|
1661
|
-
else {
|
1662
|
-
this.log('eventName must be a sting and properties must be an object', ConsoleTypes.WARN);
|
1663
|
-
}
|
1664
|
-
};
|
1665
|
-
/**
|
1666
|
-
* @param name
|
1667
|
-
* @param data
|
1668
|
-
* @param callback
|
1669
|
-
*/
|
1670
|
-
HinaTrack.prototype.quick = function (name, data, callback) {
|
1671
|
-
var params = {};
|
1672
|
-
callback = callback || (function () { });
|
1673
|
-
if (isObject(data)) {
|
1674
|
-
params = data;
|
1675
|
-
}
|
1676
|
-
else if (isFunction(data)) {
|
1677
|
-
callback = data;
|
1678
|
-
}
|
1679
|
-
this.autoTrack(params, callback);
|
1680
|
-
};
|
1681
|
-
/**
|
1682
|
-
* 开启页面浏览采集
|
1683
|
-
* @param data
|
1684
|
-
* @param callback
|
1685
|
-
*/
|
1686
|
-
HinaTrack.prototype.autoTrack = function (data, callback) {
|
1687
|
-
if (data === void 0) { data = {}; }
|
1688
|
-
if (callback === void 0) { callback = noop; }
|
1689
|
-
var props = this.getReportData('track', 'H_pageview', data);
|
1690
|
-
this.report(props, callback);
|
1691
|
-
if (this.store.isSetFirstVisit) {
|
1692
|
-
this.store.isSetFirstVisit = false;
|
1693
|
-
var referrer = getReferrer();
|
1694
|
-
this.userSetOnce({
|
1695
|
-
H_first_visit_time: nowStamp(),
|
1696
|
-
H_first_referrer: referrer,
|
1697
|
-
H_first_host: referrer ? getHostname(referrer, '取值异常') : '',
|
1698
|
-
H_first_browser_language: isString(navigator.language)
|
1699
|
-
? navigator.language.toLowerCase()
|
1700
|
-
: '取值异常',
|
1701
|
-
H_first_traffic_source_type: SearchKeyword.getSourceFromReferrer(),
|
1702
|
-
H_first_search_keyword: SearchKeyword.getKeywordFromReferrer()
|
1703
|
-
});
|
1704
|
-
}
|
1705
|
-
};
|
1706
|
-
/**
|
1707
|
-
* 添加用户属性
|
1708
|
-
* 直接设置用户的属性,如果存在则覆盖。
|
1709
|
-
* @param data
|
1710
|
-
* @param callback
|
1711
|
-
*/
|
1712
|
-
HinaTrack.prototype.userSet = function (data, callback) {
|
1713
|
-
if (isObject(data) && !isEmptyObject(data)) {
|
1714
|
-
var props = this.getReportData('user_set', '', data);
|
1715
|
-
this.report(props, callback);
|
1716
|
-
}
|
1717
|
-
};
|
1718
|
-
/**
|
1719
|
-
* 添加用户属性
|
1720
|
-
* 如果不存在则设置,存在就不设置
|
1721
|
-
* @param data
|
1722
|
-
* @param callback
|
1723
|
-
*/
|
1724
|
-
HinaTrack.prototype.userSetOnce = function (data, callback) {
|
1725
|
-
if (isObject(data) && !isEmptyObject(data)) {
|
1726
|
-
var props = this.getReportData('user_setOnce', '', data);
|
1727
|
-
this.report(props, callback);
|
1728
|
-
}
|
1729
|
-
};
|
1730
|
-
/**
|
1731
|
-
* 对当前用户的属性做递增或者递减
|
1732
|
-
* @param data
|
1733
|
-
* @param callback
|
1734
|
-
*/
|
1735
|
-
HinaTrack.prototype.userAdd = function (data, callback) {
|
1736
|
-
var _a;
|
1737
|
-
var _this = this;
|
1738
|
-
if (isString(data)) {
|
1739
|
-
data = (_a = {},
|
1740
|
-
_a[data] = 1,
|
1741
|
-
_a);
|
1742
|
-
}
|
1743
|
-
var isValid = function (params) {
|
1744
|
-
for (var key in params) {
|
1745
|
-
if (!/-*\d+/.test(String(params[key]))) {
|
1746
|
-
_this.log('userAdd: value is must be number', ConsoleTypes.WARN);
|
1747
|
-
return false;
|
1748
|
-
}
|
1749
|
-
}
|
1750
|
-
return true;
|
1751
|
-
};
|
1752
|
-
if (isObject(data) && !isEmptyObject(data) && isValid(data)) {
|
1753
|
-
var props = this.getReportData('user_add', '', data);
|
1754
|
-
this.report(props, callback);
|
1755
|
-
}
|
1756
|
-
};
|
1757
|
-
/**
|
1758
|
-
* 删除当前用户的一些属性
|
1759
|
-
* @param data
|
1760
|
-
* @param callback
|
1761
|
-
*/
|
1762
|
-
HinaTrack.prototype.userUnset = function (data, callback) {
|
1763
|
-
var _this = this;
|
1764
|
-
var obj = {};
|
1765
|
-
if (isString(data)) {
|
1766
|
-
data = [data];
|
1767
|
-
}
|
1768
|
-
if (isArray(data)) {
|
1769
|
-
data.forEach(function (value) {
|
1770
|
-
if (isString(value)) {
|
1771
|
-
obj[value] = true;
|
1772
|
-
}
|
1773
|
-
else {
|
1774
|
-
_this.log("userUnset: value inside the array must be string and have already been filtered out:".concat(value), ConsoleTypes.WARN);
|
1775
|
-
}
|
1776
|
-
});
|
1777
|
-
if (!isEmptyObject(obj)) {
|
1778
|
-
var props = this.getReportData('user_unset', '', obj);
|
1779
|
-
this.report(props, callback);
|
1780
|
-
}
|
1781
|
-
}
|
1782
|
-
else {
|
1783
|
-
this.log('userUnset: param must be an array or string', ConsoleTypes.WARN);
|
1784
|
-
}
|
1785
|
-
};
|
1786
|
-
/**
|
1787
|
-
* 删除当前用户及他的所有属性。
|
1788
|
-
* @param callback
|
1789
|
-
*/
|
1790
|
-
HinaTrack.prototype.userDelete = function (callback) {
|
1791
|
-
var props = this.getReportData('user_delete', '', {});
|
1792
|
-
this.report(props, callback);
|
1793
|
-
this.store.setAccountId('');
|
1794
|
-
};
|
1795
|
-
/**
|
1796
|
-
* 添加事件属性
|
1797
|
-
* 当使用函数类型作为属性值、函数返回值只能是string、bool、number、date、array类型
|
1798
|
-
* @param params
|
1799
|
-
*/
|
1800
|
-
HinaTrack.prototype.registerCommonProperties = function (params) {
|
1801
|
-
this.presetProps = merge(this.presetProps, params);
|
1802
|
-
};
|
1803
|
-
/**
|
1804
|
-
* 获取预置属性
|
1805
|
-
* 此方法可获取,页面地址,页面标题,前向地址,SDK 类型及版本,屏幕宽高,最近一次的相关属性
|
1806
|
-
*/
|
1807
|
-
HinaTrack.prototype.getPresetProperties = function () {
|
1808
|
-
return {
|
1809
|
-
H_is_first_day: this.store.isFirstDay,
|
1810
|
-
H_is_first_time: this.store.isFirstTime,
|
1811
|
-
device_id: this.store.getDeviceId(),
|
1812
|
-
anonymous_id: this.store.getAnonymousId(),
|
1813
|
-
account_id: this.store.getAccountId(),
|
1814
|
-
properties: __assign(__assign(__assign({}, this.presetProps), getPageProperties()), getBrowserInfo())
|
1815
|
-
};
|
1816
|
-
};
|
1817
|
-
/**
|
1818
|
-
* 清空预置属性
|
1819
|
-
* @param payload
|
1820
|
-
*/
|
1821
|
-
HinaTrack.prototype.clearPageRegister = function (payload) {
|
1822
|
-
var _this = this;
|
1823
|
-
if (payload === void 0) { payload = true; }
|
1824
|
-
if (payload === true) {
|
1825
|
-
this.presetProps = {};
|
1826
|
-
}
|
1827
|
-
else if (isArray(payload)) {
|
1828
|
-
payload.forEach(function (key) {
|
1829
|
-
if (key in _this.presetProps)
|
1830
|
-
delete _this.presetProps[key];
|
1831
|
-
});
|
1832
|
-
}
|
1833
|
-
};
|
1834
|
-
/**
|
1835
|
-
* 检查发送数据
|
1836
|
-
* @param props
|
1837
|
-
*/
|
1838
|
-
HinaTrack.prototype.checkReportProperties = function (props) {
|
1839
|
-
var _this = this;
|
1840
|
-
Object.keys(props).forEach(function (key) {
|
1841
|
-
var value = props[key];
|
1842
|
-
if (isString(value) && value.length > MAX_STRING_LENGTH) {
|
1843
|
-
_this.log("\u5C5E\u6027--".concat(key, " \u5185\u5BB9\u8FC7\u957F\uFF0C\u5DF2\u88AB\u5220\u9664"), ConsoleTypes.WARN);
|
1844
|
-
delete props[key];
|
1845
|
-
}
|
1846
|
-
else if (isObject(value)) {
|
1847
|
-
_this.checkReportProperties(value);
|
1848
|
-
}
|
1849
|
-
else if (isFunction(value)) {
|
1850
|
-
props[key] = value(props);
|
1851
|
-
if (isObject(props[key])) {
|
1852
|
-
_this.checkReportProperties(props[key]);
|
1853
|
-
}
|
1854
|
-
else if (isString(props[key]) &&
|
1855
|
-
props[key].length > MAX_STRING_LENGTH) {
|
1856
|
-
_this.log("\u5C5E\u6027--".concat(key, " \u5185\u5BB9\u8FC7\u957F\uFF0C\u5DF2\u88AB\u5220\u9664"), ConsoleTypes.WARN);
|
1857
|
-
delete props[key];
|
1858
|
-
}
|
1859
|
-
}
|
1860
|
-
});
|
1861
|
-
};
|
1862
|
-
/**
|
1863
|
-
* 获取上报数据
|
1864
|
-
* @param type
|
1865
|
-
* @param event
|
1866
|
-
* @param data
|
1867
|
-
*/
|
1868
|
-
HinaTrack.prototype.getReportData = function (type, event, data) {
|
1869
|
-
var anonymous_id = this.store.getAnonymousId();
|
1870
|
-
var accountId = this.store.getAccountId();
|
1871
|
-
var time = nowStamp();
|
1872
|
-
var reportProperties = this.getReportProperties(type, event);
|
1873
|
-
var properties = __assign(__assign({}, reportProperties), (data || {}));
|
1874
|
-
this.checkReportProperties(properties);
|
1875
|
-
var props = {
|
1876
|
-
anonymous_id: anonymous_id,
|
1877
|
-
type: type,
|
1878
|
-
event: event,
|
1879
|
-
time: time,
|
1880
|
-
_track_id: Number(String(getRandom()).slice(2, 5) +
|
1881
|
-
String(getRandom()).slice(2, 4) +
|
1882
|
-
String(nowStamp()).slice(-4)),
|
1883
|
-
properties: properties
|
1884
|
-
};
|
1885
|
-
if (accountId) {
|
1886
|
-
props.account_id = accountId;
|
1887
|
-
}
|
1888
|
-
props.send_time = nowStamp();
|
1889
|
-
return props;
|
1890
|
-
};
|
1891
|
-
/**
|
1892
|
-
* 获取通用的上报数据
|
1893
|
-
* @param type 上报类型
|
1894
|
-
* @param event 事件名称
|
1895
|
-
*/
|
1896
|
-
HinaTrack.prototype.getReportProperties = function (type, event) {
|
1897
|
-
if (type === void 0) { type = ''; }
|
1898
|
-
if (event === void 0) { event = ''; }
|
1899
|
-
// 这里对预置属性进行merge是为了防止影响this.presetProps的自身结构,深拷贝的操作
|
1900
|
-
var presetProps = merge(this.presetProps);
|
1901
|
-
var properties = __assign(__assign({ device_id: this.store.getDeviceId() }, this.store.state.props), presetProps);
|
1902
|
-
// user_set、user_setOnce、user_add、user_unset、user_delete
|
1903
|
-
if (!type || type.slice(0, 4) !== 'user') {
|
1904
|
-
properties = __assign(__assign(__assign({}, properties), getPageProperties()), getBrowserInfo());
|
1905
|
-
}
|
1906
|
-
if (type === 'track') {
|
1907
|
-
properties.H_is_first_day = this.store.isFirstDay;
|
1908
|
-
this.store.isFirstDay = false;
|
1909
|
-
if (event === 'H_pageview') {
|
1910
|
-
properties.H_is_first_time = this.store.isFirstTime;
|
1911
|
-
this.store.isFirstTime = false;
|
1912
|
-
}
|
1913
|
-
}
|
1914
|
-
return properties;
|
1915
|
-
};
|
1916
|
-
return HinaTrack;
|
1917
|
-
}(BaseCore));
|
1918
|
-
|
1919
|
-
function createInstance(options) {
|
1920
|
-
return new HinaTrack(options, false);
|
1921
|
-
}
|
1922
|
-
var hinaSdk = createInstance({});
|
1923
|
-
|
1924
|
-
export { HinaTrack, hinaSdk as default };
|
1925
|
-
//# sourceMappingURL=index.esm.js.map
|