UNPKG

qoe-pps

Version:

this is a qoe project of pps

1 lines 8.07 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("usertiming")):"function"==typeof define&&define.amd?define(["usertiming"],e):"object"==typeof exports?exports.qoe=e(require("usertiming")):t.qoe=e(t._)}(window,(function(t){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(e,n){e.exports=t},function(t,e,n){"use strict";n.r(e);var o=n(0),r=n.n(o);const s="undefined"==typeof window?{sessionStorage:{removeItem:t=>{},setItem:(t,e)=>{},getItem:t=>{}},navigator:{connection:{effectiveType:""},mozConnection:{effectiveType:""},appVersion:""}}:window;const a="//10.3.12.100/qos";function i(t,e){(e?Object.getOwnPropertyNames(e):[]).forEach((function(n){t[n]=e[n]}))}function c(t){s.navigator.sendBeacon&&FormData?function(t){const e=Object.keys(t),n=new FormData;n.append("t",1),e.forEach(e=>n.append(e,t[e])),s.navigator.sendBeacon(a,n),console.log("[QOE] sent: "+a)}(t):function(t){let e=a;const n=Object.keys(t);e+="?t=10&"+n.map((function(e){return e+"="+t[e]})).join("&"),(new Image).src=e,console.log("[QOE] sent: "+e)}(t)}function u(t){return r.a.getEntriesByName(t)}function p(t){return r.a.getEntriesByType(t||"resource")}function h(t,e){let n=[];return(n="[object Array]"===Object.prototype.toString.call(e)?e:p(e)).filter(t)}function d(t,e){return h(function(t){switch(Object.prototype.toString.call(t)){case"[object RegExp]":return function(e){return t.test(e.name)};case"[object String]":return function(e){return-1!==e.name.indexOf(t)};default:return function(t){return t.name}}}(t),e)}const f="firstPage";function m(t){const e={duration:-1,LastResponse:-1};let n=[];if("[object Array]"===Object.prototype.toString.call(t)){t.forEach((function(t){t.startTime>0&&n.push(t.startTime),t.responseEnd>0&&n.push(t.responseEnd)}));const o=Math.max.apply(Math,n);e.duration=o-Math.min.apply(Math,n),e.LastResponse=o}return e}n.d(e,"default",(function(){return E}));const _="_Q_test_",l="_QOE_HIT_";class E{constructor(t={}){this.hit=t.sampleRate,this.p1=t.p1||"2_20_201",this.bc=t.bc||"1",this.config(t)}config(t={}){if(!t.pageName)return console.warn("[QOE] error: there seems to be no pagename"),!1;this._QOE={},this.errorList=[],this.actionIndex=0,this.pageName=t.pageName;const e=this.checkHit(this.hit);return e&&(this.ajax=t.ajax||[],this.consuming=t.consuming||[],this.extendParams=t.extendParams||{}),e}checkHit(t){try{s.sessionStorage.removeItem(_),s.sessionStorage.setItem(_,1),s.sessionStorage.removeItem(_)}catch(t){return console.error("sessionStorage error: "+JSON.stringify(t)),!1}let e=sessionStorage.getItem(l);return e||(e=Math.round(100*Math.random()),sessionStorage.setItem(l,e)),e>>0<(t||1)}mark(t,e){r.a.mark(t);const n=r.a.now();return e&&(this._QOE[t]=n),n}measure(t,e,n,o){r.a.measure(t,e,n);const s=u(t)[0].duration;return o&&(this._QOE[t]=s),r.a.clearMeasures(t),s}syncResource(){this.syncJsAndCssOn1stPage=h(t=>"css"!==t.initiatorType&&"img"!==t.initiatorType)}sendGroup(){if(!this.pageName)return;this.mark("QOEPrepare"),i(this._QOE,function(t,e){const n=r.a.timing||{},o=r.a.timing||{},a=u(f)[0],i=s.navigator||{},c=i.connection||i.mozConnection,p=i.appVersion.replace(/.*AppleWebKit\/([\w.]+).*\..*/,"$1");return{docLoad:n.responseEnd-n.navigationStart,analysisStart:n.domLoading-n.navigationStart,domComplete:n.domComplete-n.navigationStart,responseStart:n.responseStart-n.navigationStart,analysisEnd:n.domInteractive-n.navigationStart,syncJsAndCssOn1stPage:m(t).duration,firstPaint:e,firstPage:a?a.startTime:null,networkInfomation:c?c.effectiveType:"",browserVersion:p,lookupDomain:n.domainLookupEnd-n.domainLookupStart,appcache:n.domainLookupStart-n.fetchStart,connect:n.connectEnd-n.connectStart,accessType:o.type}}(this.syncJsAndCssOn1stPage,s.__first_paint_count||0)),i(this._QOE,function(){const t={hm:/\/\/hm\.baidu\.com\/hm\.js\?5df871ab99f94347b23ca224fc7d013f/,irt:/\/\/iqiyi\.irs01\.com\/irt/,ads:/\/\/static\.iqiyi\.com\/js\/common\/ares-/};for(let e in t)t[e]=m(d(t[e])).duration;return t}()),i(this._QOE,function(t){let e,n=[];return t.forEach((function(t){n=n.concat(d(t))})),{ajaxConsuming:(e=m(n)).duration,ajaxReady:e.LastResponse}}(this.ajax));let t={type:"qoe",groupname:"m_page_"+this.pageName,_:+new Date};i(t,this.extendParams),this.mark("QOESend"),this.measure("QOERun","QOEPrepare","QOESend",!0);const e={res_start:this._QOE.responseStart,ana_start:this._QOE.analysisStart,doc_load:this._QOE.docLoad,fst_paint:this._QOE.firstPaint,fst_page:this._QOE.firstPage,ana_end:this._QOE.analysisEnd,dom_comp:this._QOE.domComplete,ajax_ready:this._QOE.ajaxReady,adjs_start:this._QOE.ad_script_start,adjs_end:this._QOE.ad_script_end,fdl:this._QOE.fangdaolian,src_auth:this._QOE.sourceAuth,ad_req:this._QOE.ad_request,pbtn_show:this._QOE.playBtnShow,qoe_run:this._QOE.QOERun,net_info:this._QOE.networkInfomation,bro_ver:this._QOE.browserVersion,lookup_dns:this._QOE.lookupDomain,appcache:this._QOE.appcache,connect:this._QOE.connect,acc_type:this._QOE.accessType,doc_ana:Math.ceil(this._QOE.analysisEnd-this._QOE.firstPaint),trans:Math.ceil(this._QOE.firstPaint)};this.getApi(e,t)}sendSync(){if(!this.pageName)return;this.mark("QOEPrepare");const t={type:"qoe",groupname:"m_page_"+this.pageName,_:+new Date};this.mark("QOESend"),this.measure("QOERun","QOEPrepare","QOESend",!0);const e={fdl_dl:Math.ceil(this._QOE.fangdaolianDownload),fdl_exc:Math.ceil(this._QOE.fangdaolian),ad_dl:Math.ceil(this._QOE.adDownload),ad_exc:Math.ceil(this._QOE.ad_request)};this.getApi(e,t)}sendAjax(){if(!this.pageName)return;this.mark("QOEPrepare");const t={type:"qoe",groupname:"m_page_"+this.pageName,_:+new Date};this.mark("QOESend"),this.measure("QOERun","QOEPrepare","QOESend",!0);const e={cooksdk_dl:Math.ceil(this._QOE.cooksdkDownload),cooksdk_exc:Math.ceil(this._QOE.cooksdkExecute),tmts_ajax:Math.ceil(this._QOE.sourceAuth),dfp_to:Math.ceil(this._QOE.dfpTimeout),set_src:Math.ceil(this._QOE.playBtnShow),can_play:Math.ceil(this._QOE.canPlayPreloaded),fst_play:Math.ceil(this._QOE.videoTimeupdate)};this.getApi(e,t)}getApi(t,e){let n=0;for(let o in t)t[o]&&t[o]>0&&isFinite(t[o])?(n+=1,e[o]="number"==typeof t[o]?parseInt(t[o].toFixed(2)):0):console.warn("[QOE] missing: "+o);0!==n&&(e.p1=this.p1,e.bc=this.bc,c(e))}sendInterface(t,e){e="object"!=typeof e?{[t]:e}:e,this._sendInterface(t,e)}sendIntreface(t,e){const n="object"==typeof JSON.parse(e)?e:{[t]:e};this._sendInterface(t,n)}_sendInterface(t,e={}){const n=Object.keys(e)||[],o={groupname:"m_if_"+t,p1:this.p1,bc:this.bc};n.forEach(t=>{let n=e[t];if(!n){const e=t+"Start",o=t+"End";u(e).length&&u(o).length&&(n=this.measure(t,e,o))}o[t]="number"==typeof n?parseInt(n.toFixed(2)):n}),c(o)}sendAction(){const t=this.consuming,e=this.actionIndex,n=h((function(t,n){return n>e&&("script"===t.initiatorType||"xmlhttprequest"===t.initiatorType)}));t.forEach(t=>{d(t.pattern,n).forEach(e=>{this.sendIntreface(t.name,e.duration)})}),this.actionIndex=p().length}addError(t){this.errorList.push(t)}sendError(){if(this.errorList.length){const t=this.errorList.reduce((t,e)=>Object.assign(t,e),{});this._sendInterface("error",t)}}get(t){return t&&this._QOE[t]?this._QOE[t]:t&&!this._QOE[t]?(console.warn("there is no property called '"+t+"'"),null):this._QOE}}}])}));