@datarangers/sdk-javascript 0.0.5-lite → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -11
- package/es/index-base.min.js +1 -0
- package/es/index.min.js +1 -1
- package/es/plugin/ab.js +1 -0
- package/es/plugin/autotrack.js +1 -0
- package/es/plugin/duration.js +1 -0
- package/es/plugin/route.js +1 -0
- package/es/plugin/stay.js +1 -0
- package/es/plugin/store.js +1 -0
- package/lib/index-base.min.js +1 -0
- package/lib/index.min.js +1 -1
- package/lib/plugin/ab.js +1 -0
- package/lib/plugin/autotrack.js +1 -0
- package/lib/plugin/duration.js +1 -0
- package/lib/plugin/route.js +1 -0
- package/lib/plugin/stay.js +1 -0
- package/lib/plugin/store.js +1 -0
- package/package.json +3 -2
- package/types/types.d.ts +150 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=function(e){return Array.isArray(e)};Date.now(),Number((""+Math.random()).slice(2,8));function n(e,t){if(void 0===t&&(t="list"),!e)return!1;if(t&&"list"===t){if(["LI","TR","DL"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaIdx"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-idx"))return!0}else{if(["A","BUTTON"].includes(e.nodeName))return!0;if(e.dataset&&e.dataset.hasOwnProperty("teaContainer"))return!0;if(e.hasAttribute&&e.hasAttribute("data-tea-container"))return!0;if(e.hasAttribute&&s(e,"ss"))return!0}return!1}var i=function(e,t){return!!s(e,t)};function o(e){for(var t=e;t&&!n(t,"container");){if("HTML"===t.nodeName||"BODY"===t.nodeName)return e;t=t.parentElement}return t||e}function r(e){var t="";return 3===e.nodeType?t=e.textContent.trim():e.dataset&&e.dataset.hasOwnProperty("teaTitle")||e.hasAttribute("ata-tea-title")?t=e.getAttribute("data-tea-title"):e.hasAttribute("title")?t=e.getAttribute("title"):"INPUT"===e.nodeName&&["button","submit"].includes(e.getAttribute("type"))?t=e.getAttribute("value"):"IMG"===e.nodeName&&e.getAttribute("alt")&&(t=e.getAttribute("alt")),t.slice(0,200)}var a=function(e,t){return e.hasAttribute?e.hasAttribute(t):e.attributes?!(!e.attributes[t]||!e.attributes[t].specified):void 0},s=function(e,n){if("string"==typeof n)return a(e,n);if(t(n)){for(var i=!1,o=0;o<n.length;o++){if(a(e,n[o])){i=!0;break}}return i}};var c=function(){function t(t,o,r){var a=this;this.clickEvent=function(e){(function(e,t){if(1!==e.nodeType)return!1;if(!t.svg&&function(e){if("svg"===e.tagName.toLowerCase())return!0;for(var t=e.parentElement,n=!1;t;)"svg"===t.tagName.toLowerCase()?(t=null,n=!0):t=t.parentElement;return n}(e))return!1;if(["HTML","BODY"].includes(e.tagName.toUpperCase()))return!1;var o=e;return!!("none"!==o.style.display&&(n(o,"container")||t.track_attr&&i(o,t.track_attr)||function(e){if(e.children.length){var t=e.children;return![].slice.call(t).some((function(e){return e.children.length>0}))}return!0}(o)))})(e.target,a.options)&&a.eventHandel({eventType:"dom",eventName:"click"},e)},this.changeEvent=function(e){a.eventHandel({eventType:"dom",eventName:"change"},e)},this.submitEvent=function(e){a.eventHandel({eventType:"dom",eventName:"submit"},e)},this.getPageViewEvent=function(t,n){n&&"pushState"===n&&a.eventHandel({eventType:"dom",eventName:"beat"},e({beat_type:0},t)),a.eventHandel({eventType:"dom",eventName:"page_view"},t)},this.getPageLoadEvent=function(e){a.eventHandel({eventType:"dom",eventName:"page_statistics"},{lcp:e})},this.config=r.getConfig().eventConfig,this.collect=o,this.options=t,this.beatTime=t.beat,this.statistics=!1}return t.prototype.init=function(e){this.eventHandel=e;var t=this.config.mode;this.addListener(t)},t.prototype.addListener=function(e){var t=this;if("proxy-capturing"===e&&(this.config.click&&window.document.addEventListener("click",this.clickEvent,!0),this.config.change&&window.document.addEventListener("change",this.changeEvent,!0),this.config.submit&&window.document.addEventListener("submit",this.submitEvent,!0),this.config.pv&&this.collect.on("route-change",(function(e){var n=e.config,i=e.name;t.getPageViewEvent(n,i)})),this.config.beat)){try{"complete"===document.readyState?this.beatEvent(this.beatTime):window.addEventListener("load",(function(){t.beatEvent(t.beatTime)}));var n=0,i=null;window.addEventListener("scroll",(function(){clearTimeout(i),i=setTimeout(o,500),n=document.documentElement.scrollTop||document.body.scrollTop}));var o=function(){(document.documentElement.scrollTop||document.body.scrollTop)==n&&t.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:1})}}catch(e){}try{var r=window.performance&&window.performance.getEntriesByType("paint");if(r&&r.length){var a=new PerformanceObserver((function(e){var n=e.getEntries(),i=n[n.length-1],o=i.renderTime||i.loadTime;t.statistics||(t.getPageLoadEvent(o),t.statistics=!0)}));a.observe({entryTypes:["largest-contentful-paint"]}),setTimeout((function(){t.statistics||(t.getPageLoadEvent(r[0].startTime||0),t.statistics=!0)}),2e3)}else this.getPageLoadEvent(0)}catch(e){this.getPageLoadEvent(0)}}},t.prototype.removeListener=function(){window.document.removeEventListener("click",this.clickEvent,!0),window.document.removeEventListener("change",this.changeEvent,!0),window.document.removeEventListener("submit",this.submitEvent,!0)},t.prototype.beatEvent=function(e){var t,n=this;try{var i;this.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:3}),this.beatTime&&(i=setInterval((function(){n.eventHandel({eventType:"dom",eventName:"beat"},{beat_type:2})}),e)),t=function(){n.eventHandel({eventType:"dom",eventName:"beat",eventSend:"becon"},{beat_type:0}),n.beatTime&&clearInterval(i)},navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?window.addEventListener("pagehide",t,!1):window.addEventListener("beforeunload",t,!1)}catch(e){}},t}(),u={eventConfig:{mode:"proxy-capturing",submit:!1,click:!0,change:!1,pv:!0,beat:!0,hashTag:!1,impr:!1},scoutConfig:{mode:"xpath"}},d=function(){function e(e,t){this.config=e,this.config.eventConfig=Object.assign(this.config.eventConfig,t)}return e.prototype.getConfig=function(){return this.config},e.prototype.setConfig=function(e){return this.config=e},e}();function l(e){for(var t=[];null!==e.parentElement;)t.push(e),e=e.parentElement;var i=[],o=[];return t.forEach((function(e){var t=function(e){if(null===e)return{str:"",index:0};var t=0,i=e.parentElement;if(i)for(var o=i.children,r=0;r<o.length&&o[r]!==e;r++)o[r].nodeName===e.nodeName&&t++;return{str:[e.nodeName.toLowerCase(),n(e,"list")?"[]":""].join(""),index:t}}(e),r=t.str,a=t.index;i.unshift(r),o.unshift(a)})),{element_path:"/"+i.join("/"),positions:o}}function p(e,n,s,c){var u={},d=function(e){if(e){var t=e.getBoundingClientRect(),n=t.width,i=t.height;return{left:t.left,top:t.top,element_width:n,element_height:i}}}(n),p=function(e,t){void 0===e&&(e={}),void 0===t&&(t={});var n=e.clientX,i=e.clientY,o=t.left,r=t.top,a=n-o>=0?n-o:0,s=i-r>=0?i-r:0;return{touch_x:Math.floor(a),touch_y:Math.floor(s)}}(e,d),h=d.element_width,v=d.element_height,f=p.touch_x,g=p.touch_y,m=l(n),_=m.element_path,b=m.positions,y=function(e){var t=o(e),n=[];return function e(t){var i=r(t);if(i&&-1===n.indexOf(i)&&n.push(i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)8!==o[a].nodeType&&e(o[a])}(t),n}(n),w=window.performance.timing.navigationStart,E=Date.now()-w,T=b.map((function(e){return""+e})),x=null;if(window.TEAVisualEditor.getOriginXpath&&(x=window.TEAVisualEditor.getOriginXpath({xpath:_,positions:T})),u.element_path=x&&x.xpath||_,u.positions=x&&x.positions||T,c&&!c.text&&(u.texts=y,u.element_title=function(e){var t=o(e),n="";return function e(t){var i=r(t);if(i&&(n+=i),t.childNodes.length>0)for(var o=t.childNodes,a=0;a<o.length;a++)3===o[a].nodeType&&e(o[a])}(t),n}(n)),u.element_id=n.getAttribute("id")||"",u.element_class_name=n.getAttribute("class")||"",u.element_type=n.nodeType,u.element_width=Math.floor(h),u.element_height=Math.floor(v),u.touch_x=f,u.touch_y=g,u.page_manual_key="",u.elememt_manual_key="",u.since_page_start_ms=E,u.page_start_ms=w,u.page_path=location.pathname,u.page_host=location.host,s.track_attr&&i(n,s.track_attr)){var A=function(e,n){var i={};if("string"==typeof n)a(e,n)&&(i.attrs=e.getAttribute(n));else if(t(n))for(var o=0;o<n.length;o++)a(e,n[o])&&(i[n[o]]=e.getAttribute(n[o]));return i}(n,s.track_attr);for(var k in A)u[k]=A[k]}var N=o(n);return"A"===N.tagName&&(u.href=N.getAttribute("href")),"IMG"===n.tagName&&(u.src=n.getAttribute("src")),u}var h=function(t,n,i,o,r){return e({event:t},p(n,i,o,r),{is_html:1,page_key:window.location.href,page_title:document.title})},v=function(){function t(e,t){this.ignore={text:!1},this.initConfig=e,this.options=t,this.eventName=t&&"tea"===t.custom?{click:"__bav_click",page:"__bav_page",beat:"__bav_beat",static:"__bav_page_statistics",exposure:"__bav_page_exposure"}:{click:"bav2b_click",page:"bav2b_page",beat:"bav2b_beat",static:"bav2b_page_statistics",exposure:"bav2b_exposure"},t&&!1===t.text&&(this.ignore.text=!0),t&&t.exposure&&t.exposure.eventName&&(this.eventName.exposure=t.exposure.eventName)}return t.prototype.handleEvent=function(t,n){try{if(function(e){for(var t=e;t&&t.parentNode;){if(t.hasAttribute("data-tea-ignore"))return!0;if("HTML"===t.nodeName||"body"===t.nodeName)return!1;t=t.parentNode}return!1}(t.target))return null;var i="bav2b_click";switch(n){case"click":return i=this.eventName.click,h(i,t,t.target,this.options,this.ignore);case"exposure":return i=this.eventName.exposure,h(i,t,t.target,this.options,this.ignore);case"change":return e({},h(i="bav2b_change",t,t.target,this.options),function(e,t){try{if("bav2b_change"===e)return t.hasAttribute("data-tea-track")?{value:t.value}:{}}catch(e){return{}}}(i,t.target));case"submit":return h(i="bav2b_submit",t,t.target,this.options)}}catch(e){return console.error(e),null}},t.prototype.handleViewEvent=function(e){e.event=this.eventName.page,e.page_title=document.title,e.page_total_width=window.innerWidth,e.page_total_height=window.innerHeight;try{var t=window.sessionStorage.getItem("_tea_cache_duration");if(t){var n=JSON.parse(t);e.refer_page_duration_ms=n?n.duration:""}e.scroll_width=document.documentElement.scrollLeft?document.documentElement.scrollLeft+window.innerWidth:window.innerWidth,e.scroll_height=document.documentElement.scrollTop?document.documentElement.scrollTop+window.innerHeight:window.innerHeight,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("page event error "+JSON.stringify(e))}return e},t.prototype.handleStatisticsEvent=function(e){var t={};t.event=this.eventName.static,t.is_html=1,t.page_key=location.href,t.refer_page_key=document.referrer||"",t.page_title=document.title,t.page_manual_key=this.initConfig.autotrack.page_manual_key||"",t.refer_page_manual_key="";try{var n=e.lcp,i=window.performance.timing,o=i.loadEventEnd-i.navigationStart;t.page_init_cost_ms=parseInt(n||(o>0?o:0)),t.page_start_ms=i.navigationStart}catch(e){console.log("page_statistics event error "+JSON.stringify(e))}return t},t.prototype.handleBeadtEvent=function(e){e.event=this.eventName.beat,e.page_key=window.location.href,e.is_html=1,e.page_title=document.title,e.page_manual_key=this.initConfig.autotrack.page_manual_key||"";try{e.page_viewport_width=window.innerWidth,e.page_viewport_height=window.innerHeight,e.page_total_width=document.documentElement.scrollWidth,e.page_total_height=document.documentElement.scrollHeight,e.scroll_width=document.documentElement.scrollLeft+window.innerWidth,e.scroll_height=document.documentElement.scrollTop+window.innerHeight,e.since_page_start_ms=Date.now()-window.performance.timing.navigationStart,e.page_start_ms=window.performance.timing.navigationStart}catch(e){console.log("beat event error "+JSON.stringify(e))}return e},t}(),f=function(){function e(e){this.collect=e,this.eventNameList=["report_click_event","report_change_event","report_submit_event","report_exposure_event","report_page_view_event","report_page_statistics_event","report_beat_event"]}return e.prototype.send=function(e,t){var n=e.eventSend,i=t.event;delete t.event,n&&"becon"===n?this.collect.beconEvent(i,t):this.collect.event(i,t)},e.prototype.get=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"GET"},t);fetch(e,n)},e.prototype.post=function(e,t){var n=Object.assign({headers:{"content-type":"application/json"},method:"POST"},t);fetch(e,n)},e}(),g={},m=[];function _(e,t,n,i){var o=e&&e.source||window.opener||window.parent,r=e&&e.origin||i||"*",a={type:t,payload:n};o.postMessage(JSON.stringify(a),r)}function b(e,t){g[e]=g[e]||[],g[e].push(t)}function y(e){if(m.some((function(e){return"*"===e}))||m.some((function(t){return e.origin===t}))){var t=e.data;if("string"==typeof e.data)try{t=JSON.parse(e.data)}catch(e){t=void 0}if(!t)return;var n=t.type,i=t.payload;g[n]&&g[n].forEach((function(t){"function"==typeof t&&t(e,i)}))}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var w=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){e.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)e[i]=n[i]}return e}function t(n,i){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=e({},i,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var s in r)r[s]&&(a+="; "+s,!0!==r[s]&&(a+="="+r[s].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+a}}function r(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],i={},o=0;o<t.length;o++){var r=t[o].split("="),a=r.slice(1).join("=");try{var s=decodeURIComponent(r[0]);if(i[s]=n.read(a,s),e===s)break}catch(e){}}return e?i[e]:i}}return Object.create({set:o,get:r,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}()})),E=w;function T(){try{var e=window.TEAVisualEditor.lang=window.TEAVisualEditor.lang||E.get("lang"),t=window.TEAVisualEditor.__editor_ajax_domain=window.TEAVisualEditor.__editor_ajax_domain||E.get("_TEA_VE_APIHOST"),n=window.TEAVisualEditor.__editor_verison=window.TEAVisualEditor.__editor_verison||E.get("_VISUAL_EDITOR_V"),i=window.TEAVisualEditor.__editor_url=window.TEAVisualEditor.__editor_url||E.get("_VISUAL_EDITOR_U"),o=+new Date,r=new Date(o+18e5);E.set("_TEA_VE_OPEN","1",{expires:r}),E.set("_TEA_VE_APIHOST",t,{expires:r}),E.set("_VISUAL_EDITOR_U",i,{expires:r}),E.set("lang",e,{expires:r}),E.set("_VISUAL_EDITOR_V",n||"",{expires:r})}catch(e){console.log("set cookie err")}}var x=!1;function A(e){var t,n,i,o,r=e.event,a=e.editorUrl,s=e.autoTrackInstance;x||(x=!0,t=a,n=function(){_(r,"editorScriptloadSuccess"),s.destroy()},i=function(){r&&_(r,"editorScriptloadError"),x=!1},(o=document.createElement("script")).src=t,o.onerror=function(){i(t)},o.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(o))}function k(t,n){window.TEAVisualEditor=window.TEAVisualEditor||{};var i="",o="https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/visual-editor-rangers.js?query="+Date.now();window.TEAVisualEditor.appId=n.app_id;var r,a,s,c=n.channel_domain,u="";if((r=["*"]).length&&r.forEach((function(e){m.push(e)})),c){var d,l="";try{var p=window.performance.getEntriesByType("resource");if(p&&p.length&&(p.forEach((function(e){"script"===e.initiatorType&&e.name&&-1!==e.name.indexOf("collect")&&(l=e.name)})),l||document.currentScript&&(l=document.currentScript.src),l&&(d=l.split("/"))&&d.length)){u="https:/";for(var h=2;h<d.length&&h!==d.length-1;h++)u=u+"/"+d[h];if(u&&u.indexOf("/5.0")){var v=u.split("/5.0");u=v[0]||u}}}catch(e){}}if(a="0.0.6",(s=e({},n)).filter&&delete s.filter,"object"==typeof s.autotrack&&s.autotrack.collect_url&&delete s.autotrack.collect_url,(window.opener||window.parent).postMessage({type:"tea:sdk:info",config:s,version:a},"*"),window.addEventListener("message",y,!1),"1"===E.get("_TEA_VE_OPEN")){var f=function(){var e=E.get("_TEA_VE_APIHOST");try{e=JSON.parse(e)}catch(e){}return e}(),g="";f&&(window.TEAVisualEditor.__editor_ajax_domain=f,g=E.get("_VISUAL_EDITOR_U")),A({event:null,editorUrl:g||o,autoTrackInstance:t}),T()}else try{b("tea:openVisualEditor",(function(e){var n=e.data;if("string"==typeof e.data)try{n=JSON.parse(e.data)}catch(e){n=void 0}if(n){var r=n.referrer,a=n.lang;if(r&&(window.TEAVisualEditor.__editor_ajax_domain=r),i=o,c){var s=n.version;i=u?""+u+(s?"/visual-editor-rangers-v"+s:"/visual-editor-rangers-v1.0.0")+".js":o,window.TEAVisualEditor.__editor_verison=s}window.TEAVisualEditor.__editor_url=i,window.TEAVisualEditor.lang=a,A({event:e,editorUrl:i,autoTrackInstance:t}),T()}})),window.TEAVisualEditor.openAutotrackEditor=function(){A({event:null,editorUrl:window.TEAVisualEditor.__editor_url,autoTrackInstance:t})}}catch(e){console.log("receive message error")}try{b("tea:openHeatMapCore",(function(e){A({event:e,editorUrl:"https://lf3-data.volccdn.com/obj/data-static/log-sdk/collect/heatmap-core.js?query="+Date.now(),autoTrackInstance:t})}))}catch(e){console.log("openHeatMapCore error")}}var N=function(){function e(e){this._instance=null,this._intersection=e,this._intersection&&this.init()}return e.prototype.init=function(){var e=this;MutationObserver?(this._instance=new MutationObserver((function(t){t.forEach((function(t){"attributes"===t.type&&e.attributeChangeObserve(t),"childList"===t.type&&e.modifyNodeObserve(t)}))})),this._instance.observe(document.body,{childList:!0,attributes:!0,subtree:!0,attributeOldValue:!1})):console.log("your browser cannot support MutationObserver")},e.prototype.attributeChangeObserve=function(e){e.target.hasAttribute("data-exposure")?this.exposureAdd(e,"mutation"):this.exposureRemove(e)},e.prototype.modifyNodeObserve=function(e){var t=this;Array.prototype.forEach.call(e.addedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureAdd(e,"intersect"),t.mapChild(e,t.exposureAdd)})),Array.prototype.forEach.call(e.removedNodes,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t.exposureRemove(e),t.mapChild(e,t.exposureRemove)}))},e.prototype.mapChild=function(e,t){var n=this;1===e.nodeType&&e.children.length&&Array.prototype.forEach.call(e.children,(function(e){1===e.nodeType&&e.hasAttribute("data-exposure")&&t(e),n.mapChild(e,t)}))},e.prototype.exposureAdd=function(e,t){try{this._intersection&&this._intersection.exposureAdd(e,t)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e.prototype.exposureRemove=function(e){try{this._intersection&&this._intersection.exposureRemove(e)}catch(e){console.log("intersection error",JSON.stringify(e.message))}},e._exposure_observer=null,e}(),O=function(){function e(t,n){this.count=1,this.instance=this.buildObserver(),this.observeMap=e._observer_map,t.autotrack.exposure.ratio?this.Ratio=t.autotrack.exposure.ratio:0===t.autotrack.exposure.ratio?this.Ratio=0:this.Ratio=.5,this.EventHandle=n}return e.prototype.buildObserver=function(){var t=this;return e._observer_instance?(console.log("your browser cannot support IntersectionObserver"),null):(IntersectionObserver&&(e._observer_instance=new IntersectionObserver((function(e){e.forEach((function(e){t.observeMap.get(e.target._observeId)&&t.exposureEvent(e)}))}),{threshold:[.01,.25,.5,.75,1]})),e._observer_instance)},e.prototype.exposureAdd=function(e,t){var n=e;"mutation"===t&&(n=e.target);var i=n._observeId;if(i||this.observeMap.has(i)){if(!1===n.visible){var o=n.getBoundingClientRect(),r=o.top,a=o.left,s=o.right,c=o.bottom;r>=0&&c<=window.innerHeight&&a>=0&&s<=window.innerWidth&&(n.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e))}}else n._observeId=this.count,n.visible=!1,this.observeMap.set(this.count,n),this.observe(n),this.count++},e.prototype.exposureRemove=function(e){this.observeMap.has(e._observeId)&&(this.observeMap.delete(e._observeId),this.unobserve(e))},e.prototype.exposureEvent=function(e){if(e.intersectionRatio>=this.Ratio&&e.isIntersecting){if("0"===e.target.style.opacity||"hidden"===e.target.style.visibility)return;if(!0===e.target.visible)return;e.target.visible=!0,this.EventHandle({eventType:"dom",eventName:"exposure"},e)}else e.target.visible=!1},e.prototype.observe=function(e){this.instance&&this.instance.observe(e)},e.prototype.unobserve=function(e){this.instance&&this.instance.unobserve(e)},e._observer_instance=null,e._observer_map=new Map,e}(),S=function(){function e(e,t){e.autotrack&&e.autotrack.exposure&&(this._intersection=new O(e,t),this._observer=new N(this._intersection),this._intersection&&this._observer?this.initObserver():console.log("your browser version cannot support exposure, please update~"))}return e.prototype.initObserver=function(){var e=this;Array.prototype.forEach.call(document.querySelectorAll("[data-exposure]"),(function(t){e._intersection.exposureAdd(t,"intersect")}))},e}(),I={hashTag:!1,impr:!1},C=function(){function e(){}return e.prototype.apply=function(e,t){if(this.autoTrackStart=!1,this.collect=e,this.config=t,t.autotrack){var n=e.Types;t.autotrack&&t.autotrack.collect_url&&!t.autotrack.collect_url()||(this.ready(n.Autotrack),this.collect.emit(n.AutotrackReady))}},e.prototype.ready=function(e){this.collect.set(e);var t=this.config.autotrack;t="object"==typeof t?t:{},t=Object.assign(I,t),this.destroyed=!1,this.options=t,this.Config=new d(u,this.options),this.Exposure=new S(this.config,this.handle.bind(this)),this.Listener=new c(t,this.collect,this.Config),this.EventHandle=new v(this.config,t),this.Request=new f(this.collect),this.autoTrackStart=!0,this.init(),k(this,this.config)},e.prototype.init=function(){this.Listener.init(this.handle.bind(this))},e.prototype.handle=function(e,t){"dom"===e.eventType&&this.handleDom(e,t)},e.prototype.handleDom=function(e,t){try{var n=e.eventName;if("click"===n||"exposure"===n||"change"===n||"submit"===n){var i=this.EventHandle.handleEvent(t,n);null!==i&&this.Request.send({eventType:"custom",eventName:"report_"+n+"_event",extra:{methods:"GET"}},i)}else if("page_view"===n||"page_statistics"===n){var o=void 0;o="page_view"===n?this.EventHandle.handleViewEvent(t):this.EventHandle.handleStatisticsEvent(t),this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"}},o)}else if("beat"===n){var r=this.EventHandle.handleBeadtEvent(t),a=e.eventSend;this.Request.send({eventType:"custom",eventName:"report_${eventName}_event",extra:{methods:"GET"},eventSend:a},r)}}catch(e){console.log("handel dom event error "+JSON.stringify(e))}},e.prototype.destroy=function(){if(!this.autoTrackStart)return console.warn("engine is undefined, make sure you have called autoTrack.start()");this.autoTrackStart=!1,this.Listener.removeListener()},e}();module.exports=C;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=function(){function t(){}return t.prototype.apply=function(t,a){var e=this;this.collector=t,this.config=a;var r=t.Types;t.on(r.TrackDurationStart,(function(t){e.trackStart(t)})),t.on(r.TrackDurationEnd,(function(t){e.trackEnd(t)})),t.on(r.TrackDurationPause,(function(t){e.trackPause(t)})),t.on(r.TrackDurationResume,(function(t){e.trackResume(t)})),this.Types=r,this.TrackMap=new Map,this.ready(r.TrackDuration)},t.prototype.ready=function(t){var a=this;if(this.collector.set(t),this.collector.hook._hooksCache.hasOwnProperty(t)){var e=this.collector.hook._hooksCache[t];if(!Object.keys(e).length)return;var r=function(t){e[t].length&&e[t].forEach((function(e){a.collector.hook.emit(t,e)}))};for(var o in e)r(o)}},t.prototype.trackStart=function(t){this.TrackMap.set(t,{startTime:Date.now(),isPause:!1,pauseTime:0,resumeTime:0})},t.prototype.trackEnd=function(t){var a=t.eventName,e=t.params;if(this.TrackMap.has(a)){var r=this.TrackMap.get(a),o=0;o=r.isPause?r.pauseTime-r.startTime:r.resumeTime?r.pauseTime-r.startTime+(Date.now()-r.resumeTime):Date.now()-r.startTime;var i=Object.assign(e,{event_duration:o});this.collector.event(a,i),this.cleanTrack(a)}},t.prototype.trackPause=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause||(a.isPause=!0,a.pauseTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.trackResume=function(t){if(this.TrackMap.has(t)){var a=this.TrackMap.get(t);a.isPause&&(a.isPause=!1,a.resumeTime=Date.now(),this.TrackMap.set(t,a))}},t.prototype.cleanTrack=function(t){this.TrackMap.delete(t)},t}();module.exports=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e,t){var a="function"==typeof Symbol&&e[Symbol.iterator];if(!a)return e;var o,r,n=a.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(a=n.return)&&a.call(n)}finally{if(r)throw r.error}}return i}function t(){for(var t=[],a=0;a<arguments.length;a++)t=t.concat(e(arguments[a]));return t}var a,o;!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.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.CepReady="cep-ready",e.TracerReady="tracer-ready"}(a||(a={})),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"}(o||(o={}));var r=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 a=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(a.RouteReady)}},e.prototype.setKey=function(){var e=this.collect.adapters.storage;this.storage=new e(!1),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.setItem(this.cache_key,this.cache)},e.prototype.hack=function(){var e=this,a=window.history.pushState;history.pushState=function(o){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onpushstate&&history.onpushstate({state:o});var i=a.call.apply(a,t([history,o],r));if(e.lastLocation!==location.href){var s=e.getPopStateChangeEventData();return e.setReferCache(e.lastLocation),e.lastLocation=location.href,e.sendPv(s,"pushState"),i}};var o=history.replaceState;history.replaceState=function(a){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];"function"==typeof history.onreplacestate&&history.onreplacestate({state:a});var i=o.call.apply(o,t([history,a],r));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(a){if(e.lastLocation!==window.location.href&&(clearTimeout(t),e.allowHash)){e.setReferCache(e.lastLocation),e.lastLocation=window.location.href;var o=e.getPopStateChangeEventData();e.sendPv(o)}})),window.addEventListener("popstate",(function(a){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.getItem(this.cache_key)||{},t=!1,a=this.storage.getItem("__tea_cache_first_"+this.appid);return t=!a||1!=a,{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(o.DEBUGGER_MESSAGE,{type:o.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.getItem()||{};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.getItem(this.cache_key)||{};t.refer_key=e,t.routeChange=!0,this.storage.setItem(this.cache_key,t)},e}();module.exports=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=function(){return t=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var s in e=arguments[i])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},t.apply(this,arguments)},e=function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)};Date.now(),Number((""+Math.random()).slice(2,8));var i,a,s=function(){var t=0;return["hidden","msHidden","webkitHidden"].forEach((function(e){void 0!==document[e]&&(t=1)})),t},n=function(){function i(t,i){this.maxDuration=432e5,this.aliveDTime=6e4,this.options={aliveName:"predefine_page_alive",params:{}},this.collect=t,this.config=i,this.pageStartTime=Date.now(),this.sessionStartTime=this.pageStartTime,this.timerHandler=null,e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration))}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.resetParams=function(t,e,i){this.url_path=t,this.url=i,this.title=e},i.prototype.enable=function(t,e,i){this.url_path=t||this.url_path,this.url=i||this.url,this.title=e||this.title,this.disableCallback=this.enablePageAlive(),this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params},i.prototype.disable=function(){this.disableCallback(),this.pageStartTime=Date.now()},i.prototype.sendEvent=function(e,i){void 0===i&&(i=!1);var a=i?this.aliveDTime:Date.now()-this.sessionStartTime;a<0||a>this.aliveDTime||Date.now()-this.pageStartTime>this.maxDuration||(this.collect.beconEvent(this.options.aliveName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),duration:a,is_support_visibility_change:s(),startTime:this.sessionStartTime,hidden:document.visibilityState,leave:e},this.customParmas)),this.sessionStartTime=Date.now(),this.resetParams(location.pathname,document.title,location.href))},i.prototype.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},i.prototype.setUpTimer=function(){var t=this;return this.timerHandler&&clearInterval(this.timerHandler),setInterval((function(){Date.now()-t.sessionStartTime>t.aliveDTime&&t.sendEvent(!1,!0)}),1e3)},i.prototype.visibilitychange=function(){"hidden"===document.visibilityState?this.timerHandler&&(clearInterval(this.timerHandler),this.sendEvent(!1)):"visible"===document.visibilityState&&(this.sessionStartTime=Date.now(),this.timerHandler=this.setUpTimer())},i.prototype.beforeunload=function(){document.hidden||this.sendEvent(!0)},i.prototype.enablePageAlive=function(){var t=this;this.timerHandler=this.setUpTimer();var e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),window.addEventListener("pagehide",i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}(),o=function(){function i(t,i){var a=this;this.maxDuration=432e5,this.aliveDTime=6e4,this.options={closeName:"predefine_page_close",params:{}},this.visibilitychange=function(){"hidden"===document.visibilityState?a.activeEndTime=Date.now():"visible"===document.visibilityState&&(a.activeEndTime&&(a.totalTime+=a.activeEndTime-a.activeStartTime,a.activeTimes+=1),a.activeEndTime=void 0,a.activeStartTime=Date.now())},this.beforeunload=function(){if(a.totalTime+=(a.activeEndTime||Date.now())-a.activeStartTime,a.config.autotrack){try{window.sessionStorage.setItem("_tea_cache_duration",JSON.stringify({duration:a.totalTime,page_title:document.title||location.pathname}))}catch(t){}}a.sendEventPageClose()},this.collect=t,this.config=i,this.maxDuration=i.maxDuration||864e5,this.pageStartTime=Date.now(),e(i.enable_stay_duration)&&(this.options=Object.assign(this.options,i.enable_stay_duration)),this.resetData()}return i.prototype.setParams=function(t,e,i){this.set_path=t,this.set_url=i,this.set_title=e},i.prototype.resetParams=function(t,e,i){this.url_path=t,this.url=i,this.title=e},i.prototype.enable=function(t,e,i){this.url_path=t||this.url_path,this.url=i||this.url,this.title=e||this.title,this.disableCallback=this.enablePageClose()},i.prototype.disable=function(){this.disableCallback()},i.prototype.resetData=function(){this.activeStartTime=void 0===this.activeStartTime?this.pageStartTime:Date.now(),this.activeEndTime=void 0,this.activeTimes=1,this.totalTime=0,this.options.params instanceof Function?this.customParmas=this.options.params():this.customParmas=this.options.params,this.resetParams(location.pathname,document.title,location.href)},i.prototype.sendEventPageClose=function(){var e=Date.now()-this.pageStartTime;this.totalTime<0||e<0||this.totalTime>=this.maxDuration||(this.collect.beconEvent(this.options.closeName,t({url_path:this.getParams("url_path"),title:this.getParams("title"),url:this.getParams("url"),active_times:this.activeTimes,duration:this.totalTime,total_duration:e,is_support_visibility_change:s()},this.customParmas)),this.pageStartTime=Date.now(),this.resetData())},i.prototype.getParams=function(t){switch(t){case"url_path":return this.set_path||this.url_path||location.pathname;case"title":return this.set_title||this.title||document.title||location.pathname;case"url":return this.set_url||this.url||location.href}},i.prototype.enablePageClose=function(){var t=this,e=this.visibilitychange.bind(this),i=this.beforeunload.bind(this);return document.addEventListener("visibilitychange",e),window.addEventListener("pagehide",i),function(){t.beforeunload(),document.removeEventListener("visibilitychange",e),window.removeEventListener("beforeunload",i),window.removeEventListener("pagehide",i)}},i}();!function(t){t.Init="init",t.Config="config",t.Start="start",t.Ready="ready",t.TokenComplete="token-complete",t.TokenStorage="token-storage",t.TokenFetch="token-fetch",t.TokenError="token-error",t.ConfigUuid="config-uuid",t.ConfigWebId="config-webid",t.ConfigDomain="config-domain",t.CustomWebId="custom-webid",t.AnonymousId="anonymous-id",t.TokenChange="token-change",t.TokenReset="token-reset",t.ConfigTransform="config-transform",t.EnvTransform="env-transform",t.SessionReset="session-reset",t.SessionResetTime="session-reset-time",t.Event="event",t.Events="events",t.EventNow="event-now",t.CleanEvents="clean-events",t.BeconEvent="becon-event",t.SubmitBefore="submit-before",t.SubmitScuess="submit-scuess",t.SubmitAfter="submit-after",t.SubmitError="submit-error",t.SubmitVerifyH="submit-verify-h5",t.Stay="stay",t.ResetStay="reset-stay",t.StayReady="stay-ready",t.SetStay="set-stay",t.RouteChange="route-change",t.RouteReady="route-ready",t.Ab="ab",t.AbVar="ab-var",t.AbAllVars="ab-all-vars",t.AbConfig="ab-config",t.AbExternalVersion="ab-external-version",t.AbVersionChangeOn="ab-version-change-on",t.AbVersionChangeOff="ab-version-change-off",t.AbOpenLayer="ab-open-layer",t.AbCloseLayer="ab-close-layer",t.AbReady="ab-ready",t.AbComplete="ab-complete",t.AbTimeout="ab-timeout",t.Profile="profile",t.ProfileSet="profile-set",t.ProfileSetOnce="profile-set-once",t.ProfileUnset="profile-unset",t.ProfileIncrement="profile-increment",t.ProfileAppend="profile-append",t.ProfileClear="profile-clear",t.TrackDuration="track-duration",t.TrackDurationStart="track-duration-start",t.TrackDurationEnd="track-duration-end",t.TrackDurationPause="track-duration-pause",t.TrackDurationResume="tracl-duration-resume",t.Autotrack="autotrack",t.AutotrackReady="autotrack-ready",t.CepReady="cep-ready",t.TracerReady="tracer-ready"}(i||(i={})),function(t){t.DEBUGGER_MESSAGE="debugger-message",t.DEBUGGER_MESSAGE_SDK="debugger-message-sdk",t.DEBUGGER_MESSAGE_FETCH="debugger-message-fetch",t.DEBUGGER_MESSAGE_FETCH_RESULT="debugger-message-fetch-result",t.DEBUGGER_MESSAGE_EVENT="debugger-message-event",t.DEVTOOL_WEB_READY="devtool-web-ready"}(a||(a={}));var r=function(){function t(){}return t.prototype.apply=function(t,e){var i=this;if(this.collect=t,this.config=e,this.config.enable_stay_duration){this.title=document.title||location.pathname,this.url=location.href,this.url_path=location.pathname,this.pageAlive=new n(t,e),this.pageClose=new o(t,e);var a=this.collect.Types;this.collect.on(a.ResetStay,(function(t){var e=t.url_path,a=t.title,s=t.url;i.resetStayDuration(e,a,s)})),this.collect.on(a.RouteChange,(function(t){t.init||e.disable_route_report||i.resetStayDuration()})),this.collect.on(a.SetStay,(function(t){var e=t.url_path,a=t.title,s=t.url;i.setStayParmas(e,a,s)})),this.enable(this.url_path,this.title,this.url),this.ready(a.Stay),this.collect.emit(a.StayReady)}},t.prototype.ready=function(t){var e=this;if(this.collect.set(t),this.collect.hook._hooksCache.hasOwnProperty(t)){var i=this.collect.hook._hooksCache[t];if(!Object.keys(i).length)return;var a=function(t){i[t].length&&i[t].forEach((function(i){e.collect.hook.emit(t,i)}))};for(var s in i)a(s)}},t.prototype.enable=function(t,e,i){this.pageAlive.enable(t,e,i),this.pageClose.enable(t,e,i)},t.prototype.disable=function(){this.pageAlive.disable(),this.pageClose.disable()},t.prototype.setStayParmas=function(t,e,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===i&&(i=""),this.pageAlive.setParams(t,e,i),this.pageClose.setParams(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayParams",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t.prototype.reset=function(t,e,i){this.disable(),this.enable(t,e,i)},t.prototype.resetStayDuration=function(t,e,i){this.reset(t,e,i),this.collect.emit(a.DEBUGGER_MESSAGE,{type:a.DEBUGGER_MESSAGE_SDK,info:"SDK 执行 resetStayDuration",level:"info",time:Date.now(),data:{url_path:t,title:e,url:i}})},t}();module.exports=r;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=function(){function t(){this.retryWaitTime=3e3,this.retryStatus=!1,this.retryCacheStatus=!1}return t.prototype.apply=function(t,e){var r=this;if(e.enable_storage&&!e.disable_storage&&(this.collect=t,this.config=e,!this.collect.destroyInstance)){var a=t.Types,n=t.adapters,o=n.storage,i=n.fetch;this.storage=new o(!1),this.fetch=i,this.eventUrl=this.collect.configManager.getUrl("event"),this.eventKey="__tea_cache_events_"+e.app_id,this.storageNum=e.storage_num||50,this.retryNum=e.retry_num||3,this.retryInterval=1e3,t.on(a.SubmitError,(function(t){"f_data"===t.type&&r.storeData(t)})),t.on(a.Ready,(function(){r.checkStorage()}))}},t.prototype.retryRightNow=function(t){var e=this;if(this.retryStatus)this.errorCache.push(t);else{var r=0;this.retryStatus=!0;var a=setInterval((function(){if(3===r)return e.storeData(e.errorCache),e.retryStatus=!1,void clearInterval(a);var n=t.eventData;e.fetchData(n,(function(){e.retryStatus=!1,clearInterval(a),e.retryCacheStatus&&e.errorCache.splice(0,1),e.errorCache.length&&(e.retryCacheStatus=!0,e.retryRightNow(e.errorCache[0]))}),(function(){r++}))}),this.retryInterval)}},t.prototype.storeData=function(t){var e=this.storage.getItem(this.eventKey),r=t.eventData;Object.keys(e).length!==this.storageNum&&(e[Date.now()]=r,this.storage.setItem(this.eventKey,e))},t.prototype.checkStorage=function(){var t=this;try{if(!window.navigator.onLine)return;var e=this.storage.getItem(this.eventKey);if(!e||!Object.keys(e).length)return;var r={events:[{event:"ontest",params:{app_id:this.config.app_id},local_time_ms:Date.now()}],user:{user_unique_id:this.collect.configManager.get("web_id")},header:{}};this.fetchData([r],(function(){var r=JSON.parse(JSON.stringify(e)),a=function(a){t.fetchData(e[a],(function(){delete r[a],t.storage.setItem(t.eventKey,r)}),(function(){}),!1)};for(var n in e)a(n)}),(function(){}),!0)}catch(t){console.warn("error check storage")}},t.prototype.fetchData=function(t,e,r,a){this.fetch(this.eventUrl,t,3e4,!1,(function(){e&&e()}),(function(){r&&r(),console.log("network error,compensate report failk")}),a&&!this.config.channel_domain?"566f58151b0ed37e":"")},t}();module.exports=t;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datarangers/sdk-javascript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"nclean": "rimraf es lib core",
|
|
6
6
|
"build": "export NODE_ENV=production && npm run nclean && npx rollup -c rollup.config.js",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"types": "./types/types.d.ts",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"js-cookie": "^3.0.1"
|
|
14
|
+
"js-cookie": "^3.0.1",
|
|
15
|
+
"sm-crypto": "^0.3.12"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"es",
|
package/types/types.d.ts
CHANGED
|
@@ -3,16 +3,67 @@ export interface IInitParam {
|
|
|
3
3
|
channel?: 'cn' | 'va' | 'sg';
|
|
4
4
|
channel_domain?: string;
|
|
5
5
|
app_key?: string;
|
|
6
|
+
caller?: string;
|
|
6
7
|
log?: boolean;
|
|
8
|
+
disable_webid?: boolean;
|
|
9
|
+
disable_sdk_monitor?: boolean;
|
|
10
|
+
disable_storage?: boolean;
|
|
11
|
+
autotrack?: any;
|
|
12
|
+
enable_stay_duration?: any;
|
|
13
|
+
disable_route_report?: boolean;
|
|
14
|
+
disable_session?: boolean;
|
|
15
|
+
disable_heartbeat?: boolean;
|
|
7
16
|
disable_auto_pv?: boolean;
|
|
17
|
+
enable_tracer?: boolean;
|
|
18
|
+
enable_spa?: boolean;
|
|
8
19
|
event_verify_url?: string;
|
|
20
|
+
enable_ttwebid?: boolean;
|
|
21
|
+
user_unique_type?: string;
|
|
22
|
+
enable_ab_test?: boolean;
|
|
23
|
+
max_storage_num?: number;
|
|
24
|
+
enable_storage?: boolean;
|
|
25
|
+
enable_cookie?: boolean;
|
|
26
|
+
enable_ab_visual?: boolean;
|
|
27
|
+
cross_subdomain?: boolean;
|
|
28
|
+
cookie_domain?: string;
|
|
29
|
+
enable_multilink?: boolean;
|
|
30
|
+
multilink_timeout_ms?: number;
|
|
31
|
+
reportTime?: number;
|
|
32
|
+
timeout?: number;
|
|
33
|
+
max_report?: number;
|
|
34
|
+
report_url?: string;
|
|
35
|
+
maxDuration?: number;
|
|
36
|
+
ab_channel_domain?: string;
|
|
37
|
+
configPersist?: number;
|
|
38
|
+
extend?: any;
|
|
39
|
+
ab_timeout?: number;
|
|
40
|
+
disable_tracer?: boolean;
|
|
41
|
+
extendConfig?: any;
|
|
42
|
+
filter?: any;
|
|
43
|
+
cep?: boolean;
|
|
44
|
+
cep_url?: string;
|
|
45
|
+
spa?: boolean;
|
|
46
|
+
cookie_expire?: number;
|
|
47
|
+
enable_custom_webid?: boolean;
|
|
48
|
+
disable_track_event?: boolean;
|
|
49
|
+
allow_hash?: boolean;
|
|
50
|
+
enable_native?: boolean;
|
|
51
|
+
ab_cross?: boolean;
|
|
52
|
+
ab_cookie_domain?: string;
|
|
53
|
+
disable_ab_reset?: boolean;
|
|
54
|
+
enable_encryption?: boolean;
|
|
55
|
+
enable_anonymousid?: boolean
|
|
56
|
+
enable_debug?: boolean
|
|
57
|
+
crypto_publicKey?: string
|
|
58
|
+
encryption_type?: string
|
|
59
|
+
encryption_header?: string
|
|
9
60
|
}
|
|
10
61
|
|
|
11
62
|
export interface IConfigParam {
|
|
12
63
|
_staging_flag?: 0 | 1;
|
|
13
64
|
user_unique_id?: string;
|
|
14
|
-
web_id?: string;
|
|
15
65
|
disable_auto_pv?: boolean;
|
|
66
|
+
web_id?: string;
|
|
16
67
|
user_type?: number;
|
|
17
68
|
os_name?: string;
|
|
18
69
|
os_version?: string;
|
|
@@ -67,6 +118,14 @@ export type SdkOption = Omit<IInitParam, 'app_id'>;
|
|
|
67
118
|
|
|
68
119
|
export type SdkHookListener = (hookInfo?: any) => void;
|
|
69
120
|
|
|
121
|
+
export interface Plugin {
|
|
122
|
+
apply(sdk: Sdk, options: SdkOption): void;
|
|
123
|
+
}
|
|
124
|
+
export interface PluginConstructor {
|
|
125
|
+
new(): Plugin;
|
|
126
|
+
pluginName?: string;
|
|
127
|
+
init?(Sdk: SdkConstructor): void;
|
|
128
|
+
}
|
|
70
129
|
|
|
71
130
|
export declare enum SdkHook {
|
|
72
131
|
Init = 'init',
|
|
@@ -78,17 +137,72 @@ export declare enum SdkHook {
|
|
|
78
137
|
TokenFetch = 'token-fetch',
|
|
79
138
|
TokenError = 'token-error',
|
|
80
139
|
ConfigUuid = 'config-uuid',
|
|
140
|
+
ConfigWebId = 'config-webid',
|
|
81
141
|
ConfigDomain = 'config-domain',
|
|
142
|
+
CustomWebId = 'custom-webid',
|
|
82
143
|
TokenChange = 'token-change',
|
|
83
144
|
TokenReset = 'token-reset',
|
|
145
|
+
ConfigTransform = 'config-transform',
|
|
146
|
+
EnvTransform = 'env-transform',
|
|
84
147
|
SessionReset = 'session-reset',
|
|
85
148
|
SessionResetTime = 'session-reset-time',
|
|
86
149
|
Event = 'event',
|
|
87
150
|
Events = 'events',
|
|
151
|
+
EventNow = 'event-now',
|
|
152
|
+
CleanEvents = 'clean-events',
|
|
153
|
+
BeconEvent = 'becon-event',
|
|
154
|
+
SubmitBefore = 'submit-before',
|
|
155
|
+
SubmitScuess = 'submit-scuess',
|
|
156
|
+
SubmitAfter = 'submit-after',
|
|
157
|
+
SubmitError = 'submit-error',
|
|
158
|
+
SubmitVerify = 'submit-verify',
|
|
159
|
+
SubmitVerifyH = 'submit-verify-h5',
|
|
160
|
+
|
|
161
|
+
Stay = 'stay',
|
|
162
|
+
ResetStay = 'reset-stay',
|
|
163
|
+
StayReady = 'stay-ready',
|
|
164
|
+
SetStay = 'set-stay',
|
|
165
|
+
|
|
166
|
+
RouteChange = 'route-change',
|
|
167
|
+
RouteReady = 'route-ready',
|
|
168
|
+
|
|
169
|
+
Ab = 'ab',
|
|
170
|
+
AbVar = 'ab-var',
|
|
171
|
+
AbAllVars = 'ab-all-vars',
|
|
172
|
+
AbConfig = 'ab-config',
|
|
173
|
+
AbExternalVersion = 'ab-external-version',
|
|
174
|
+
AbVersionChangeOn = 'ab-version-change-on',
|
|
175
|
+
AbVersionChangeOff = 'ab-version-change-off',
|
|
176
|
+
AbOpenLayer = 'ab-open-layer',
|
|
177
|
+
AbCloseLayer = 'ab-close-layer',
|
|
178
|
+
AbReady = 'ab-ready',
|
|
179
|
+
AbComplete = 'ab-complete',
|
|
180
|
+
|
|
181
|
+
Profile = 'profile',
|
|
182
|
+
ProfileSet = 'profile-set',
|
|
183
|
+
ProfileSetOnce = 'profile-set-once',
|
|
184
|
+
ProfileUnset = 'profile-unset',
|
|
185
|
+
ProfileIncrement = 'profile-increment',
|
|
186
|
+
ProfileAppend = 'profile-append',
|
|
187
|
+
ProfileClear = 'profile-clear',
|
|
188
|
+
|
|
189
|
+
TrackDuration = 'track-duration',
|
|
190
|
+
TrackDurationStart = 'track-duration-start',
|
|
191
|
+
TrackDurationEnd = 'track-duration-end',
|
|
192
|
+
TrackDurationPause = 'track-duration-pause',
|
|
193
|
+
TrackDurationResume = 'tracl-duration-resume',
|
|
194
|
+
|
|
195
|
+
Autotrack = 'autotrack',
|
|
196
|
+
AutotrackReady = 'autotrack-ready',
|
|
197
|
+
|
|
198
|
+
CepReady = 'cep-ready',
|
|
199
|
+
|
|
200
|
+
TracerReady = 'tracer-ready'
|
|
88
201
|
}
|
|
89
202
|
interface SdkConstructor {
|
|
90
203
|
new(name: string): Sdk;
|
|
91
204
|
instances: Array<Sdk>;
|
|
205
|
+
usePlugin: (plugin: PluginConstructor, pluginName?: string) => void;
|
|
92
206
|
}
|
|
93
207
|
interface Sdk {
|
|
94
208
|
Types: typeof SdkHook;
|
|
@@ -97,9 +211,11 @@ interface Sdk {
|
|
|
97
211
|
once(type: string, hook: SdkHookListener): void;
|
|
98
212
|
off(type: string, hook?: SdkHookListener): void;
|
|
99
213
|
emit(type: string, info?: any, wait?: string): void;
|
|
214
|
+
|
|
100
215
|
init(options: IInitParam): void;
|
|
101
216
|
config(configs?: IConfigParam): void;
|
|
102
217
|
getConfig(key?: string): Record<string, any>;
|
|
218
|
+
setDomain(domain: string): void;
|
|
103
219
|
start(): void;
|
|
104
220
|
send(): void;
|
|
105
221
|
set(type: string): void;
|
|
@@ -109,7 +225,40 @@ interface Sdk {
|
|
|
109
225
|
events:
|
|
110
226
|
| Array<[string, EventParams] | [string, EventParams, number]>
|
|
111
227
|
): void;
|
|
228
|
+
|
|
112
229
|
predefinePageView(params: any): void;
|
|
230
|
+
clearEventCache(): void;
|
|
231
|
+
setWebIDviaUnionID(unionId: string): void;
|
|
232
|
+
setWebIDviaOpenID(openId): void;
|
|
233
|
+
getToken(callback: (info: Record<string, string | number>) => void, timeout?: number): void;
|
|
234
|
+
|
|
235
|
+
resetStayDuration(url_path?: string, title?: string, url?: string): void;
|
|
236
|
+
resetStayParams(url_path?: string, title?: string, url?: string): void;
|
|
237
|
+
|
|
238
|
+
profileSet(profile: any): void;
|
|
239
|
+
profileSetOnce(profile: any): void;
|
|
240
|
+
profileIncrement(profile: any): void;
|
|
241
|
+
profileUnset(key: string): void;
|
|
242
|
+
profileAppend(profile: any): void;
|
|
243
|
+
|
|
244
|
+
startTrackEvent(eventName: string): void;
|
|
245
|
+
endTrackEvent(eventName: string, params: any): void;
|
|
246
|
+
pauseTrackEvent(eventName: string): void;
|
|
247
|
+
resumeTrackEvent(eventName: string): void;
|
|
248
|
+
|
|
249
|
+
setExternalAbVersion(vids: string): void;
|
|
250
|
+
getVar(name: string, defaultValue: any, callback: (value: any) => void): void;
|
|
251
|
+
getAllVars(callback: (value: any) => void): void;
|
|
252
|
+
getAbSdkVersion(): string;
|
|
253
|
+
onAbSdkVersionChange(callback: (vids: string) => void): () => void;
|
|
254
|
+
offAbSdkVersionChange(callback: (vids: string) => void): void;
|
|
255
|
+
setExternalAbVersion(vids: string | null): void;
|
|
256
|
+
getABconfig(params: Record<string, any>, callback: (value: any) => void): void;
|
|
257
|
+
openOverlayer(): void;
|
|
258
|
+
closeOverlayer(): void;
|
|
259
|
+
autoInitializationRangers(
|
|
260
|
+
config: IInitParam & { onTokenReady: (webId: string) => void },
|
|
261
|
+
): void;
|
|
113
262
|
}
|
|
114
263
|
declare const Sdk: Sdk;
|
|
115
264
|
export const Collector: SdkConstructor;
|