@datarangers/sdk-javascript 0.1.1 → 0.1.3
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 +6218 -1
- package/es/index.min.js +9165 -1
- package/es/plugin/ab.js +1114 -1
- package/es/plugin/autotrack.js +1608 -1
- package/es/plugin/duration.js +100 -1
- package/es/plugin/route.js +605 -1
- package/es/plugin/stay.js +476 -1
- package/lib/index-base.min.js +6223 -1
- package/lib/index.min.js +9170 -1
- package/lib/plugin/ab.js +1116 -1
- package/lib/plugin/autotrack.js +1610 -1
- package/lib/plugin/duration.js +102 -1
- package/lib/plugin/route.js +607 -1
- package/lib/plugin/stay.js +478 -1
- package/package.json +1 -1
- package/types/types.d.ts +2 -0
package/lib/plugin/route.js
CHANGED
|
@@ -1 +1,607 @@
|
|
|
1
|
-
"use strict";function e(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var r,n,a=o.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=a.next()).done;)i.push(r.value)}catch(e){n={error:e}}finally{try{r&&!r.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}return i}function t(){for(var t=[],o=0;o<arguments.length;o++)t=t.concat(e(arguments[o]));return t}var o,r;!function(e){e.Init="init",e.Config="config",e.Start="start",e.Ready="ready",e.TokenComplete="token-complete",e.TokenStorage="token-storage",e.TokenFetch="token-fetch",e.TokenError="token-error",e.ConfigUuid="config-uuid",e.ConfigWebId="config-webid",e.ConfigDomain="config-domain",e.CustomWebId="custom-webid",e.AnonymousId="anonymous-id",e.TokenChange="token-change",e.TokenReset="token-reset",e.ConfigTransform="config-transform",e.EnvTransform="env-transform",e.SessionReset="session-reset",e.SessionResetTime="session-reset-time",e.Event="event",e.Events="events",e.EventNow="event-now",e.CleanEvents="clean-events",e.BeconEvent="becon-event",e.SubmitBefore="submit-before",e.SubmitScuess="submit-scuess",e.SubmitSuccess="submit-success",e.SubmitAfter="submit-after",e.SubmitError="submit-error",e.SubmitVerifyH="submit-verify-h5",e.Stay="stay",e.ResetStay="reset-stay",e.StayReady="stay-ready",e.SetStay="set-stay",e.RouteChange="route-change",e.RouteReady="route-ready",e.Ab="ab",e.AbVar="ab-var",e.AbAllVars="ab-all-vars",e.AbConfig="ab-config",e.AbExternalVersion="ab-external-version",e.AbVersionChangeOn="ab-version-change-on",e.AbVersionChangeOff="ab-version-change-off",e.AbOpenLayer="ab-open-layer",e.AbCloseLayer="ab-close-layer",e.AbReady="ab-ready",e.AbComplete="ab-complete",e.AbTimeout="ab-timeout",e.Profile="profile",e.ProfileSet="profile-set",e.ProfileSetOnce="profile-set-once",e.ProfileUnset="profile-unset",e.ProfileIncrement="profile-increment",e.ProfileAppend="profile-append",e.ProfileClear="profile-clear",e.TrackDuration="track-duration",e.TrackDurationStart="track-duration-start",e.TrackDurationEnd="track-duration-end",e.TrackDurationPause="track-duration-pause",e.TrackDurationResume="tracl-duration-resume",e.Autotrack="autotrack",e.AutotrackReady="autotrack-ready",e.CustomHeader="custom-request-header",e.TracerReady="tracer-ready"}(o||(o={})),function(e){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"}(r||(r={}));var n=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e,t){var o;o=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var o=arguments[e];for(var r in o)t[r]=o[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function o(r){function n(){}function a(t,o,a){if("undefined"!=typeof document){"number"==typeof(a=e({path:"/"},n.defaults,a)).expires&&(a.expires=new Date(1*new Date+864e5*a.expires)),a.expires=a.expires?a.expires.toUTCString():"";try{var i=JSON.stringify(o);/^[\{\[]/.test(i)&&(o=i)}catch(e){}o=r.write?r.write(o,t):encodeURIComponent(String(o)).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 s="";for(var c in a)a[c]&&(s+="; "+c,!0!==a[c]&&(s+="="+a[c].split(";")[0]));return document.cookie=t+"="+o+s}}function i(e,o){if("undefined"!=typeof document){for(var n={},a=document.cookie?document.cookie.split("; "):[],i=0;i<a.length;i++){var s=a[i].split("="),c=s.slice(1).join("=");o||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var u=t(s[0]);if(c=(r.read||r)(c,u)||t(c),o)try{c=JSON.parse(c)}catch(e){}if(n[u]=c,e===u)break}catch(e){}}return e?n[e]:n}}return n.set=a,n.get=function(e){return i(e,!1)},n.getJSON=function(e){return i(e,!0)},n.remove=function(t,o){a(t,"",e(o,{expires:-1}))},n.defaults={},n.withConverter=o,n}(function(){})},e.exports=o()}),a=function(){function e(){this.cache={}}return e.prototype.setItem=function(e,t){this.cache[e]=t},e.prototype.getItem=function(e){return this.cache[e]},e.prototype.removeItem=function(e){this.cache[e]=void 0},e}(),i=function(){function e(){this.support=this.isSupportLS()}return e.prototype.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}},e.prototype.getItem=function(e){try{var t=localStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);localStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{localStorage.removeItem(e)}catch(e){}},e}(),s=function(){function e(){this.support=this.isSupportSession()}return e.prototype.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}},e.prototype.getItem=function(e){try{var t=sessionStorage.getItem(e),o=t;try{t&&"string"==typeof t&&(o=JSON.parse(t))}catch(e){}return o||{}}catch(e){}return{}},e.prototype.setItem=function(e,t){try{var o="string"==typeof t?t:JSON.stringify(t);sessionStorage.setItem(e,o)}catch(e){}},e.prototype.removeItem=function(e){try{sessionStorage.removeItem(e)}catch(e){}},e}(),c=function(){function e(){this.defaultExpireTime=6048e5,this.local=new i,this.session=new s,this.cache=new a}return e.prototype.getLocalItem=function(e){return this.local.getItem(e)},e.prototype.setLocalItem=function(e,t){this.local.setItem(e,t)},e.prototype.removeLocalItem=function(e){this.local.removeItem(e)},e.prototype.getSessionItem=function(e){return this.session.getItem(e)},e.prototype.setSessionItem=function(e,t){this.session.setItem(e,t)},e.prototype.removeSessionItem=function(e){this.session.removeItem(e)},e.prototype.getCacheItem=function(e){return this.cache.getItem(e)},e.prototype.setCacheItem=function(e,t){this.cache.setItem(e,t)},e.prototype.removeCacheItem=function(e){this.cache.removeItem(e)},e.prototype.getCookie=function(e,t){try{return n.get(e)}catch(e){return""}},e.prototype.setCookie=function(e,t,o,r){void 0===o&&(o=this.defaultExpireTime);try{var a=r||document.domain,i=+new Date+o;n.set(e,t,{expires:new Date(i),path:"/",domain:a})}catch(e){}},e.prototype.removeCookie=function(e,t){try{n.remove(e,{path:"/",domain:t||""})}catch(e){}},e}(),u=function(){function e(){this.autotrack=!1,this.spa=!1,this.cache={},this.allowHash=!1}return e.prototype.apply=function(e,t){if(t.spa||t.autotrack){var o=e.Types;this.collect=e,this.config=t,this.appid=t.app_id,this.allowHash=t.allow_hash,this.fncArray=new Map,this.setKey(),this.setLocation(),this.hack(),this.init(),this.listener(),e.emit(o.RouteReady)}},e.prototype.setKey=function(){this.storage=new c,this.cache_key="__tea_cache_refer_"+this.appid,this.cache={refer_key:"",refer_title:document.title||location.pathname,refer_manual_key:"",routeChange:!1},this.config.autotrack&&"object"==typeof this.config.autotrack&&this.config.autotrack.page_manual_key&&(this.cache.refer_manual_key=this.config.autotrack.page_manual_key),this.storage.setLocalItem(this.cache_key,this.cache)},e.prototype.hack=function(){var e=this,o=window.history.pushState;history.pushState=function(r){for(var n=[],a=1;a<arguments.length;a++)n[a-1]=arguments[a];"function"==typeof history.onpushstate&&history.onpushstate({state:r});var i=o.call.apply(o,t([history,r],n));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.setReferCache(e.lastLocation),e.lastLocation=location.href,e.sendPv(s,"pushState"),i}};var r=history.replaceState;history.replaceState=function(o){for(var n=[],a=1;a<arguments.length;a++)n[a-1]=arguments[a];"function"==typeof history.onreplacestate&&history.onreplacestate({state:o});var i=r.call.apply(r,t([history,o],n));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.setReferCache(e.lastLocation),e.lastLocation=location.href,e.sendPv(s),i}}},e.prototype.setLocation=function(){"undefined"!=typeof window&&(this.lastLocation=window.location.href)},e.prototype.getLocation=function(){return this.lastLocation},e.prototype.init=function(){var e=this.getPopStateChangeEventData();this.collect.emit("route-change",{config:e,init:!0})},e.prototype.listener=function(){var e=this,t=null;window.addEventListener("hashchange",function(o){if(e.lastLocation!==window.location.href&&(clearTimeout(t),e.allowHash)){e.setReferCache(e.lastLocation),e.lastLocation=window.location.href;var r=e.getPopStateChangeEventData();e.sendPv(r)}}),window.addEventListener("popstate",function(o){e.lastLocation!==window.location.href&&(t=setTimeout(function(){e.setReferCache(e.lastLocation),e.lastLocation=window.location.href;var t=e.getPopStateChangeEventData();e.sendPv(t)},10))})},e.prototype.getPopStateChangeEventData=function(){var e=this.pageConfig();return e.is_back=0,e},e.prototype.pageConfig=function(){try{var e=this.storage.getLocalItem(this.cache_key)||{},t=!1,o=this.storage.getLocalItem("__tea_cache_first_"+this.appid);return t=!o||1!=o,{is_html:1,url:location.href,referrer:this.handleRefer(),page_key:location.href,refer_page_key:this.handleRefer(),page_title:document.title||location.pathname,page_manual_key:this.config.autotrack&&this.config.autotrack.page_manual_key||"",refer_page_manual_key:e&&e.refer_manual_key||"",refer_page_title:e&&e.refer_title||"",page_path:location.pathname,page_host:location.host,is_first_time:""+t}}catch(e){return this.collect.emit(r.DEBUGGER_MESSAGE,{type:r.DEBUGGER_MESSAGE_SDK,info:"发生了异常",level:"error",time:Date.now(),data:e.message}),{}}},e.prototype.sendPv=function(e,t){this.collect.emit("route-change",{config:e,init:!1})},e.prototype.handleRefer=function(){var e="";try{var t=this.storage.getLocalItem()||{};e=t.routeChange?t.refer_key:this.collect.configManager.get("referrer")}catch(t){e=document.referrer}return e},e.prototype.setReferCache=function(e){var t=this.storage.getLocalItem(this.cache_key)||{};t.refer_key=e,t.routeChange=!0,this.storage.setLocalItem(this.cache_key,t)},e}();module.exports=u;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
function __read(o, n) {
|
|
19
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
20
|
+
if (!m) return o;
|
|
21
|
+
var i = m.call(o), r, ar = [], e;
|
|
22
|
+
try {
|
|
23
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
24
|
+
}
|
|
25
|
+
catch (error) { e = { error: error }; }
|
|
26
|
+
finally {
|
|
27
|
+
try {
|
|
28
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29
|
+
}
|
|
30
|
+
finally { if (e) throw e.error; }
|
|
31
|
+
}
|
|
32
|
+
return ar;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @deprecated */
|
|
36
|
+
function __spread() {
|
|
37
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
38
|
+
ar = ar.concat(__read(arguments[i]));
|
|
39
|
+
return ar;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
48
|
+
var Types;
|
|
49
|
+
(function (Types) {
|
|
50
|
+
Types["Init"] = "init";
|
|
51
|
+
Types["Config"] = "config";
|
|
52
|
+
Types["Start"] = "start";
|
|
53
|
+
Types["Ready"] = "ready";
|
|
54
|
+
Types["TokenComplete"] = "token-complete";
|
|
55
|
+
Types["TokenStorage"] = "token-storage";
|
|
56
|
+
Types["TokenFetch"] = "token-fetch";
|
|
57
|
+
Types["TokenError"] = "token-error";
|
|
58
|
+
Types["ConfigUuid"] = "config-uuid";
|
|
59
|
+
Types["ConfigWebId"] = "config-webid";
|
|
60
|
+
Types["ConfigDomain"] = "config-domain";
|
|
61
|
+
Types["CustomWebId"] = "custom-webid";
|
|
62
|
+
Types["AnonymousId"] = "anonymous-id";
|
|
63
|
+
Types["TokenChange"] = "token-change";
|
|
64
|
+
Types["TokenReset"] = "token-reset";
|
|
65
|
+
Types["ConfigTransform"] = "config-transform";
|
|
66
|
+
Types["EnvTransform"] = "env-transform";
|
|
67
|
+
Types["SessionReset"] = "session-reset";
|
|
68
|
+
Types["SessionResetTime"] = "session-reset-time";
|
|
69
|
+
Types["Event"] = "event";
|
|
70
|
+
Types["Events"] = "events";
|
|
71
|
+
Types["EventNow"] = "event-now";
|
|
72
|
+
Types["CleanEvents"] = "clean-events";
|
|
73
|
+
Types["BeconEvent"] = "becon-event";
|
|
74
|
+
Types["SubmitBefore"] = "submit-before";
|
|
75
|
+
Types["SubmitScuess"] = "submit-scuess";
|
|
76
|
+
Types["SubmitSuccess"] = "submit-success";
|
|
77
|
+
Types["SubmitAfter"] = "submit-after";
|
|
78
|
+
Types["SubmitError"] = "submit-error";
|
|
79
|
+
Types["SubmitVerifyH"] = "submit-verify-h5";
|
|
80
|
+
Types["Stay"] = "stay";
|
|
81
|
+
Types["ResetStay"] = "reset-stay";
|
|
82
|
+
Types["StayReady"] = "stay-ready";
|
|
83
|
+
Types["SetStay"] = "set-stay";
|
|
84
|
+
Types["RouteChange"] = "route-change";
|
|
85
|
+
Types["RouteReady"] = "route-ready";
|
|
86
|
+
Types["Ab"] = "ab";
|
|
87
|
+
Types["AbVar"] = "ab-var";
|
|
88
|
+
Types["AbAllVars"] = "ab-all-vars";
|
|
89
|
+
Types["AbConfig"] = "ab-config";
|
|
90
|
+
Types["AbExternalVersion"] = "ab-external-version";
|
|
91
|
+
Types["AbVersionChangeOn"] = "ab-version-change-on";
|
|
92
|
+
Types["AbVersionChangeOff"] = "ab-version-change-off";
|
|
93
|
+
Types["AbOpenLayer"] = "ab-open-layer";
|
|
94
|
+
Types["AbCloseLayer"] = "ab-close-layer";
|
|
95
|
+
Types["AbReady"] = "ab-ready";
|
|
96
|
+
Types["AbComplete"] = "ab-complete";
|
|
97
|
+
Types["AbTimeout"] = "ab-timeout";
|
|
98
|
+
Types["Profile"] = "profile";
|
|
99
|
+
Types["ProfileSet"] = "profile-set";
|
|
100
|
+
Types["ProfileSetOnce"] = "profile-set-once";
|
|
101
|
+
Types["ProfileUnset"] = "profile-unset";
|
|
102
|
+
Types["ProfileIncrement"] = "profile-increment";
|
|
103
|
+
Types["ProfileAppend"] = "profile-append";
|
|
104
|
+
Types["ProfileClear"] = "profile-clear";
|
|
105
|
+
Types["TrackDuration"] = "track-duration";
|
|
106
|
+
Types["TrackDurationStart"] = "track-duration-start";
|
|
107
|
+
Types["TrackDurationEnd"] = "track-duration-end";
|
|
108
|
+
Types["TrackDurationPause"] = "track-duration-pause";
|
|
109
|
+
Types["TrackDurationResume"] = "tracl-duration-resume";
|
|
110
|
+
Types["Autotrack"] = "autotrack";
|
|
111
|
+
Types["AutotrackReady"] = "autotrack-ready";
|
|
112
|
+
Types["CustomHeader"] = "custom-request-header";
|
|
113
|
+
Types["TracerReady"] = "tracer-ready";
|
|
114
|
+
})(Types || (Types = {}));
|
|
115
|
+
var DebuggerMesssge;
|
|
116
|
+
(function (DebuggerMesssge) {
|
|
117
|
+
DebuggerMesssge["DEBUGGER_MESSAGE"] = "debugger-message";
|
|
118
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_SDK"] = "debugger-message-sdk";
|
|
119
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH"] = "debugger-message-fetch";
|
|
120
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_FETCH_RESULT"] = "debugger-message-fetch-result";
|
|
121
|
+
DebuggerMesssge["DEBUGGER_MESSAGE_EVENT"] = "debugger-message-event";
|
|
122
|
+
DebuggerMesssge["DEVTOOL_WEB_READY"] = "devtool-web-ready";
|
|
123
|
+
})(DebuggerMesssge || (DebuggerMesssge = {}));
|
|
124
|
+
|
|
125
|
+
function createCommonjsModule(fn, module) {
|
|
126
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var cookie = createCommonjsModule(function (module, exports) {
|
|
130
|
+
(function (factory) {
|
|
131
|
+
var registeredInModuleLoader;
|
|
132
|
+
{
|
|
133
|
+
module.exports = factory();
|
|
134
|
+
registeredInModuleLoader = true;
|
|
135
|
+
}
|
|
136
|
+
if (!registeredInModuleLoader) {
|
|
137
|
+
var OldCookies = window.Cookies;
|
|
138
|
+
var api = window.Cookies = factory();
|
|
139
|
+
api.noConflict = function () {
|
|
140
|
+
window.Cookies = OldCookies;
|
|
141
|
+
return api;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
})(function () {
|
|
145
|
+
function extend() {
|
|
146
|
+
var i = 0;
|
|
147
|
+
var result = {};
|
|
148
|
+
for (; i < arguments.length; i++) {
|
|
149
|
+
var attributes = arguments[i];
|
|
150
|
+
for (var key in attributes) {
|
|
151
|
+
result[key] = attributes[key];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function decode(s) {
|
|
157
|
+
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
|
158
|
+
}
|
|
159
|
+
function init(converter) {
|
|
160
|
+
function api() {}
|
|
161
|
+
function set(key, value, attributes) {
|
|
162
|
+
if (typeof document === 'undefined') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
attributes = extend({
|
|
166
|
+
path: '/'
|
|
167
|
+
}, api.defaults, attributes);
|
|
168
|
+
if (typeof attributes.expires === 'number') {
|
|
169
|
+
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
|
|
170
|
+
}
|
|
171
|
+
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
|
172
|
+
try {
|
|
173
|
+
var result = JSON.stringify(value);
|
|
174
|
+
if (/^[\{\[]/.test(result)) {
|
|
175
|
+
value = result;
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {}
|
|
178
|
+
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);
|
|
179
|
+
key = encodeURIComponent(String(key)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
|
|
180
|
+
var stringifiedAttributes = '';
|
|
181
|
+
for (var attributeName in attributes) {
|
|
182
|
+
if (!attributes[attributeName]) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
186
|
+
if (attributes[attributeName] === true) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
190
|
+
}
|
|
191
|
+
return document.cookie = key + '=' + value + stringifiedAttributes;
|
|
192
|
+
}
|
|
193
|
+
function get(key, json) {
|
|
194
|
+
if (typeof document === 'undefined') {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
var jar = {};
|
|
198
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
199
|
+
var i = 0;
|
|
200
|
+
for (; i < cookies.length; i++) {
|
|
201
|
+
var parts = cookies[i].split('=');
|
|
202
|
+
var cookie = parts.slice(1).join('=');
|
|
203
|
+
if (!json && cookie.charAt(0) === '"') {
|
|
204
|
+
cookie = cookie.slice(1, -1);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
var name = decode(parts[0]);
|
|
208
|
+
cookie = (converter.read || converter)(cookie, name) || decode(cookie);
|
|
209
|
+
if (json) {
|
|
210
|
+
try {
|
|
211
|
+
cookie = JSON.parse(cookie);
|
|
212
|
+
} catch (e) {}
|
|
213
|
+
}
|
|
214
|
+
jar[name] = cookie;
|
|
215
|
+
if (key === name) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
} catch (e) {}
|
|
219
|
+
}
|
|
220
|
+
return key ? jar[key] : jar;
|
|
221
|
+
}
|
|
222
|
+
api.set = set;
|
|
223
|
+
api.get = function (key) {
|
|
224
|
+
return get(key, false );
|
|
225
|
+
};
|
|
226
|
+
api.getJSON = function (key) {
|
|
227
|
+
return get(key, true );
|
|
228
|
+
};
|
|
229
|
+
api.remove = function (key, attributes) {
|
|
230
|
+
set(key, '', extend(attributes, {
|
|
231
|
+
expires: -1
|
|
232
|
+
}));
|
|
233
|
+
};
|
|
234
|
+
api.defaults = {};
|
|
235
|
+
api.withConverter = init;
|
|
236
|
+
return api;
|
|
237
|
+
}
|
|
238
|
+
return init(function () {});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
|
|
243
|
+
/**
|
|
244
|
+
* cacheStorage
|
|
245
|
+
*/
|
|
246
|
+
var Memory = /** @class */function () {
|
|
247
|
+
function Memory() {
|
|
248
|
+
this.cache = {};
|
|
249
|
+
}
|
|
250
|
+
Memory.prototype.setItem = function (cacheKey, data) {
|
|
251
|
+
this.cache[cacheKey] = data;
|
|
252
|
+
};
|
|
253
|
+
Memory.prototype.getItem = function (cacheKey) {
|
|
254
|
+
return this.cache[cacheKey];
|
|
255
|
+
};
|
|
256
|
+
Memory.prototype.removeItem = function (cacheKey) {
|
|
257
|
+
this.cache[cacheKey] = undefined;
|
|
258
|
+
};
|
|
259
|
+
return Memory;
|
|
260
|
+
}();
|
|
261
|
+
/**
|
|
262
|
+
* localStorage
|
|
263
|
+
*/
|
|
264
|
+
var Local = /** @class */function () {
|
|
265
|
+
function Local() {
|
|
266
|
+
this.support = this.isSupportLS();
|
|
267
|
+
}
|
|
268
|
+
Local.prototype.isSupportLS = function () {
|
|
269
|
+
try {
|
|
270
|
+
localStorage.setItem('_applogtest-test-key', 'hi');
|
|
271
|
+
localStorage.getItem('_applogtest-test-key');
|
|
272
|
+
localStorage.removeItem('_applogtest-test-key');
|
|
273
|
+
return true;
|
|
274
|
+
} catch (e) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
Local.prototype.getItem = function (key) {
|
|
279
|
+
try {
|
|
280
|
+
var value = localStorage.getItem(key);
|
|
281
|
+
var ret = value;
|
|
282
|
+
try {
|
|
283
|
+
if (value && typeof value === 'string') {
|
|
284
|
+
ret = JSON.parse(value);
|
|
285
|
+
}
|
|
286
|
+
} catch (e) {}
|
|
287
|
+
return ret || {};
|
|
288
|
+
} catch (e) {}
|
|
289
|
+
return {};
|
|
290
|
+
};
|
|
291
|
+
Local.prototype.setItem = function (key, value) {
|
|
292
|
+
try {
|
|
293
|
+
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
294
|
+
localStorage.setItem(key, stringValue);
|
|
295
|
+
} catch (e) {}
|
|
296
|
+
};
|
|
297
|
+
Local.prototype.removeItem = function (key) {
|
|
298
|
+
try {
|
|
299
|
+
localStorage.removeItem(key);
|
|
300
|
+
} catch (e) {}
|
|
301
|
+
};
|
|
302
|
+
return Local;
|
|
303
|
+
}();
|
|
304
|
+
/**
|
|
305
|
+
* sessionStorage
|
|
306
|
+
*/
|
|
307
|
+
var Session = /** @class */function () {
|
|
308
|
+
function Session() {
|
|
309
|
+
this.support = this.isSupportSession();
|
|
310
|
+
}
|
|
311
|
+
Session.prototype.isSupportSession = function () {
|
|
312
|
+
try {
|
|
313
|
+
sessionStorage.setItem('_applogtest-test-key', 'hi');
|
|
314
|
+
sessionStorage.getItem('_applogtest-test-key');
|
|
315
|
+
sessionStorage.removeItem('_applogtest-test-key');
|
|
316
|
+
return true;
|
|
317
|
+
} catch (e) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
Session.prototype.getItem = function (key) {
|
|
322
|
+
try {
|
|
323
|
+
var value = sessionStorage.getItem(key);
|
|
324
|
+
var ret = value;
|
|
325
|
+
try {
|
|
326
|
+
if (value && typeof value === 'string') {
|
|
327
|
+
ret = JSON.parse(value);
|
|
328
|
+
}
|
|
329
|
+
} catch (e) {}
|
|
330
|
+
return ret || {};
|
|
331
|
+
} catch (e) {}
|
|
332
|
+
return {};
|
|
333
|
+
};
|
|
334
|
+
Session.prototype.setItem = function (key, value) {
|
|
335
|
+
try {
|
|
336
|
+
var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
337
|
+
sessionStorage.setItem(key, stringValue);
|
|
338
|
+
} catch (e) {}
|
|
339
|
+
};
|
|
340
|
+
Session.prototype.removeItem = function (key) {
|
|
341
|
+
try {
|
|
342
|
+
sessionStorage.removeItem(key);
|
|
343
|
+
} catch (e) {}
|
|
344
|
+
};
|
|
345
|
+
return Session;
|
|
346
|
+
}();
|
|
347
|
+
var StorageManager = /** @class */function () {
|
|
348
|
+
function StorageManager() {
|
|
349
|
+
this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
|
|
350
|
+
this.local = new Local();
|
|
351
|
+
this.session = new Session();
|
|
352
|
+
this.cache = new Memory();
|
|
353
|
+
}
|
|
354
|
+
StorageManager.prototype.getLocalItem = function (key) {
|
|
355
|
+
return this.local.getItem(key);
|
|
356
|
+
};
|
|
357
|
+
StorageManager.prototype.setLocalItem = function (key, value) {
|
|
358
|
+
this.local.setItem(key, value);
|
|
359
|
+
};
|
|
360
|
+
StorageManager.prototype.removeLocalItem = function (key) {
|
|
361
|
+
this.local.removeItem(key);
|
|
362
|
+
};
|
|
363
|
+
StorageManager.prototype.getSessionItem = function (key) {
|
|
364
|
+
return this.session.getItem(key);
|
|
365
|
+
};
|
|
366
|
+
StorageManager.prototype.setSessionItem = function (key, value) {
|
|
367
|
+
this.session.setItem(key, value);
|
|
368
|
+
};
|
|
369
|
+
StorageManager.prototype.removeSessionItem = function (key) {
|
|
370
|
+
this.session.removeItem(key);
|
|
371
|
+
};
|
|
372
|
+
StorageManager.prototype.getCacheItem = function (key) {
|
|
373
|
+
return this.cache.getItem(key);
|
|
374
|
+
};
|
|
375
|
+
StorageManager.prototype.setCacheItem = function (key, value) {
|
|
376
|
+
this.cache.setItem(key, value);
|
|
377
|
+
};
|
|
378
|
+
StorageManager.prototype.removeCacheItem = function (key) {
|
|
379
|
+
this.cache.removeItem(key);
|
|
380
|
+
};
|
|
381
|
+
StorageManager.prototype.getCookie = function (key, domain) {
|
|
382
|
+
try {
|
|
383
|
+
// const _matches = Cookies.get(name, { domain: domain || document.domain })
|
|
384
|
+
var _matches = cookie.get(key);
|
|
385
|
+
return _matches;
|
|
386
|
+
} catch (e) {
|
|
387
|
+
return '';
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
|
|
391
|
+
if (expiresTime === void 0) {
|
|
392
|
+
expiresTime = this.defaultExpireTime;
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
var _domain = domain || document.domain;
|
|
396
|
+
var timestamp = +new Date();
|
|
397
|
+
var furureTimestamp = timestamp + expiresTime;
|
|
398
|
+
cookie.set(key, value, {
|
|
399
|
+
expires: new Date(furureTimestamp),
|
|
400
|
+
path: '/',
|
|
401
|
+
domain: _domain
|
|
402
|
+
});
|
|
403
|
+
} catch (e) {}
|
|
404
|
+
};
|
|
405
|
+
StorageManager.prototype.removeCookie = function (key, domain) {
|
|
406
|
+
try {
|
|
407
|
+
cookie.remove(key, {
|
|
408
|
+
path: '/',
|
|
409
|
+
domain: domain || ''
|
|
410
|
+
});
|
|
411
|
+
} catch (e) {}
|
|
412
|
+
};
|
|
413
|
+
return StorageManager;
|
|
414
|
+
}();
|
|
415
|
+
|
|
416
|
+
var RuotePage = /** @class */function () {
|
|
417
|
+
function RuotePage() {
|
|
418
|
+
this.autotrack = false;
|
|
419
|
+
this.spa = false;
|
|
420
|
+
this.cache = {};
|
|
421
|
+
this.allowHash = false;
|
|
422
|
+
}
|
|
423
|
+
RuotePage.prototype.apply = function (collect, config) {
|
|
424
|
+
if (!config.spa && !config.autotrack) return;
|
|
425
|
+
var Types = collect.Types;
|
|
426
|
+
this.collect = collect;
|
|
427
|
+
this.config = config;
|
|
428
|
+
this.appid = config.app_id;
|
|
429
|
+
this.allowHash = config.allow_hash;
|
|
430
|
+
this.fncArray = new Map();
|
|
431
|
+
this.setKey();
|
|
432
|
+
this.setLocation();
|
|
433
|
+
this.hack();
|
|
434
|
+
this.init();
|
|
435
|
+
this.listener();
|
|
436
|
+
collect.emit(Types.RouteReady);
|
|
437
|
+
};
|
|
438
|
+
RuotePage.prototype.setKey = function () {
|
|
439
|
+
this.storage = new StorageManager();
|
|
440
|
+
this.cache_key = "__tea_cache_refer_" + this.appid;
|
|
441
|
+
this.cache = {
|
|
442
|
+
refer_key: '',
|
|
443
|
+
refer_title: document.title || location.pathname,
|
|
444
|
+
refer_manual_key: '',
|
|
445
|
+
routeChange: false
|
|
446
|
+
};
|
|
447
|
+
if (this.config.autotrack && typeof this.config.autotrack === 'object' && this.config.autotrack.page_manual_key) {
|
|
448
|
+
this.cache.refer_manual_key = this.config.autotrack.page_manual_key;
|
|
449
|
+
}
|
|
450
|
+
this.storage.setLocalItem(this.cache_key, this.cache);
|
|
451
|
+
};
|
|
452
|
+
RuotePage.prototype.hack = function () {
|
|
453
|
+
var _this = this;
|
|
454
|
+
var oldPushState = window.history.pushState;
|
|
455
|
+
history.pushState = function (state) {
|
|
456
|
+
var args = [];
|
|
457
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
458
|
+
args[_i - 1] = arguments[_i];
|
|
459
|
+
}
|
|
460
|
+
if (typeof history['onpushstate'] === 'function') {
|
|
461
|
+
history['onpushstate']({
|
|
462
|
+
state: state
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
var ret = oldPushState.call.apply(oldPushState, __spread([history, state], args));
|
|
466
|
+
if (_this.lastLocation === location.href) return;
|
|
467
|
+
var config = _this.getPopStateChangeEventData();
|
|
468
|
+
_this.setReferCache(_this.lastLocation);
|
|
469
|
+
_this.lastLocation = location.href;
|
|
470
|
+
_this.sendPv(config, 'pushState');
|
|
471
|
+
return ret;
|
|
472
|
+
};
|
|
473
|
+
var oldReplaceState = history.replaceState;
|
|
474
|
+
history.replaceState = function (state) {
|
|
475
|
+
var args = [];
|
|
476
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
477
|
+
args[_i - 1] = arguments[_i];
|
|
478
|
+
}
|
|
479
|
+
if (typeof history['onreplacestate'] === 'function') {
|
|
480
|
+
history['onreplacestate']({
|
|
481
|
+
state: state
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
var ret = oldReplaceState.call.apply(oldReplaceState, __spread([history, state], args));
|
|
485
|
+
if (_this.lastLocation === location.href) return;
|
|
486
|
+
var config = _this.getPopStateChangeEventData();
|
|
487
|
+
_this.setReferCache(_this.lastLocation);
|
|
488
|
+
_this.lastLocation = location.href;
|
|
489
|
+
_this.sendPv(config);
|
|
490
|
+
return ret;
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
RuotePage.prototype.setLocation = function () {
|
|
494
|
+
if (typeof window !== 'undefined') {
|
|
495
|
+
this.lastLocation = window.location.href;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
RuotePage.prototype.getLocation = function () {
|
|
499
|
+
return this.lastLocation;
|
|
500
|
+
};
|
|
501
|
+
RuotePage.prototype.init = function () {
|
|
502
|
+
var config = this.getPopStateChangeEventData();
|
|
503
|
+
this.collect.emit('route-change', {
|
|
504
|
+
config: config,
|
|
505
|
+
init: true
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
RuotePage.prototype.listener = function () {
|
|
509
|
+
var _this = this;
|
|
510
|
+
var timeoutId = null;
|
|
511
|
+
var time = 10;
|
|
512
|
+
window.addEventListener('hashchange', function (e) {
|
|
513
|
+
if (_this.lastLocation === window.location.href) return;
|
|
514
|
+
clearTimeout(timeoutId);
|
|
515
|
+
if (_this.allowHash) {
|
|
516
|
+
// 如果允许hashTag,就执行回调函数
|
|
517
|
+
_this.setReferCache(_this.lastLocation);
|
|
518
|
+
_this.lastLocation = window.location.href;
|
|
519
|
+
var config = _this.getPopStateChangeEventData();
|
|
520
|
+
_this.sendPv(config);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
window.addEventListener('popstate', function (e) {
|
|
524
|
+
if (_this.lastLocation === window.location.href) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
timeoutId = setTimeout(function () {
|
|
528
|
+
_this.setReferCache(_this.lastLocation);
|
|
529
|
+
_this.lastLocation = window.location.href;
|
|
530
|
+
var config = _this.getPopStateChangeEventData();
|
|
531
|
+
_this.sendPv(config);
|
|
532
|
+
}, time);
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
RuotePage.prototype.getPopStateChangeEventData = function () {
|
|
536
|
+
var config = this.pageConfig();
|
|
537
|
+
config['is_back'] = 0;
|
|
538
|
+
return config;
|
|
539
|
+
};
|
|
540
|
+
RuotePage.prototype.pageConfig = function () {
|
|
541
|
+
try {
|
|
542
|
+
var cache_local = this.storage.getLocalItem(this.cache_key) || {};
|
|
543
|
+
var is_first_time = false;
|
|
544
|
+
var firstStatus = this.storage.getLocalItem("__tea_cache_first_" + this.appid);
|
|
545
|
+
if (firstStatus && firstStatus == 1) {
|
|
546
|
+
is_first_time = false;
|
|
547
|
+
} else {
|
|
548
|
+
is_first_time = true;
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
is_html: 1,
|
|
552
|
+
url: location.href,
|
|
553
|
+
referrer: this.handleRefer(),
|
|
554
|
+
page_key: location.href,
|
|
555
|
+
refer_page_key: this.handleRefer(),
|
|
556
|
+
page_title: document.title || location.pathname,
|
|
557
|
+
page_manual_key: this.config.autotrack && this.config.autotrack.page_manual_key || '',
|
|
558
|
+
refer_page_manual_key: cache_local && cache_local.refer_manual_key || '',
|
|
559
|
+
refer_page_title: cache_local && cache_local.refer_title || '',
|
|
560
|
+
page_path: location.pathname,
|
|
561
|
+
page_host: location.host,
|
|
562
|
+
is_first_time: "" + is_first_time
|
|
563
|
+
};
|
|
564
|
+
} catch (e) {
|
|
565
|
+
this.collect.emit(DebuggerMesssge.DEBUGGER_MESSAGE, {
|
|
566
|
+
type: DebuggerMesssge.DEBUGGER_MESSAGE_SDK,
|
|
567
|
+
info: '发生了异常',
|
|
568
|
+
level: 'error',
|
|
569
|
+
time: Date.now(),
|
|
570
|
+
data: e.message
|
|
571
|
+
});
|
|
572
|
+
return {};
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
RuotePage.prototype.sendPv = function (config, name) {
|
|
576
|
+
this.collect.emit('route-change', {
|
|
577
|
+
config: config,
|
|
578
|
+
init: false
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
RuotePage.prototype.handleRefer = function () {
|
|
582
|
+
var refer = '';
|
|
583
|
+
try {
|
|
584
|
+
var cache_local = this.storage.getLocalItem() || {};
|
|
585
|
+
if (cache_local.routeChange) {
|
|
586
|
+
// 已经发生路由变化
|
|
587
|
+
refer = cache_local.refer_key;
|
|
588
|
+
} else {
|
|
589
|
+
// 首页,用浏览器的refer
|
|
590
|
+
refer = this.collect.configManager.get('referrer');
|
|
591
|
+
}
|
|
592
|
+
} catch (e) {
|
|
593
|
+
refer = document.referrer;
|
|
594
|
+
}
|
|
595
|
+
return refer;
|
|
596
|
+
};
|
|
597
|
+
RuotePage.prototype.setReferCache = function (url) {
|
|
598
|
+
var cache_local = this.storage.getLocalItem(this.cache_key) || {};
|
|
599
|
+
cache_local.refer_key = url;
|
|
600
|
+
// 不再是第一次进入页面
|
|
601
|
+
cache_local.routeChange = true;
|
|
602
|
+
this.storage.setLocalItem(this.cache_key, cache_local);
|
|
603
|
+
};
|
|
604
|
+
return RuotePage;
|
|
605
|
+
}();
|
|
606
|
+
|
|
607
|
+
module.exports = RuotePage;
|