@datarangers/sdk-javascript 0.1.4 → 0.1.5
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 -6629
- package/es/index.min.js +1 -9570
- package/es/plugin/ab.js +1 -1114
- package/es/plugin/autotrack.js +1 -1608
- package/es/plugin/duration.js +1 -100
- package/es/plugin/route.js +1 -605
- package/es/plugin/stay.js +1 -476
- package/lib/index-base.min.js +1 -6634
- package/lib/index.min.js +1 -9575
- package/lib/plugin/ab.js +1 -1116
- package/lib/plugin/autotrack.js +1 -1610
- package/lib/plugin/duration.js +1 -102
- package/lib/plugin/route.js +1 -607
- package/lib/plugin/stay.js +1 -478
- package/package.json +1 -1
package/es/plugin/ab.js
CHANGED
|
@@ -1,1114 +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
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
-
var e = new Error(message);
|
|
29
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
33
|
-
var STYLE_ID = '__rangers_ab_style__';
|
|
34
|
-
function openOverlayer() {
|
|
35
|
-
if (document.getElementById(STYLE_ID)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
var css = 'body { opacity: 0 !important; }';
|
|
39
|
-
var head = document.head || document.getElementsByTagName('head')[0];
|
|
40
|
-
var style = document.createElement('style');
|
|
41
|
-
style.id = STYLE_ID;
|
|
42
|
-
style.type = 'text/css';
|
|
43
|
-
if (style.styleSheet) {
|
|
44
|
-
style.styleSheet.cssText = css;
|
|
45
|
-
} else {
|
|
46
|
-
style.appendChild(document.createTextNode(css));
|
|
47
|
-
}
|
|
48
|
-
head.appendChild(style);
|
|
49
|
-
}
|
|
50
|
-
function closeOverlayer() {
|
|
51
|
-
var style = document.getElementById(STYLE_ID);
|
|
52
|
-
if (style) {
|
|
53
|
-
style.parentElement.removeChild(style);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
58
|
-
var AB_DOMAINS = {
|
|
59
|
-
cn: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
|
|
60
|
-
va: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
|
|
61
|
-
sg: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k'
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
65
|
-
var Types;
|
|
66
|
-
(function (Types) {
|
|
67
|
-
Types["Init"] = "init";
|
|
68
|
-
Types["Config"] = "config";
|
|
69
|
-
Types["Start"] = "start";
|
|
70
|
-
Types["Ready"] = "ready";
|
|
71
|
-
Types["TokenComplete"] = "token-complete";
|
|
72
|
-
Types["TokenStorage"] = "token-storage";
|
|
73
|
-
Types["TokenFetch"] = "token-fetch";
|
|
74
|
-
Types["TokenError"] = "token-error";
|
|
75
|
-
Types["ConfigUuid"] = "config-uuid";
|
|
76
|
-
Types["ConfigWebId"] = "config-webid";
|
|
77
|
-
Types["ConfigDomain"] = "config-domain";
|
|
78
|
-
Types["CustomWebId"] = "custom-webid";
|
|
79
|
-
Types["AnonymousId"] = "anonymous-id";
|
|
80
|
-
Types["TokenChange"] = "token-change";
|
|
81
|
-
Types["TokenReset"] = "token-reset";
|
|
82
|
-
Types["ConfigTransform"] = "config-transform";
|
|
83
|
-
Types["EnvTransform"] = "env-transform";
|
|
84
|
-
Types["SessionReset"] = "session-reset";
|
|
85
|
-
Types["SessionResetTime"] = "session-reset-time";
|
|
86
|
-
Types["Event"] = "event";
|
|
87
|
-
Types["Events"] = "events";
|
|
88
|
-
Types["EventNow"] = "event-now";
|
|
89
|
-
Types["CleanEvents"] = "clean-events";
|
|
90
|
-
Types["BeconEvent"] = "becon-event";
|
|
91
|
-
Types["SubmitBefore"] = "submit-before";
|
|
92
|
-
Types["SubmitScuess"] = "submit-scuess";
|
|
93
|
-
Types["SubmitSuccess"] = "submit-success";
|
|
94
|
-
Types["SubmitAfter"] = "submit-after";
|
|
95
|
-
Types["SubmitError"] = "submit-error";
|
|
96
|
-
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
97
|
-
Types["Stay"] = "stay";
|
|
98
|
-
Types["ResetStay"] = "reset-stay";
|
|
99
|
-
Types["StayReady"] = "stay-ready";
|
|
100
|
-
Types["SetStay"] = "set-stay";
|
|
101
|
-
Types["RouteChange"] = "route-change";
|
|
102
|
-
Types["RouteReady"] = "route-ready";
|
|
103
|
-
Types["Ab"] = "ab";
|
|
104
|
-
Types["AbVar"] = "ab-var";
|
|
105
|
-
Types["AbAllVars"] = "ab-all-vars";
|
|
106
|
-
Types["AbConfig"] = "ab-config";
|
|
107
|
-
Types["AbExternalVersion"] = "ab-external-version";
|
|
108
|
-
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
109
|
-
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
110
|
-
Types["AbOpenLayer"] = "ab-open-layer";
|
|
111
|
-
Types["AbCloseLayer"] = "ab-close-layer";
|
|
112
|
-
Types["AbReady"] = "ab-ready";
|
|
113
|
-
Types["AbComplete"] = "ab-complete";
|
|
114
|
-
Types["AbTimeout"] = "ab-timeout";
|
|
115
|
-
Types["Profile"] = "profile";
|
|
116
|
-
Types["ProfileSet"] = "profile-set";
|
|
117
|
-
Types["ProfileSetOnce"] = "profile-set-once";
|
|
118
|
-
Types["ProfileUnset"] = "profile-unset";
|
|
119
|
-
Types["ProfileIncrement"] = "profile-increment";
|
|
120
|
-
Types["ProfileAppend"] = "profile-append";
|
|
121
|
-
Types["ProfileClear"] = "profile-clear";
|
|
122
|
-
Types["TrackDuration"] = "track-duration";
|
|
123
|
-
Types["TrackDurationStart"] = "track-duration-start";
|
|
124
|
-
Types["TrackDurationEnd"] = "track-duration-end";
|
|
125
|
-
Types["TrackDurationPause"] = "track-duration-pause";
|
|
126
|
-
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
127
|
-
Types["Autotrack"] = "autotrack";
|
|
128
|
-
Types["AutotrackReady"] = "autotrack-ready";
|
|
129
|
-
Types["CustomHeader"] = "custom-request-header";
|
|
130
|
-
Types["TracerReady"] = "tracer-ready";
|
|
131
|
-
})(Types || (Types = {}));
|
|
132
|
-
var DebuggerMesssge;
|
|
133
|
-
(function (DebuggerMesssge) {
|
|
134
|
-
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
135
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
136
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
137
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
138
|
-
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
139
|
-
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
140
|
-
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
141
|
-
|
|
142
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
143
|
-
// @ts-nocheck
|
|
144
|
-
// @ts-nocheck
|
|
145
|
-
var isObject = function isObject(obj) {
|
|
146
|
-
return obj != null && Object.prototype.toString.call(obj) == '[object Object]';
|
|
147
|
-
};
|
|
148
|
-
(function () {
|
|
149
|
-
var lastEventId = +Date.now() + Number(("" + Math.random()).slice(2, 8));
|
|
150
|
-
return function () {
|
|
151
|
-
lastEventId += 1;
|
|
152
|
-
return lastEventId;
|
|
153
|
-
};
|
|
154
|
-
})();
|
|
155
|
-
/* eslint-disable no-param-reassign */
|
|
156
|
-
var decrypto = function decrypto(str, xor, hex) {
|
|
157
|
-
if (typeof str !== 'string' || typeof xor !== 'number' || typeof hex !== 'number') {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
var strCharList = [];
|
|
161
|
-
var resultList = [];
|
|
162
|
-
hex = hex <= 25 ? hex : hex % 25;
|
|
163
|
-
var splitStr = String.fromCharCode(hex + 97);
|
|
164
|
-
strCharList = str.split(splitStr);
|
|
165
|
-
for (var i = 0; i < strCharList.length; i++) {
|
|
166
|
-
var charCode = parseInt(strCharList[i], hex);
|
|
167
|
-
charCode = charCode * 1 ^ xor;
|
|
168
|
-
var strChar = String.fromCharCode(charCode);
|
|
169
|
-
resultList.push(strChar);
|
|
170
|
-
}
|
|
171
|
-
var resultStr = resultList.join('');
|
|
172
|
-
return resultStr;
|
|
173
|
-
};
|
|
174
|
-
var decodeUrl = function decodeUrl(string) {
|
|
175
|
-
return decrypto(string, 64, 25);
|
|
176
|
-
};
|
|
177
|
-
var parseURL = function parseURL(url) {
|
|
178
|
-
var a = document.createElement('a');
|
|
179
|
-
a.href = url;
|
|
180
|
-
return a;
|
|
181
|
-
};
|
|
182
|
-
var parseUrlQuery = function parseUrlQuery(url) {
|
|
183
|
-
var queryObj = {};
|
|
184
|
-
try {
|
|
185
|
-
var queryString = parseURL(url).search;
|
|
186
|
-
queryString = queryString.slice(1);
|
|
187
|
-
queryString.split('&').forEach(function (keyValue) {
|
|
188
|
-
var _keyValue = keyValue.split('=');
|
|
189
|
-
var key;
|
|
190
|
-
var value;
|
|
191
|
-
if (_keyValue.length) {
|
|
192
|
-
key = _keyValue[0];
|
|
193
|
-
value = _keyValue[1];
|
|
194
|
-
}
|
|
195
|
-
try {
|
|
196
|
-
queryObj[key] = decodeURIComponent(typeof value === 'undefined' ? '' : value);
|
|
197
|
-
} catch (e) {
|
|
198
|
-
queryObj[key] = value;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
} catch (e) {}
|
|
202
|
-
return queryObj;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
function createCommonjsModule(fn, module) {
|
|
206
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
var cookie = createCommonjsModule(function (module, exports) {
|
|
210
|
-
(function (factory) {
|
|
211
|
-
var registeredInModuleLoader;
|
|
212
|
-
{
|
|
213
|
-
module.exports = factory();
|
|
214
|
-
registeredInModuleLoader = true;
|
|
215
|
-
}
|
|
216
|
-
if (!registeredInModuleLoader) {
|
|
217
|
-
var OldCookies = window.Cookies;
|
|
218
|
-
var api = window.Cookies = factory();
|
|
219
|
-
api.noConflict = function () {
|
|
220
|
-
window.Cookies = OldCookies;
|
|
221
|
-
return api;
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
})(function () {
|
|
225
|
-
function extend() {
|
|
226
|
-
var i = 0;
|
|
227
|
-
var result = {};
|
|
228
|
-
for (; i < arguments.length; i++) {
|
|
229
|
-
var attributes = arguments[i];
|
|
230
|
-
for (var key in attributes) {
|
|
231
|
-
result[key] = attributes[key];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
function decode(s) {
|
|
237
|
-
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
238
|
-
}
|
|
239
|
-
function init(converter) {
|
|
240
|
-
function api() {}
|
|
241
|
-
function set(key, value, attributes) {
|
|
242
|
-
if (typeof document === 'undefined') {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
attributes = extend({
|
|
246
|
-
path: '/'
|
|
247
|
-
}, api.defaults, attributes);
|
|
248
|
-
if (typeof attributes.expires === 'number') {
|
|
249
|
-
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
|
|
250
|
-
}
|
|
251
|
-
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
|
252
|
-
try {
|
|
253
|
-
var result = JSON.stringify(value);
|
|
254
|
-
if (/^[\{\[]/.test(result)) {
|
|
255
|
-
value = result;
|
|
256
|
-
}
|
|
257
|
-
} catch (e) {}
|
|
258
|
-
value = converter.write ? converter.write(value, key) : encodeURIComponent(String(value)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
|
259
|
-
key = encodeURIComponent(String(key)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
|
|
260
|
-
var stringifiedAttributes = '';
|
|
261
|
-
for (var attributeName in attributes) {
|
|
262
|
-
if (!attributes[attributeName]) {
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
stringifiedAttributes += '; ' + attributeName;
|
|
266
|
-
if (attributes[attributeName] === true) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
270
|
-
}
|
|
271
|
-
return document.cookie = key + '=' + value + stringifiedAttributes;
|
|
272
|
-
}
|
|
273
|
-
function get(key, json) {
|
|
274
|
-
if (typeof document === 'undefined') {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
var jar = {};
|
|
278
|
-
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
279
|
-
var i = 0;
|
|
280
|
-
for (; i < cookies.length; i++) {
|
|
281
|
-
var parts = cookies[i].split('=');
|
|
282
|
-
var cookie = parts.slice(1).join('=');
|
|
283
|
-
if (!json && cookie.charAt(0) === '"') {
|
|
284
|
-
cookie = cookie.slice(1, -1);
|
|
285
|
-
}
|
|
286
|
-
try {
|
|
287
|
-
var name = decode(parts[0]);
|
|
288
|
-
cookie = (converter.read || converter)(cookie, name) || decode(cookie);
|
|
289
|
-
if (json) {
|
|
290
|
-
try {
|
|
291
|
-
cookie = JSON.parse(cookie);
|
|
292
|
-
} catch (e) {}
|
|
293
|
-
}
|
|
294
|
-
jar[name] = cookie;
|
|
295
|
-
if (key === name) {
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
} catch (e) {}
|
|
299
|
-
}
|
|
300
|
-
return key ? jar[key] : jar;
|
|
301
|
-
}
|
|
302
|
-
api.set = set;
|
|
303
|
-
api.get = function (key) {
|
|
304
|
-
return get(key, false );
|
|
305
|
-
};
|
|
306
|
-
api.getJSON = function (key) {
|
|
307
|
-
return get(key, true );
|
|
308
|
-
};
|
|
309
|
-
api.remove = function (key, attributes) {
|
|
310
|
-
set(key, '', extend(attributes, {
|
|
311
|
-
expires: -1
|
|
312
|
-
}));
|
|
313
|
-
};
|
|
314
|
-
api.defaults = {};
|
|
315
|
-
api.withConverter = init;
|
|
316
|
-
return api;
|
|
317
|
-
}
|
|
318
|
-
return init(function () {});
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
323
|
-
/**
|
|
324
|
-
* cacheStorage
|
|
325
|
-
*/
|
|
326
|
-
var Memory = /** @class */function () {
|
|
327
|
-
function Memory() {
|
|
328
|
-
this.cache = {};
|
|
329
|
-
}
|
|
330
|
-
Memory.prototype.setItem = function (cacheKey, data) {
|
|
331
|
-
this.cache[cacheKey] = data;
|
|
332
|
-
};
|
|
333
|
-
Memory.prototype.getItem = function (cacheKey) {
|
|
334
|
-
return this.cache[cacheKey];
|
|
335
|
-
};
|
|
336
|
-
Memory.prototype.removeItem = function (cacheKey) {
|
|
337
|
-
this.cache[cacheKey] = undefined;
|
|
338
|
-
};
|
|
339
|
-
return Memory;
|
|
340
|
-
}();
|
|
341
|
-
/**
|
|
342
|
-
* localStorage
|
|
343
|
-
*/
|
|
344
|
-
var Local = /** @class */function () {
|
|
345
|
-
function Local() {
|
|
346
|
-
this.support = this.isSupportLS();
|
|
347
|
-
}
|
|
348
|
-
Local.prototype.isSupportLS = function () {
|
|
349
|
-
try {
|
|
350
|
-
localStorage.setItem('_applogtest-test-key', 'hi');
|
|
351
|
-
localStorage.getItem('_applogtest-test-key');
|
|
352
|
-
localStorage.removeItem('_applogtest-test-key');
|
|
353
|
-
return true;
|
|
354
|
-
} catch (e) {
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
Local.prototype.getItem = function (key) {
|
|
359
|
-
try {
|
|
360
|
-
var value = localStorage.getItem(key);
|
|
361
|
-
var ret = value;
|
|
362
|
-
try {
|
|
363
|
-
if (value && typeof value === 'string') {
|
|
364
|
-
ret = JSON.parse(value);
|
|
365
|
-
}
|
|
366
|
-
} catch (e) {}
|
|
367
|
-
return ret || {};
|
|
368
|
-
} catch (e) {}
|
|
369
|
-
return {};
|
|
370
|
-
};
|
|
371
|
-
Local.prototype.setItem = function (key, value) {
|
|
372
|
-
try {
|
|
373
|
-
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
374
|
-
localStorage.setItem(key, stringValue);
|
|
375
|
-
} catch (e) {}
|
|
376
|
-
};
|
|
377
|
-
Local.prototype.removeItem = function (key) {
|
|
378
|
-
try {
|
|
379
|
-
localStorage.removeItem(key);
|
|
380
|
-
} catch (e) {}
|
|
381
|
-
};
|
|
382
|
-
return Local;
|
|
383
|
-
}();
|
|
384
|
-
/**
|
|
385
|
-
* sessionStorage
|
|
386
|
-
*/
|
|
387
|
-
var Session = /** @class */function () {
|
|
388
|
-
function Session() {
|
|
389
|
-
this.support = this.isSupportSession();
|
|
390
|
-
}
|
|
391
|
-
Session.prototype.isSupportSession = function () {
|
|
392
|
-
try {
|
|
393
|
-
sessionStorage.setItem('_applogtest-test-key', 'hi');
|
|
394
|
-
sessionStorage.getItem('_applogtest-test-key');
|
|
395
|
-
sessionStorage.removeItem('_applogtest-test-key');
|
|
396
|
-
return true;
|
|
397
|
-
} catch (e) {
|
|
398
|
-
return false;
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
Session.prototype.getItem = function (key) {
|
|
402
|
-
try {
|
|
403
|
-
var value = sessionStorage.getItem(key);
|
|
404
|
-
var ret = value;
|
|
405
|
-
try {
|
|
406
|
-
if (value && typeof value === 'string') {
|
|
407
|
-
ret = JSON.parse(value);
|
|
408
|
-
}
|
|
409
|
-
} catch (e) {}
|
|
410
|
-
return ret || {};
|
|
411
|
-
} catch (e) {}
|
|
412
|
-
return {};
|
|
413
|
-
};
|
|
414
|
-
Session.prototype.setItem = function (key, value) {
|
|
415
|
-
try {
|
|
416
|
-
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
417
|
-
sessionStorage.setItem(key, stringValue);
|
|
418
|
-
} catch (e) {}
|
|
419
|
-
};
|
|
420
|
-
Session.prototype.removeItem = function (key) {
|
|
421
|
-
try {
|
|
422
|
-
sessionStorage.removeItem(key);
|
|
423
|
-
} catch (e) {}
|
|
424
|
-
};
|
|
425
|
-
return Session;
|
|
426
|
-
}();
|
|
427
|
-
var StorageManager = /** @class */function () {
|
|
428
|
-
function StorageManager() {
|
|
429
|
-
this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
|
|
430
|
-
this.local = new Local();
|
|
431
|
-
this.session = new Session();
|
|
432
|
-
this.cache = new Memory();
|
|
433
|
-
}
|
|
434
|
-
StorageManager.prototype.getLocalItem = function (key) {
|
|
435
|
-
return this.local.getItem(key);
|
|
436
|
-
};
|
|
437
|
-
StorageManager.prototype.setLocalItem = function (key, value) {
|
|
438
|
-
this.local.setItem(key, value);
|
|
439
|
-
};
|
|
440
|
-
StorageManager.prototype.removeLocalItem = function (key) {
|
|
441
|
-
this.local.removeItem(key);
|
|
442
|
-
};
|
|
443
|
-
StorageManager.prototype.getSessionItem = function (key) {
|
|
444
|
-
return this.session.getItem(key);
|
|
445
|
-
};
|
|
446
|
-
StorageManager.prototype.setSessionItem = function (key, value) {
|
|
447
|
-
this.session.setItem(key, value);
|
|
448
|
-
};
|
|
449
|
-
StorageManager.prototype.removeSessionItem = function (key) {
|
|
450
|
-
this.session.removeItem(key);
|
|
451
|
-
};
|
|
452
|
-
StorageManager.prototype.getCacheItem = function (key) {
|
|
453
|
-
return this.cache.getItem(key);
|
|
454
|
-
};
|
|
455
|
-
StorageManager.prototype.setCacheItem = function (key, value) {
|
|
456
|
-
this.cache.setItem(key, value);
|
|
457
|
-
};
|
|
458
|
-
StorageManager.prototype.removeCacheItem = function (key) {
|
|
459
|
-
this.cache.removeItem(key);
|
|
460
|
-
};
|
|
461
|
-
StorageManager.prototype.getCookie = function (key, domain) {
|
|
462
|
-
try {
|
|
463
|
-
// const _matches = Cookies.get(name, { domain: domain || document.domain })
|
|
464
|
-
var _matches = cookie.get(key);
|
|
465
|
-
return _matches;
|
|
466
|
-
} catch (e) {
|
|
467
|
-
return '';
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
|
|
471
|
-
if (expiresTime === void 0) {
|
|
472
|
-
expiresTime = this.defaultExpireTime;
|
|
473
|
-
}
|
|
474
|
-
try {
|
|
475
|
-
var _domain = domain || document.domain;
|
|
476
|
-
var timestamp = +new Date();
|
|
477
|
-
var furureTimestamp = timestamp + expiresTime;
|
|
478
|
-
cookie.set(key, value, {
|
|
479
|
-
expires: new Date(furureTimestamp),
|
|
480
|
-
path: '/',
|
|
481
|
-
domain: _domain
|
|
482
|
-
});
|
|
483
|
-
} catch (e) {}
|
|
484
|
-
};
|
|
485
|
-
StorageManager.prototype.removeCookie = function (key, domain) {
|
|
486
|
-
try {
|
|
487
|
-
cookie.remove(key, {
|
|
488
|
-
path: '/',
|
|
489
|
-
domain: domain || ''
|
|
490
|
-
});
|
|
491
|
-
} catch (e) {}
|
|
492
|
-
};
|
|
493
|
-
return StorageManager;
|
|
494
|
-
}();
|
|
495
|
-
|
|
496
|
-
var CallbackType;
|
|
497
|
-
(function (CallbackType) {
|
|
498
|
-
CallbackType[CallbackType["Var"] = 0] = "Var";
|
|
499
|
-
CallbackType[CallbackType["All"] = 1] = "All";
|
|
500
|
-
})(CallbackType || (CallbackType = {}));
|
|
501
|
-
var STORAGE_EXPRIRE = 1 * 30 * 24 * 60 * 60 * 1000;
|
|
502
|
-
var API = '/service/2/abtest_config/';
|
|
503
|
-
var Ab = /** @class */function () {
|
|
504
|
-
function Ab() {
|
|
505
|
-
this.fetchStatus = 'no';
|
|
506
|
-
this.refreshFetchStatus = 'complete';
|
|
507
|
-
this.versions = [];
|
|
508
|
-
this.extVersions = [];
|
|
509
|
-
this.mulilinkVersions = [];
|
|
510
|
-
this.enable_multilink = false;
|
|
511
|
-
this.enable_ab_visual = false;
|
|
512
|
-
this.editMode = false;
|
|
513
|
-
this.callbacks = [];
|
|
514
|
-
this.data = null;
|
|
515
|
-
this.changeListener = new Map();
|
|
516
|
-
this.readyStatus = false;
|
|
517
|
-
this.exposureCache = [];
|
|
518
|
-
}
|
|
519
|
-
Ab.prototype.apply = function (collect, config) {
|
|
520
|
-
var _this = this;
|
|
521
|
-
this.collect = collect;
|
|
522
|
-
this.config = config;
|
|
523
|
-
if (!this.config.enable_ab_test) return;
|
|
524
|
-
var enable_multilink = config.enable_multilink,
|
|
525
|
-
ab_channel_domain = config.ab_channel_domain,
|
|
526
|
-
enable_ab_visual = config.enable_ab_visual,
|
|
527
|
-
ab_cross = config.ab_cross,
|
|
528
|
-
ab_cookie_domain = config.ab_cookie_domain,
|
|
529
|
-
disable_ab_reset = config.disable_ab_reset;
|
|
530
|
-
var abDomain = ab_channel_domain || decodeUrl(AB_DOMAINS[config.channel || 'cn']);
|
|
531
|
-
this.cacheStorgae = new StorageManager();
|
|
532
|
-
this.enable_multilink = enable_multilink;
|
|
533
|
-
this.enable_ab_visual = enable_ab_visual;
|
|
534
|
-
this.abKey = "__tea_sdk_ab_version_" + config.app_id;
|
|
535
|
-
this.ab_cross = ab_cross;
|
|
536
|
-
this.ab_cookie_domain = ab_cookie_domain || '';
|
|
537
|
-
this.fetchUrl = "" + abDomain + API;
|
|
538
|
-
this.reportUrl = "" + collect.configManager.getUrl('event');
|
|
539
|
-
this.exposureLimit = config.exposure_limit || 20;
|
|
540
|
-
this.ab_batch_time = config.ab_batch_time || 500;
|
|
541
|
-
var Types = this.collect.Types;
|
|
542
|
-
this.types = Types;
|
|
543
|
-
this.collect.on(Types.TokenChange, function (tokenInfo) {
|
|
544
|
-
if (disable_ab_reset) return;
|
|
545
|
-
if (tokenInfo.type !== 'uuid') return;
|
|
546
|
-
if (!_this.readyStatus) return;
|
|
547
|
-
_this.clearCache();
|
|
548
|
-
_this.fetchAB();
|
|
549
|
-
});
|
|
550
|
-
this.collect.on(Types.TokenReset, function () {
|
|
551
|
-
if (disable_ab_reset) return;
|
|
552
|
-
if (!_this.readyStatus) return;
|
|
553
|
-
_this.clearCache();
|
|
554
|
-
_this.fetchAB();
|
|
555
|
-
});
|
|
556
|
-
this.collect.on(Types.AbVar, function (_a) {
|
|
557
|
-
var name = _a.name,
|
|
558
|
-
defaultValue = _a.defaultValue,
|
|
559
|
-
callback = _a.callback;
|
|
560
|
-
_this.getVar(name, defaultValue, callback);
|
|
561
|
-
});
|
|
562
|
-
this.collect.on(Types.AbAllVars, function (callback) {
|
|
563
|
-
_this.getAllVars(callback);
|
|
564
|
-
});
|
|
565
|
-
this.collect.on(Types.AbConfig, function (_a) {
|
|
566
|
-
var params = _a.params,
|
|
567
|
-
callback = _a.callback;
|
|
568
|
-
_this.getABconfig(params, callback);
|
|
569
|
-
});
|
|
570
|
-
this.collect.on(Types.AbExternalVersion, function (vids) {
|
|
571
|
-
_this.setExternalAbVersion(vids);
|
|
572
|
-
});
|
|
573
|
-
this.collect.on(Types.AbOpenLayer, function () {
|
|
574
|
-
_this.openOverlayer();
|
|
575
|
-
});
|
|
576
|
-
this.collect.on(Types.AbCloseLayer, function () {
|
|
577
|
-
_this.closeOverlayer();
|
|
578
|
-
});
|
|
579
|
-
this.collect.on(Types.AbVersionChangeOn, function (cb) {
|
|
580
|
-
_this.changeListener.set(cb, cb);
|
|
581
|
-
});
|
|
582
|
-
this.collect.on(Types.AbVersionChangeOff, function (cb) {
|
|
583
|
-
if (_this.changeListener.get(cb)) {
|
|
584
|
-
_this.changeListener["delete"](cb);
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
this.loadMode();
|
|
588
|
-
(this.enable_ab_visual || this.enable_multilink) && this.openOverlayer(this.config.multilink_timeout_ms || 500);
|
|
589
|
-
this.checkLocal();
|
|
590
|
-
this.ready('ab');
|
|
591
|
-
if (!this.readyStatus) {
|
|
592
|
-
this.fetchAB();
|
|
593
|
-
this.readyStatus = true;
|
|
594
|
-
}
|
|
595
|
-
this.collect.emit(Types.AbReady);
|
|
596
|
-
};
|
|
597
|
-
Ab.prototype.ready = function (name) {
|
|
598
|
-
var _this = this;
|
|
599
|
-
this.collect.set(name);
|
|
600
|
-
if (this.collect.hook._hooksCache.hasOwnProperty(name)) {
|
|
601
|
-
var emits = this.collect.hook._hooksCache[name];
|
|
602
|
-
if (!Object.keys(emits).length) return;
|
|
603
|
-
var _loop_1 = function _loop_1(key) {
|
|
604
|
-
if (emits[key].length) {
|
|
605
|
-
emits[key].forEach(function (item) {
|
|
606
|
-
_this.collect.hook.emit(key, item);
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
for (var key in emits) {
|
|
611
|
-
_loop_1(key);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
Ab.prototype.loadMode = function () {
|
|
616
|
-
// const name = getIframeUrl();
|
|
617
|
-
// let editMode = '';
|
|
618
|
-
// if (name) {
|
|
619
|
-
// const { scenario, href } = name;
|
|
620
|
-
// if (scenario) {
|
|
621
|
-
// this.editMode = true;
|
|
622
|
-
// editMode = scenario;
|
|
623
|
-
// } else if (
|
|
624
|
-
// href &&
|
|
625
|
-
// (href.indexOf('datatester') !== -1 ||
|
|
626
|
-
// href.indexOf('visual-editor') !== -1)
|
|
627
|
-
// ) {
|
|
628
|
-
// this.editMode = true;
|
|
629
|
-
// editMode = 'visual-editor';
|
|
630
|
-
// }
|
|
631
|
-
// }
|
|
632
|
-
// if (this.enable_ab_visual) {
|
|
633
|
-
// readyToLoadEditor(this.collect, this.config);
|
|
634
|
-
// if (editMode === 'visual-editor') {
|
|
635
|
-
// this.collect.destoryInstace();
|
|
636
|
-
// return;
|
|
637
|
-
// }
|
|
638
|
-
// }
|
|
639
|
-
// if (this.enable_multilink) {
|
|
640
|
-
// loadMuiltlink(this.collect, this.config);
|
|
641
|
-
// }
|
|
642
|
-
};
|
|
643
|
-
Ab.prototype.checkLocal = function () {
|
|
644
|
-
var _a = this.getABCache(),
|
|
645
|
-
ab_version = _a.ab_version,
|
|
646
|
-
ab_ext_version = _a.ab_ext_version,
|
|
647
|
-
ab_version_multilink = _a.ab_version_multilink,
|
|
648
|
-
data = _a.data;
|
|
649
|
-
var mulilinkUrlVid = this.checkFromUrl();
|
|
650
|
-
if (mulilinkUrlVid) {
|
|
651
|
-
this.mulilinkVersions.push(mulilinkUrlVid);
|
|
652
|
-
} else {
|
|
653
|
-
this.mulilinkVersions = ab_version_multilink || [];
|
|
654
|
-
}
|
|
655
|
-
this.extVersions = ab_ext_version || [];
|
|
656
|
-
this.versions = ab_version || [];
|
|
657
|
-
this.data = data;
|
|
658
|
-
var vids = this.versions.concat(this.extVersions);
|
|
659
|
-
if (this.enable_multilink) {
|
|
660
|
-
vids = vids.concat(this.mulilinkVersions);
|
|
661
|
-
}
|
|
662
|
-
this.configVersions(vids.join(','));
|
|
663
|
-
};
|
|
664
|
-
Ab.prototype.checkFromUrl = function () {
|
|
665
|
-
var urlQueryObj = parseUrlQuery(window.location.href);
|
|
666
|
-
if (urlQueryObj && urlQueryObj['vid']) {
|
|
667
|
-
return urlQueryObj['vid'];
|
|
668
|
-
}
|
|
669
|
-
return '';
|
|
670
|
-
};
|
|
671
|
-
Ab.prototype.updateVersions = function () {
|
|
672
|
-
var versions = this.extVersions.length ? this.versions.concat(this.extVersions) : this.versions;
|
|
673
|
-
if (this.enable_multilink) {
|
|
674
|
-
versions = versions.concat(this.mulilinkVersions);
|
|
675
|
-
}
|
|
676
|
-
this.configVersions(versions.join(','));
|
|
677
|
-
this.updateABCache();
|
|
678
|
-
this.changeListener.size > 0 && this.changeListener.forEach(function (listener) {
|
|
679
|
-
if (typeof listener === 'function') {
|
|
680
|
-
listener(versions);
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
};
|
|
684
|
-
Ab.prototype.configVersions = function (vids) {
|
|
685
|
-
this.collect.configManager.setAbVersion(vids);
|
|
686
|
-
};
|
|
687
|
-
Ab.prototype.getVar = function (name, defaultValue, callback) {
|
|
688
|
-
if (!name) {
|
|
689
|
-
throw new Error('variable must not be empty');
|
|
690
|
-
}
|
|
691
|
-
if (defaultValue === undefined) {
|
|
692
|
-
throw new Error('variable no default value');
|
|
693
|
-
}
|
|
694
|
-
if (typeof callback !== 'function') {
|
|
695
|
-
throw new Error('callback must be a function');
|
|
696
|
-
}
|
|
697
|
-
var callbackObj = {
|
|
698
|
-
name: name,
|
|
699
|
-
defaultValue: defaultValue,
|
|
700
|
-
callback: callback,
|
|
701
|
-
type: CallbackType.Var
|
|
702
|
-
};
|
|
703
|
-
if (this.fetchStatus === 'complete' && this.refreshFetchStatus === 'complete') {
|
|
704
|
-
this.getRealVar(callbackObj, name);
|
|
705
|
-
} else {
|
|
706
|
-
this.callbacks.push(callbackObj);
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
Ab.prototype.getRealVar = function (item, key) {
|
|
710
|
-
var name = item.name,
|
|
711
|
-
defaultValue = item.defaultValue,
|
|
712
|
-
callback = item.callback;
|
|
713
|
-
var data = this.data;
|
|
714
|
-
if (!data) {
|
|
715
|
-
callback(defaultValue);
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
if (isObject(data[name])) {
|
|
719
|
-
var vid = data[name].vid;
|
|
720
|
-
if (key === '$ab_url') {
|
|
721
|
-
if (!this.mulilinkVersions.includes(vid)) {
|
|
722
|
-
this.mulilinkVersions.push(vid);
|
|
723
|
-
}
|
|
724
|
-
} else {
|
|
725
|
-
if (!this.versions.includes(vid)) {
|
|
726
|
-
this.versions.push(vid);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
this.updateVersions();
|
|
730
|
-
this.fechEvent(vid, key, defaultValue);
|
|
731
|
-
callback(data[name].val);
|
|
732
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
733
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
734
|
-
secType: 'AB',
|
|
735
|
-
info: "SDK \u66DD\u5149\u4E86\u5B9E\u9A8C" + name,
|
|
736
|
-
level: 'info',
|
|
737
|
-
time: Date.now(),
|
|
738
|
-
data: data[name]
|
|
739
|
-
});
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
743
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
744
|
-
secType: 'AB',
|
|
745
|
-
info: 'SDK 调用getVar',
|
|
746
|
-
level: 'info',
|
|
747
|
-
time: Date.now(),
|
|
748
|
-
data: defaultValue
|
|
749
|
-
});
|
|
750
|
-
callback(defaultValue);
|
|
751
|
-
};
|
|
752
|
-
Ab.prototype.getAllVars = function (callback) {
|
|
753
|
-
if (typeof callback !== 'function') {
|
|
754
|
-
throw new Error('callback must be a function');
|
|
755
|
-
}
|
|
756
|
-
var callbackObj = {
|
|
757
|
-
callback: callback,
|
|
758
|
-
type: CallbackType.All
|
|
759
|
-
};
|
|
760
|
-
if (this.fetchStatus === 'complete' && this.refreshFetchStatus === 'complete') {
|
|
761
|
-
this.getRealAllVars(callbackObj);
|
|
762
|
-
} else {
|
|
763
|
-
this.callbacks.push(callbackObj);
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
Ab.prototype.getRealAllVars = function (item) {
|
|
767
|
-
var callback = item.callback;
|
|
768
|
-
callback(this.data ? JSON.parse(JSON.stringify(this.data)) : {});
|
|
769
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
770
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
771
|
-
secType: 'AB',
|
|
772
|
-
info: 'SDK 调用getAllVars',
|
|
773
|
-
level: 'info',
|
|
774
|
-
time: Date.now(),
|
|
775
|
-
data: this.data
|
|
776
|
-
});
|
|
777
|
-
};
|
|
778
|
-
Ab.prototype.fechEvent = function (vid, key, ab_url) {
|
|
779
|
-
try {
|
|
780
|
-
if (this.config.disable_track_event) return;
|
|
781
|
-
if (!vid) return;
|
|
782
|
-
var _a = this.collect.configManager.get(),
|
|
783
|
-
header = _a.header,
|
|
784
|
-
user = _a.user;
|
|
785
|
-
var cache = this.getABCache();
|
|
786
|
-
if (cache && cache.uuid && cache.uuid !== user.user_unique_id) return;
|
|
787
|
-
var event_1 = {
|
|
788
|
-
event: 'abtest_exposure',
|
|
789
|
-
ab_sdk_version: "" + vid,
|
|
790
|
-
params: JSON.stringify({
|
|
791
|
-
app_id: this.config.appId,
|
|
792
|
-
ab_url: key === '$ab_url' ? ab_url : window.location.href
|
|
793
|
-
}),
|
|
794
|
-
local_time_ms: Date.now()
|
|
795
|
-
};
|
|
796
|
-
header['custom'] = JSON.stringify(header['custom']);
|
|
797
|
-
var abData = {
|
|
798
|
-
events: [event_1],
|
|
799
|
-
user: user,
|
|
800
|
-
header: header
|
|
801
|
-
};
|
|
802
|
-
if (key === '$ab_url') {
|
|
803
|
-
if (window.navigator.sendBeacon) {
|
|
804
|
-
window.navigator.sendBeacon(this.reportUrl, JSON.stringify([abData]));
|
|
805
|
-
} else {
|
|
806
|
-
this.reportExposure(abData);
|
|
807
|
-
}
|
|
808
|
-
} else {
|
|
809
|
-
this.reportExposure(abData);
|
|
810
|
-
}
|
|
811
|
-
} catch (e) {
|
|
812
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
813
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
814
|
-
info: '发生了异常',
|
|
815
|
-
level: 'error',
|
|
816
|
-
time: Date.now(),
|
|
817
|
-
data: e.message
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
Ab.prototype.reportExposure = function (abData) {
|
|
822
|
-
var _this = this;
|
|
823
|
-
this.exposureCache.push(abData);
|
|
824
|
-
if (this.reportTimeout) {
|
|
825
|
-
clearTimeout(this.reportTimeout);
|
|
826
|
-
}
|
|
827
|
-
if (this.exposureCache.length >= this.exposureLimit) {
|
|
828
|
-
this.report();
|
|
829
|
-
} else {
|
|
830
|
-
this.reportTimeout = setTimeout(function () {
|
|
831
|
-
_this.report();
|
|
832
|
-
clearTimeout(_this.reportTimeout);
|
|
833
|
-
}, this.ab_batch_time);
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
Ab.prototype.report = function () {
|
|
837
|
-
var _this = this;
|
|
838
|
-
var encodeData = this.collect.cryptoData(this.exposureCache);
|
|
839
|
-
this.collect.requestManager.useRequest({
|
|
840
|
-
url: this.reportUrl,
|
|
841
|
-
data: encodeData,
|
|
842
|
-
timeout: 100000,
|
|
843
|
-
useBeacon: false,
|
|
844
|
-
encryption: this.config.enable_encryption,
|
|
845
|
-
encryption_header: this.config.encryption_header,
|
|
846
|
-
zip: true,
|
|
847
|
-
type: 'event'
|
|
848
|
-
});
|
|
849
|
-
this.exposureCache.forEach(function (item) {
|
|
850
|
-
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
851
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_EVENT,
|
|
852
|
-
info: '埋点上报成功',
|
|
853
|
-
time: Date.now(),
|
|
854
|
-
data: [item],
|
|
855
|
-
code: 200,
|
|
856
|
-
status: 'success'
|
|
857
|
-
});
|
|
858
|
-
});
|
|
859
|
-
this.exposureCache = [];
|
|
860
|
-
};
|
|
861
|
-
Ab.prototype.setExternalAbVersion = function (vid) {
|
|
862
|
-
this.extVersions = [vid];
|
|
863
|
-
this.updateVersions();
|
|
864
|
-
};
|
|
865
|
-
Ab.prototype.getABconfig = function (params, callback) {
|
|
866
|
-
var keys = Object.keys(params);
|
|
867
|
-
if (keys && keys.length) {
|
|
868
|
-
this.collect.configManager.set(params);
|
|
869
|
-
}
|
|
870
|
-
this.fetchAB(callback);
|
|
871
|
-
};
|
|
872
|
-
Ab.prototype.get = function (key) {
|
|
873
|
-
if (this.ab_cross) {
|
|
874
|
-
var ab_cookie = this.cacheStorgae.getCookie(key, this.ab_cookie_domain);
|
|
875
|
-
return ab_cookie ? JSON.parse(ab_cookie) : null;
|
|
876
|
-
} else {
|
|
877
|
-
return this.cacheStorgae.getLocalItem(key);
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
Ab.prototype.set = function (key, data) {
|
|
881
|
-
if (this.ab_cross) {
|
|
882
|
-
this.cacheStorgae.setCookie(key, data, STORAGE_EXPRIRE, this.ab_cookie_domain);
|
|
883
|
-
} else {
|
|
884
|
-
this.cacheStorgae.setLocalItem(key, data);
|
|
885
|
-
}
|
|
886
|
-
this.collect.configManager.setAbCache(data);
|
|
887
|
-
};
|
|
888
|
-
Ab.prototype.getABCache = function (key) {
|
|
889
|
-
var data = {
|
|
890
|
-
ab_version: [],
|
|
891
|
-
ab_ext_version: [],
|
|
892
|
-
ab_version_multilink: [],
|
|
893
|
-
data: null,
|
|
894
|
-
timestamp: +new Date(),
|
|
895
|
-
uuid: ''
|
|
896
|
-
};
|
|
897
|
-
data = this.get(this.abKey) || data;
|
|
898
|
-
if (Date.now() - data.timestamp >= STORAGE_EXPRIRE) {
|
|
899
|
-
this.cacheStorgae.removeLocalItem(this.abKey);
|
|
900
|
-
return null;
|
|
901
|
-
}
|
|
902
|
-
if (key) {
|
|
903
|
-
return data[key];
|
|
904
|
-
}
|
|
905
|
-
return data;
|
|
906
|
-
};
|
|
907
|
-
Ab.prototype.updateABCache = function () {
|
|
908
|
-
var cache = this.getABCache();
|
|
909
|
-
cache.ab_version_multilink = this.mulilinkVersions;
|
|
910
|
-
cache.ab_ext_version = this.extVersions;
|
|
911
|
-
cache.ab_version = this.versions;
|
|
912
|
-
cache.timestamp = Date.now();
|
|
913
|
-
this.set(this.abKey, cache);
|
|
914
|
-
};
|
|
915
|
-
Ab.prototype.setAbCache = function (uuid) {
|
|
916
|
-
var cache = this.getABCache();
|
|
917
|
-
cache.data = this.data;
|
|
918
|
-
cache.uuid = uuid;
|
|
919
|
-
cache.timestamp = Date.now();
|
|
920
|
-
this.set(this.abKey, cache);
|
|
921
|
-
};
|
|
922
|
-
Ab.prototype.clearCache = function () {
|
|
923
|
-
this.refreshFetchStatus = 'ing';
|
|
924
|
-
this.data = {};
|
|
925
|
-
this.extVersions = [];
|
|
926
|
-
this.mulilinkVersions = [];
|
|
927
|
-
this.versions = [];
|
|
928
|
-
this.collect.configManager.clearAbCache();
|
|
929
|
-
};
|
|
930
|
-
Ab.prototype.openOverlayer = function (timeout) {
|
|
931
|
-
var _this = this;
|
|
932
|
-
openOverlayer();
|
|
933
|
-
if (timeout) {
|
|
934
|
-
var layer_1 = setTimeout(function () {
|
|
935
|
-
_this.closeOverlayer();
|
|
936
|
-
clearTimeout(layer_1);
|
|
937
|
-
}, timeout);
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
Ab.prototype.closeOverlayer = function () {
|
|
941
|
-
closeOverlayer();
|
|
942
|
-
};
|
|
943
|
-
Ab.prototype.fetchComplete = function (abData, uuid) {
|
|
944
|
-
var _this = this;
|
|
945
|
-
if (abData && Object.prototype.toString.call(abData) == '[object Object]') {
|
|
946
|
-
this.data = abData;
|
|
947
|
-
this.setAbCache(uuid);
|
|
948
|
-
var versions_1 = [];
|
|
949
|
-
Object.keys(abData).forEach(function (key) {
|
|
950
|
-
var vid = abData[key].vid;
|
|
951
|
-
if (vid) {
|
|
952
|
-
versions_1.push(vid);
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
this.versions = this.versions.filter(function (vid) {
|
|
956
|
-
return versions_1.includes(vid);
|
|
957
|
-
});
|
|
958
|
-
var $ab_url = abData.$ab_url,
|
|
959
|
-
$ab_modification = abData.$ab_modification;
|
|
960
|
-
if ($ab_modification && $ab_modification.val && this.enable_ab_visual) {
|
|
961
|
-
if (this.collect.destroy) return;
|
|
962
|
-
this.getVar('$ab_modification', window.location.href, function () {
|
|
963
|
-
// loadVisual($ab_modification.val);
|
|
964
|
-
_this.closeOverlayer();
|
|
965
|
-
});
|
|
966
|
-
} else if ($ab_url && this.enable_multilink) {
|
|
967
|
-
this.mulilinkVersions = this.mulilinkVersions.filter(function (vid) {
|
|
968
|
-
return versions_1.includes(vid);
|
|
969
|
-
});
|
|
970
|
-
var val_1 = $ab_url.val,
|
|
971
|
-
vid_1 = $ab_url.vid;
|
|
972
|
-
if (val_1 && vid_1) {
|
|
973
|
-
this.getVar('$ab_url', val_1, function () {
|
|
974
|
-
if (_this.editMode) return;
|
|
975
|
-
if (val_1 !== window.location.href) {
|
|
976
|
-
setTimeout(function () {
|
|
977
|
-
if (_this.collect.destroy) return;
|
|
978
|
-
var jump = "" + val_1;
|
|
979
|
-
jump = jump.indexOf('http') === -1 ? "https://" + jump : jump;
|
|
980
|
-
var newhost = parseURL(jump).host;
|
|
981
|
-
try {
|
|
982
|
-
var urlObj = new URL(jump);
|
|
983
|
-
if (newhost !== location.host) {
|
|
984
|
-
// 跳转的是一个新域名
|
|
985
|
-
urlObj.searchParams.append('vid', vid_1);
|
|
986
|
-
} else {
|
|
987
|
-
// 不同的域名不能replace
|
|
988
|
-
window.history.replaceState('', '', jump);
|
|
989
|
-
}
|
|
990
|
-
window.location.href = urlObj.href;
|
|
991
|
-
} catch (e) {
|
|
992
|
-
window.location.href = jump;
|
|
993
|
-
}
|
|
994
|
-
}, 100);
|
|
995
|
-
} else {
|
|
996
|
-
_this.closeOverlayer();
|
|
997
|
-
}
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
this.updateVersions();
|
|
1002
|
-
} else {
|
|
1003
|
-
this.closeOverlayer();
|
|
1004
|
-
}
|
|
1005
|
-
this.callbacks.forEach(function (item) {
|
|
1006
|
-
return _this[item.type === CallbackType.Var ? 'getRealVar' : 'getRealAllVars'](item, '');
|
|
1007
|
-
});
|
|
1008
|
-
this.callbacks = [];
|
|
1009
|
-
};
|
|
1010
|
-
Ab.prototype.fetchAB = function (callback) {
|
|
1011
|
-
var _this = this;
|
|
1012
|
-
var env = this.collect.configManager.get();
|
|
1013
|
-
var header = env.header,
|
|
1014
|
-
user = env.user;
|
|
1015
|
-
if (this.config.enable_anonymousid) {
|
|
1016
|
-
delete user.web_id;
|
|
1017
|
-
}
|
|
1018
|
-
var fetchUuid = user.user_unique_id;
|
|
1019
|
-
var requestBody = {
|
|
1020
|
-
header: __assign(__assign(__assign({
|
|
1021
|
-
aid: this.config.app_id
|
|
1022
|
-
}, user || {}), header || {}), {
|
|
1023
|
-
ab_sdk_version: this.collect.configManager.getAbVersion(),
|
|
1024
|
-
ab_url: window.location.href
|
|
1025
|
-
})
|
|
1026
|
-
};
|
|
1027
|
-
var cryptoData = this.collect.cryptoData(requestBody);
|
|
1028
|
-
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1029
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1030
|
-
info: 'SDK 发起AB实验请求',
|
|
1031
|
-
level: 'info',
|
|
1032
|
-
logType: 'fetch',
|
|
1033
|
-
time: Date.now(),
|
|
1034
|
-
data: requestBody,
|
|
1035
|
-
infoType: 'sdk'
|
|
1036
|
-
});
|
|
1037
|
-
this.collect.requestManager.useRequest({
|
|
1038
|
-
url: this.fetchUrl,
|
|
1039
|
-
data: cryptoData,
|
|
1040
|
-
success: function success(response) {
|
|
1041
|
-
_this.fetchStatus = 'complete';
|
|
1042
|
-
_this.refreshFetchStatus = 'complete';
|
|
1043
|
-
// let aa = {
|
|
1044
|
-
// message: "success",
|
|
1045
|
-
// data: {
|
|
1046
|
-
// abcdefg: { val: "gss", vid: "11407" },
|
|
1047
|
-
// erf: { val: 'name', vid: "22" },
|
|
1048
|
-
// hhhhh: { val: 'age', vid: "33" },
|
|
1049
|
-
// juuioh: { val: 'sex', vid: "44" },
|
|
1050
|
-
// $ab_url: { val: 'http://0.0.0.0:8899/index_cdn_5.html?off=true', vid: '0000' }
|
|
1051
|
-
// }
|
|
1052
|
-
// }
|
|
1053
|
-
// if (env.user.user_unique_id === 'ssss') {
|
|
1054
|
-
// aa.data.abcdefg.vid = '00000'
|
|
1055
|
-
// }
|
|
1056
|
-
var data = response.data,
|
|
1057
|
-
message = response.message; // 解析出code
|
|
1058
|
-
if (message === 'success') {
|
|
1059
|
-
_this.fetchComplete(data, fetchUuid);
|
|
1060
|
-
callback && callback(data);
|
|
1061
|
-
} else {
|
|
1062
|
-
_this.fetchComplete(null, fetchUuid);
|
|
1063
|
-
callback && callback(null);
|
|
1064
|
-
}
|
|
1065
|
-
_this.collect.emit(_this.types.AbComplete, data);
|
|
1066
|
-
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1067
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1068
|
-
secType: 'AB',
|
|
1069
|
-
info: 'AB实验请求成功',
|
|
1070
|
-
level: 'info',
|
|
1071
|
-
logType: 'fetch',
|
|
1072
|
-
time: Date.now(),
|
|
1073
|
-
data: data,
|
|
1074
|
-
infoType: 'sdk'
|
|
1075
|
-
});
|
|
1076
|
-
},
|
|
1077
|
-
fail: function fail() {
|
|
1078
|
-
_this.fetchStatus = 'complete';
|
|
1079
|
-
_this.refreshFetchStatus = 'complete';
|
|
1080
|
-
_this.fetchComplete(null, fetchUuid);
|
|
1081
|
-
callback && callback(null);
|
|
1082
|
-
_this.collect.emit(_this.types.AbTimeout);
|
|
1083
|
-
_this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
1084
|
-
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
1085
|
-
secType: 'AB',
|
|
1086
|
-
info: 'AB实验请求网络异常',
|
|
1087
|
-
level: 'error',
|
|
1088
|
-
logType: 'fetch',
|
|
1089
|
-
time: Date.now(),
|
|
1090
|
-
infoType: 'sdk'
|
|
1091
|
-
});
|
|
1092
|
-
},
|
|
1093
|
-
timeout: this.config.ab_timeout || 10000,
|
|
1094
|
-
encryption: this.config.enable_encryption,
|
|
1095
|
-
encryption_header: this.config.encryption_header
|
|
1096
|
-
});
|
|
1097
|
-
};
|
|
1098
|
-
Ab.prototype.filterUrl = function (url) {
|
|
1099
|
-
try {
|
|
1100
|
-
var _reg = '';
|
|
1101
|
-
if (url.indexOf('&multilink=true') !== -1) {
|
|
1102
|
-
_reg = '&multilink=true[\x00-\xff]*';
|
|
1103
|
-
} else if (url.indexOf('?multilink=true') !== -1) {
|
|
1104
|
-
_reg = '\\?multilink=true[\x00-\xff]*';
|
|
1105
|
-
}
|
|
1106
|
-
var reg = new RegExp(_reg, 'g');
|
|
1107
|
-
url = url.replace(reg, '');
|
|
1108
|
-
} catch (e) {}
|
|
1109
|
-
return url;
|
|
1110
|
-
};
|
|
1111
|
-
return Ab;
|
|
1112
|
-
}();
|
|
1113
|
-
|
|
1114
|
-
export { Ab as default };
|
|
1
|
+
function e(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var t="__rangers_ab_style__";var i={cn:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",va:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k",sg:"1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k"},n=function(e){return e.DEBUGGER_MESSAGE="debugger-message",e.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",e.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",e.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",e.DEBUGGER_MESSAGE_EVENT="debugger-message-event",e.DEVTOOL_WEB_READY="devtool-web-ready",e}({});Date.now(),Number((""+Math.random()).slice(2,8));var o=function(e){return function(e,t,i){if("string"==typeof e&&"number"==typeof t&&"number"==typeof i){var n,o=[];i=i<=25?i:i%25;var s=String.fromCharCode(i+97);n=e.split(s);for(var r=0;r<n.length;r++){var a=parseInt(n[r],i);a=1*a^t;var c=String.fromCharCode(a);o.push(c)}return o.join("")}}(e,64,25)},s=function(e){var t=document.createElement("a");return t.href=e,t};var r,a,c=(r=function(e,t){var i;i=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var i=arguments[e];for(var n in i)t[n]=i[n]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function i(n){function o(){}function s(t,i,s){if("undefined"!=typeof document){"number"==typeof(s=e({path:"/"},o.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var r=JSON.stringify(i);/^[\{\[]/.test(r)&&(i=r)}catch(e){}i=n.write?n.write(i,t):encodeURIComponent(String(i)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var c in s)s[c]&&(a+="; "+c,!0!==s[c]&&(a+="="+s[c].split(";")[0]));return document.cookie=t+"="+i+a}}function r(e,i){if("undefined"!=typeof document){for(var o={},s=document.cookie?document.cookie.split("; "):[],r=0;r<s.length;r++){var a=s[r].split("="),c=a.slice(1).join("=");i||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var l=t(a[0]);if(c=(n.read||n)(c,l)||t(c),i)try{c=JSON.parse(c)}catch(e){}if(o[l]=c,e===l)break}catch(e){}}return e?o[e]:o}}return o.set=s,o.get=function(e){return r(e,!1)},o.getJSON=function(e){return r(e,!0)},o.remove=function(t,i){s(t,"",e(i,{expires:-1}))},o.defaults={},o.withConverter=i,o}(function(){})},e.exports=i()},r(a={exports:{}},a.exports),a.exports),l=function(){function t(){e(this,"cache",void 0),this.cache={}}var i=t.prototype;return i.setItem=function(e,t){this.cache[e]=t},i.getItem=function(e){return this.cache[e]},i.removeItem=function(e){this.cache[e]=void 0},t}(),h=function(){function t(){e(this,"support",void 0),this.support=this.isSupportLS()}var i=t.prototype;return i.isSupportLS=function(){try{return localStorage.setItem("_applogtest-test-key","hi"),localStorage.getItem("_applogtest-test-key"),localStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=localStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},t}(),u=function(){function t(){e(this,"support",void 0),this.support=this.isSupportSession()}var i=t.prototype;return i.isSupportSession=function(){try{return sessionStorage.setItem("_applogtest-test-key","hi"),sessionStorage.getItem("_applogtest-test-key"),sessionStorage.removeItem("_applogtest-test-key"),!0}catch(e){return!1}},i.getItem=function(e){try{var t=sessionStorage.getItem(e),i=t;try{t&&"string"==typeof t&&(i=JSON.parse(t))}catch(e){}return i||{}}catch(e){}return{}},i.setItem=function(e,t){try{var i="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,i)}catch(e){}},i.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},t}(),f=function(){function t(){e(this,"local",void 0),e(this,"session",void 0),e(this,"cache",void 0),e(this,"defaultExpireTime",void 0),this.defaultExpireTime=6048e5,this.local=new h,this.session=new u,this.cache=new l}var i=t.prototype;return i.getLocalItem=function(e){return this.local.getItem(e)},i.setLocalItem=function(e,t){this.local.setItem(e,t)},i.removeLocalItem=function(e){this.local.removeItem(e)},i.getSessionItem=function(e){return this.session.getItem(e)},i.setSessionItem=function(e,t){this.session.setItem(e,t)},i.removeSessionItem=function(e){this.session.removeItem(e)},i.getCacheItem=function(e){return this.cache.getItem(e)},i.setCacheItem=function(e,t){this.cache.setItem(e,t)},i.removeCacheItem=function(e){this.cache.removeItem(e)},i.getCookie=function(e,t){try{return c.get(e)}catch(e){return""}},i.setCookie=function(e,t,i,n){void 0===i&&(i=this.defaultExpireTime);try{var o=n||document.domain,s=+new Date+i;c.set(e,t,{expires:new Date(s),path:"/",domain:o})}catch(e){}},i.removeCookie=function(e,t){try{c.remove(e,{path:"/",domain:t||""})}catch(e){}},t}(),m=function(e){return e[e.Var=0]="Var",e[e.All=1]="All",e}(m||{}),p=2592e6,d=function(){function r(){e(this,"collect",void 0),e(this,"config",void 0),e(this,"abOption",void 0),e(this,"fetchUrl",void 0),e(this,"reportUrl",void 0),e(this,"fetchStatus","no"),e(this,"refreshFetchStatus","complete"),e(this,"versions",[]),e(this,"extVersions",[]),e(this,"mulilinkVersions",[]),e(this,"enable_multilink",!1),e(this,"enable_ab_visual",!1),e(this,"editMode",!1),e(this,"callbacks",[]),e(this,"abKey",void 0),e(this,"cacheStorgae",void 0),e(this,"data",null),e(this,"changeListener",new Map),e(this,"fetch",void 0),e(this,"readyStatus",!1),e(this,"types",void 0),e(this,"ab_cross",void 0),e(this,"ab_cookie_domain",void 0),e(this,"exposureCache",[]),e(this,"exposureLimit",void 0),e(this,"ab_batch_time",void 0),e(this,"reportTimeout",void 0)}var a=r.prototype;return a.apply=function(e,t){var n=this;if(this.collect=e,this.config=t,this.config.enable_ab_test){var s=t.enable_multilink,r=t.ab_channel_domain,a=t.enable_ab_visual,c=t.ab_cross,l=t.ab_cookie_domain,h=t.disable_ab_reset,u=r||o(i[t.channel||"cn"]);this.cacheStorgae=new f,this.enable_multilink=s,this.enable_ab_visual=a,this.abKey="__tea_sdk_ab_version_"+t.app_id,this.ab_cross=c,this.ab_cookie_domain=l||"",this.fetchUrl=u+"/service/2/abtest_config/",this.reportUrl=""+e.configManager.getUrl("event"),this.exposureLimit=t.exposure_limit||20,this.ab_batch_time=t.ab_batch_time||500;var m=this.collect.Types;this.types=m,this.collect.on(m.TokenChange,function(e){h||"uuid"===e.type&&n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.TokenReset,function(){h||n.readyStatus&&(n.clearCache(),n.fetchAB())}),this.collect.on(m.AbVar,function(e){var t=e.name,i=e.defaultValue,o=e.callback;n.getVar(t,i,o)}),this.collect.on(m.AbAllVars,function(e){n.getAllVars(e)}),this.collect.on(m.AbConfig,function(e){var t=e.params,i=e.callback;n.getABconfig(t,i)}),this.collect.on(m.AbExternalVersion,function(e){n.setExternalAbVersion(e)}),this.collect.on(m.AbOpenLayer,function(){n.openOverlayer()}),this.collect.on(m.AbCloseLayer,function(){n.closeOverlayer()}),this.collect.on(m.AbVersionChangeOn,function(e){n.changeListener.set(e,e)}),this.collect.on(m.AbVersionChangeOff,function(e){n.changeListener.get(e)&&n.changeListener.delete(e)}),this.loadMode(),(this.enable_ab_visual||this.enable_multilink)&&this.openOverlayer(this.config.multilink_timeout_ms||500),this.checkLocal(),this.ready("ab"),this.readyStatus||(this.fetchAB(),this.readyStatus=!0),this.collect.emit(m.AbReady)}},a.ready=function(e){var t=this;if(this.collect.set(e),this.collect.hook._hooksCache.hasOwnProperty(e)){var i=this.collect.hook._hooksCache[e];if(!Object.keys(i).length)return;var n=function(e){i[e].length&&i[e].forEach(function(i){t.collect.hook.emit(e,i)})};for(var o in i)n(o)}},a.loadMode=function(){},a.checkLocal=function(){var e=this.getABCache(),t=e.ab_version,i=e.ab_ext_version,n=e.ab_version_multilink,o=e.data,s=this.checkFromUrl();s?this.mulilinkVersions.push(s):this.mulilinkVersions=n||[],this.extVersions=i||[],this.versions=t||[],this.data=o;var r=this.versions.concat(this.extVersions);this.enable_multilink&&(r=r.concat(this.mulilinkVersions)),this.configVersions(r.join(","))},a.checkFromUrl=function(){var e=function(e){var t={};try{var i=s(e).search;(i=i.slice(1)).split("&").forEach(function(e){var i,n,o=e.split("=");o.length&&(i=o[0],n=o[1]);try{t[i]=decodeURIComponent(void 0===n?"":n)}catch(e){t[i]=n}})}catch(e){}return t}(window.location.href);return e&&e.vid?e.vid:""},a.updateVersions=function(){var e=this.extVersions.length?this.versions.concat(this.extVersions):this.versions;this.enable_multilink&&(e=e.concat(this.mulilinkVersions)),this.configVersions(e.join(",")),this.updateABCache(),this.changeListener.size>0&&this.changeListener.forEach(function(t){"function"==typeof t&&t(e)})},a.configVersions=function(e){this.collect.configManager.setAbVersion(e)},a.getVar=function(e,t,i){if(!e)throw new Error("variable must not be empty");if(void 0===t)throw new Error("variable no default value");if("function"!=typeof i)throw new Error("callback must be a function");var n={name:e,defaultValue:t,callback:i,type:m.Var};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealVar(n,e):this.callbacks.push(n)},a.getRealVar=function(e,t){var i=e.name,o=e.defaultValue,s=e.callback,r=this.data;if(r){if(null!=(c=r[i])&&"[object Object]"==Object.prototype.toString.call(c)){var a=r[i].vid;return"$ab_url"===t?this.mulilinkVersions.includes(a)||this.mulilinkVersions.push(a):this.versions.includes(a)||this.versions.push(a),this.updateVersions(),this.fechEvent(a,t,o),s(r[i].val),void this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 曝光了实验"+i,level:"info",time:Date.now(),data:r[i]})}var c;this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getVar",level:"info",time:Date.now(),data:o}),s(o)}else s(o)},a.getAllVars=function(e){if("function"!=typeof e)throw new Error("callback must be a function");var t={callback:e,type:m.All};"complete"===this.fetchStatus&&"complete"===this.refreshFetchStatus?this.getRealAllVars(t):this.callbacks.push(t)},a.getRealAllVars=function(e){(0,e.callback)(this.data?JSON.parse(JSON.stringify(this.data)):{}),this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"SDK 调用getAllVars",level:"info",time:Date.now(),data:this.data})},a.fechEvent=function(e,t,i){try{if(this.config.disable_track_event)return;if(!e)return;var o=this.collect.configManager.get(),s=o.header,r=o.user,a=this.getABCache();if(a&&a.uuid&&a.uuid!==r.user_unique_id)return;var c={event:"abtest_exposure",ab_sdk_version:""+e,params:JSON.stringify({app_id:this.config.appId,ab_url:"$ab_url"===t?i:window.location.href}),local_time_ms:Date.now()};s.custom=JSON.stringify(s.custom);var l={events:[c],user:r,header:s};"$ab_url"===t&&window.navigator.sendBeacon?window.navigator.sendBeacon(this.reportUrl,JSON.stringify([l])):this.reportExposure(l)}catch(e){this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message})}},a.reportExposure=function(e){var t=this;this.exposureCache.push(e),this.reportTimeout&&clearTimeout(this.reportTimeout),this.exposureCache.length>=this.exposureLimit?this.report():this.reportTimeout=setTimeout(function(){t.report(),clearTimeout(t.reportTimeout)},this.ab_batch_time)},a.report=function(){var e=this,t=this.collect.cryptoData(this.exposureCache);this.collect.requestManager.useRequest({url:this.reportUrl,data:t,timeout:1e5,useBeacon:!1,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header,zip:!0,type:"event"}),this.exposureCache.forEach(function(t){e.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_EVENT,info:"埋点上报成功",time:Date.now(),data:[t],code:200,status:"success"})}),this.exposureCache=[]},a.setExternalAbVersion=function(e){this.extVersions=[e],this.updateVersions()},a.getABconfig=function(e,t){var i=Object.keys(e);i&&i.length&&this.collect.configManager.set(e),this.fetchAB(t)},a.get=function(e){if(this.ab_cross){var t=this.cacheStorgae.getCookie(e,this.ab_cookie_domain);return t?JSON.parse(t):null}return this.cacheStorgae.getLocalItem(e)},a.set=function(e,t){this.ab_cross?this.cacheStorgae.setCookie(e,t,p,this.ab_cookie_domain):this.cacheStorgae.setLocalItem(e,t),this.collect.configManager.setAbCache(t)},a.getABCache=function(e){var t={ab_version:[],ab_ext_version:[],ab_version_multilink:[],data:null,timestamp:+new Date,uuid:""};return t=this.get(this.abKey)||t,Date.now()-t.timestamp>=p?(this.cacheStorgae.removeLocalItem(this.abKey),null):e?t[e]:t},a.updateABCache=function(){var e=this.getABCache();e.ab_version_multilink=this.mulilinkVersions,e.ab_ext_version=this.extVersions,e.ab_version=this.versions,e.timestamp=Date.now(),this.set(this.abKey,e)},a.setAbCache=function(e){var t=this.getABCache();t.data=this.data,t.uuid=e,t.timestamp=Date.now(),this.set(this.abKey,t)},a.clearCache=function(){this.refreshFetchStatus="ing",this.data={},this.extVersions=[],this.mulilinkVersions=[],this.versions=[],this.collect.configManager.clearAbCache()},a.openOverlayer=function(e){var i=this;if(function(){if(!document.getElementById(t)){var e="body { opacity: 0 !important; }",i=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.id=t,n.type="text/css",n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),i.appendChild(n)}}(),e)var n=setTimeout(function(){i.closeOverlayer(),clearTimeout(n)},e)},a.closeOverlayer=function(){var e;(e=document.getElementById(t))&&e.parentElement.removeChild(e)},a.fetchComplete=function(e,t){var i=this;if(e&&"[object Object]"==Object.prototype.toString.call(e)){this.data=e,this.setAbCache(t);var n=[];Object.keys(e).forEach(function(t){var i=e[t].vid;i&&n.push(i)}),this.versions=this.versions.filter(function(e){return n.includes(e)});var o=e.$ab_url,r=e.$ab_modification;if(r&&r.val&&this.enable_ab_visual){if(this.collect.destroy)return;this.getVar("$ab_modification",window.location.href,function(){i.closeOverlayer()})}else if(o&&this.enable_multilink){this.mulilinkVersions=this.mulilinkVersions.filter(function(e){return n.includes(e)});var a=o.val,c=o.vid;a&&c&&this.getVar("$ab_url",a,function(){i.editMode||(a!==window.location.href?setTimeout(function(){if(!i.collect.destroy){var e=""+a;e=-1===e.indexOf("http")?"https://"+e:e;var t=s(e).host;try{var n=new URL(e);t!==location.host?n.searchParams.append("vid",c):window.history.replaceState("","",e),window.location.href=n.href}catch(t){window.location.href=e}}},100):i.closeOverlayer())})}this.updateVersions()}else this.closeOverlayer();this.callbacks.forEach(function(e){return i[e.type===m.Var?"getRealVar":"getRealAllVars"](e,"")}),this.callbacks=[]},a.fetchAB=function(e){var t=this,i=this.collect.configManager.get(),o=i.header,s=i.user;this.config.enable_anonymousid&&delete s.web_id;var r=s.user_unique_id,a={header:Object.assign({aid:this.config.app_id},s||{},o||{},{ab_sdk_version:this.collect.configManager.getAbVersion(),ab_url:window.location.href})},c=this.collect.cryptoData(a);this.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,info:"SDK 发起AB实验请求",level:"info",logType:"fetch",time:Date.now(),data:a,infoType:"sdk"}),this.collect.requestManager.useRequest({url:this.fetchUrl,data:c,success:function(i){t.fetchStatus="complete",t.refreshFetchStatus="complete";var o=i.data;"success"===i.message?(t.fetchComplete(o,r),e&&e(o)):(t.fetchComplete(null,r),e&&e(null)),t.collect.emit(t.types.AbComplete,o),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求成功",level:"info",logType:"fetch",time:Date.now(),data:o,infoType:"sdk"})},fail:function(){t.fetchStatus="complete",t.refreshFetchStatus="complete",t.fetchComplete(null,r),e&&e(null),t.collect.emit(t.types.AbTimeout),t.collect.emit(n.DEBUGGER_MESSAGE,{type:n.DEBUGGER_MESSAGE_SDK,secType:"AB",info:"AB实验请求网络异常",level:"error",logType:"fetch",time:Date.now(),infoType:"sdk"})},timeout:this.config.ab_timeout||1e4,encryption:this.config.enable_encryption,encryption_header:this.config.encryption_header})},a.filterUrl=function(e){try{var t="";-1!==e.indexOf("&multilink=true")?t="&multilink=true[\0-ÿ]*":-1!==e.indexOf("?multilink=true")&&(t="\\?multilink=true[\0-ÿ]*");var i=new RegExp(t,"g");e=e.replace(i,"")}catch(e){}return e},r}();export{d as default};
|