gio-miniprogram-sdk 4.5.1 → 4.6.1

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.
@@ -1 +1 @@
1
- var e=function(){return e=Object.assign||function(e){for(var t,r=1,n=arguments.length;n>r;r++)for(var i in t=arguments[r])({}).hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t,r=/^gioTrack(.+)/,n=/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/,i=function(e){return["undefined","null"].includes(v(e))},o=function(e){return"string"===v(e)},s=function(e){return"[object Object]"==={}.toString.call(e)&&!i(e)},c=function(e){return Array.isArray(e)&&"array"===v(e)},a=function(e,t){if(void 0===t&&(t=!1),c(e)){for(var r=0,n=[],i=0,o=e;i<o.length;i++){var s=o[i];s&&!d(s)&&(n[r++]=s),t&&0===s&&(n[r++]=s)}return n}return e},u=function(e){return i(e)?"":"".concat(e)},l=function(e){return s(e)?Object.keys(e):[]},g=function(e,t){if(!s(e))return!1;try{if("string"===v(t))return delete e[t];if("array"===v(t))return t.map(function(t){return delete e[t]});"object"===v(t)&&t.constructor===RegExp&&l(e).forEach(function(r){t.test(r)&&g(e,r)})}catch(e){return!1}},d=function(e){return c(e)?0===e.length:s(e)?0===l(e).length:!e},v=function(e){return{}.toString.call(e).slice(8,-1).toLowerCase()},p=function(e){try{return e()}catch(e){return}},f=function(e){var t={};return s(e)&&(g(e,"&&sendTo"),function(e){l(e).forEach(function(r){return function(e,r){var n=u(r).slice(0,100);s(e)?t[n]=f(e):c(e)?(t[n]=a(e.slice(0,100),!0),t[n]=t[n].join("||").slice(0,1e3)):function(e){return"date"===v(e)}(e)?t[n]=function(e){function t(e){return 10>e?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+" "+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+t(e.getMilliseconds())}(e):t[n]=i(e)?"":u(e).slice(0,1e3)}(e[r],r)})}(e)),t},m=function(e,t){void 0===t&&(t=!1);var r=0;if(d(e)||"boolean"==typeof e)return r;for(var n=0;n<e.length;)r=(r<<5)-r+e.charCodeAt(n),r&=r,n++;return t?Math.abs(r):r},I={name:"gioImpressionTracking",method:function(i){var l=this;this.growingIO=i,this.traverseListen=function(e){var r=l.growingIO.minipInstance;if(t.isFunction(null==e?void 0:e.selectAllComponents)){var n=null==e?void 0:e.selectAllComponents(".growing_collect_imp_component");t.isEmpty(n)||n.forEach(function(e){l.traverseListen(e)})}r.initImpression(e)},this.isEqualRects=function(e,t,r){var n,i,o,s,a=(null!==(i=(null!==(n=l.rects[t])&&void 0!==n?n:{})[r])&&void 0!==i?i:[]).map(function(e){return m(JSON.stringify(e))}),u=(null!=e?e:[]).map(function(e){return m(JSON.stringify(e))});return s=u,!(!c(o=a)||!c(s)||o.length!==s.length)&&o.every(function(e,t){return e===s[t]})},this.getNodeId=function(e){switch(l.growingIO.gioPlatform){case"wx":case"qq":case"ks":case"jd":return e.__wxExparserNodeId__;case"my":case"tb":return e.$page?"".concat(e.$page.$id,"-").concat(e.$id):e.$id;case"swan":return e.route?u(m(e.route)):e.nodeId;case"tt":return e.route?u(m(e.route)):e.__nodeId__;case"xhs":return e.route?e.pageId:e.componentId}},this.rectObserve=function(e,r,n){var i=l.growingIO.gioPlatform;if("tt"===i&&r.__nodeId__||"ks"===i&&r.is||"xhs"===i&&r.componentId)return!1;var o=l.getNodeId(r),s=r.route?r:l.growingIO.minipInstance.getCurrentPage(),c=!1;if(s.route){var a=l.isEqualRects(e,s.route,o),u=t.get(l.observerIds,"".concat(s.route,".").concat(o,"._disconnected"));c=!a||!1!==u}t.isArray(e)&&!t.isEmpty(e)&&!t.isNil(e[0])&&c&&(t.isEmpty(l.rects[s.route])&&(l.rects[s.route]={}),l.rects[s.route][o]=e,l.createObserver(r,n))},this.main=function(e,r){var n,i,o=l.growingIO.gioPlatform,s=e.route?null===(n=l.growingIO.minipInstance.minip)||void 0===n?void 0:n.createSelectorQuery():null===(i=l.growingIO.minipInstance.minip)||void 0===i?void 0:i.createSelectorQuery().in(e);["ks","qq"].includes(o)?(s.selectAll(".growing_collect_imp").boundingClientRect(function(n){var i=n[0],o=void 0===i?[]:i;o=t.isArray(o)?o:[o],d(o)||l.rectObserve(o,e,r)}),s.exec()):(s.selectAll(".growing_collect_imp").boundingClientRect(),s.exec(function(t){var n=t[0];d(n)||l.rectObserve(n,e,r)}))},this.createObserver=function(e,r){var n,i,o=l.growingIO,s=o.gioPlatform,c=o.minipInstance,a=((n={thresholds:[o.vdsConfig.impressionScale||1e-13]})[r]=!0,n);["tb","my"].includes(s)&&t.compareVersion(my.SDKVersion,"2.7.0")>=-1&&(a.dataset=!0);var u=l.getNodeId(e),g=e;!e.isComponent&&e.route&&"component"!==e.mpType||(g=c.getCurrentPage()),l.observerIds[g.route]||(l.observerIds[g.route]={});var d,v=l.observerIds[g.route][u];v&&!v._disconnected&&v.disconnect(),["swan","jd","xhs"].includes(s)?d=null===(i=c.minip)||void 0===i?void 0:i.createIntersectionObserver(e,a):(d=p(function(){return e.createIntersectionObserver(a)}))||(d=p(function(){var t;return null===(t=c.minip)||void 0===t?void 0:t.createIntersectionObserver(e,a)})),(null==d?void 0:d.relativeToViewport)?(d=d.relativeToViewport(),l.observerIds[g.route][u]=d,l.targetObserve(d,g)):t.consoleText("创建曝光监听失败,当前环境不支持 createIntersectionObserver: ".concat(s),"warn")},this.targetObserve=function(e,r){var n=l.growingIO.vdsConfig,i=n.taro,s=n.impressionScale||1e-13;e.observe(".growing_collect_imp",function(e){if(!t.isEmpty(e)&&e.intersectionRatio>=s){var n=e.dataset;i&&t.isTaro3(i)&&(n=l.getTaro3Dataset(r.route,e.id));var u=l.getImpressionProperties(n),g=e.id;if(g){if("once"===n.gioImpType&&t.has(l.sentImps,g))return;l.sentImps[g]=u}if(u.eventName){var v=[];if(n.gioImpSendto){var f=n.gioImpSendto;c(f)?v=a(f):o(f)&&(v=a(p(function(){return JSON.parse(f)})||[]),d(v)&&f.split(",").forEach(function(e){(e=o(e)&&e.trim().replace("[","").replace("]",""))&&v.push(e)}))}l.buildImpEvent(u,v)}else t.consoleText("曝光事件格式不正确,事件名只能包含数字、字母和下划线,且不以数字开头!","warn")}})},this.getImpressionProperties=function(e){var i,s,c={eventName:void 0,properties:{}};if(!(null==e?void 0:e.gioImpTrack))return c;if(c.eventName=e.gioImpTrack,t.has(e,"gioImpAttrs"))c.properties=t.niceTry(function(){return t.isObject(e.gioImpAttrs)?e.gioImpAttrs:JSON.parse(e.gioImpAttrs)});else for(var a in e){var u=void 0,l=a.match(r);l&&"track"!==(u=t.lowerFirst(l[1]))&&(c.properties[u]=e[a])}return c.properties=t.limitObject(c.properties),i=c.eventName,s=function(){return c},(o(i)&&!d(i)&&i.match(n)?s():(console.log("%c[GrowingIO]:事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!","color: #EF4444"),!1))||(c.eventName=null,c={}),c},this.getTaro3Dataset=function(e,r){var n,i=null===(n=l.growingIO)||void 0===n?void 0:n.taro3VMs[e];if(!i)return!1;var o={},s=function(e){e.some(function(e){var n;return e.uid!==r&&e.sid!==r||-1>=(null===(n=e.props)||void 0===n?void 0:n.class.indexOf("growing_collect_imp"))||t.isEmpty(e.dataset)?!!Array.isArray(e.childNodes)&&s(e.childNodes):(o=e.dataset,!0)})};return s(i.childNodes),o},this.buildImpEvent=function(t,r){var n,i=t.eventName,o=t.properties,c=l.growingIO,a=c.trackingId,u=c.dataStore,g=u.eventContextBuilder,v=u.eventConverter,p=c.plugins,m=e({eventType:"CUSTOM",eventName:i},g(a));m.attributes=f(e(e({},null!==(n=m.attributes)&&void 0!==n?n:{}),s(o)&&!d(o)?o:{})),p.gioMultipleInstances&&!d(r)&&(m["&&sendTo"]=r),v(m)},this.pluginVersion="4.5.1",t=this.growingIO.utils,this.observerIds={},this.rects={},this.sentImps={};var g=this.growingIO,v=g.emitter,I=g.minipInstance;this.growingIO.updateImpression=function(e){e||(e=I.getCurrentPage()),I.initImpression(e)},v.on("MINIP_LIFECYCLE",function(e){var t,r=e.event,n=e.params,i=l.growingIO.minipInstance;if("Page onShowEnd"===r){var o=i.getCurrentPage();l.traverseListen(o)}if(["Page onHide","Page onUnload"].includes(r)){var s=n.page.route;Object.values(null!==(t=l.observerIds[s])&&void 0!==t?t:{}).forEach(function(e){return e.disconnect()})}})}};export{I as default};
1
+ var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;r>n;n++)for(var i in t=arguments[n])({}).hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t,n=/^gioTrack(.+)/,r=/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/,i=function(e){return["undefined","null"].includes(d(e))},o=function(e){return"string"===d(e)},a=function(e){return"[object Object]"==={}.toString.call(e)&&!i(e)},s=function(e){return Array.isArray(e)&&"array"===d(e)},c=function(e,t){if(void 0===t&&(t=!1),s(e)){for(var n=0,r=[],i=0,o=e;i<o.length;i++){var a=o[i];a&&!v(a)&&(r[n++]=a),t&&0===a&&(r[n++]=a)}return r}return e},u=function(e){return i(e)?"":"".concat(e)},l=function(e){return a(e)?Object.keys(e):[]},g=function(e,t){if(!a(e))return!1;try{if("string"===d(t))return delete e[t];if("array"===d(t))return t.map(function(t){return delete e[t]});"object"===d(t)&&t.constructor===RegExp&&l(e).forEach(function(n){t.test(n)&&g(e,n)})}catch(e){return!1}},v=function(e){return s(e)?0===e.length:a(e)?0===l(e).length:!e},d=function(e){return{}.toString.call(e).slice(8,-1).toLowerCase()},p=function(e){try{return e()}catch(e){return}},f=function(e){var t={};return a(e)&&(g(e,"&&sendTo"),function(e){l(e).forEach(function(n){return function(e,n){var r=u(n).slice(0,100);a(e)?t[r]=f(e):s(e)?(t[r]=c(e.slice(0,100),!0),t[r]=t[r].join("||").slice(0,1e3)):function(e){return"date"===d(e)}(e)?t[r]=function(e){function t(e){return 10>e?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+" "+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+t(e.getMilliseconds())}(e):t[r]=i(e)?"":u(e).slice(0,1e3)}(e[n],n)})}(e)),t},m=function(e,t){void 0===t&&(t=!1);var n=0;if(v(e)||"boolean"==typeof e)return n;for(var r=0;r<e.length;)n=(n<<5)-n+e.charCodeAt(r),n&=n,r++;return t?Math.abs(n):n},I=function(e){var t,n;return!!e&&!e.isComponent&&"component"!==e.mpType&&"component"!==(null===(t=e.$vm)||void 0===t?void 0:t.mpType)&&void 0===(null===(n=e.$page)||void 0===n?void 0:n.$id)&&!!h(e)},h=function(e){var t,n;return(null==e?void 0:e.route)||(null==e?void 0:e.uri)||(null==e?void 0:e.__route__)||(null===(t=null==e?void 0:e.$vm)||void 0===t?void 0:t.__route__)||function(e){if(o(e)){var t=e.indexOf("?");return-1!==t?[e.substring(0,t),e.substring(t+1)]:[e,""]}return["",""]}((null===(n=null==e?void 0:e.$page)||void 0===n?void 0:n.fullPath)||(null==e?void 0:e.$taroPath))[0]||""},O={name:"gioImpressionTracking",method:function(i){var l=this;this.growingIO=i,this.isPageTarget=I,this.getPagePath=function(e){return l.isPageTarget(e)?h(e):""},this.getOwnerPage=function(e,t){var n,r;return l.isPageTarget(e)?e:t||(l.isPageTarget(null==e?void 0:e.$page)?e.$page:void 0)||(null===(r=null===(n=l.growingIO.dataStore)||void 0===n?void 0:n.eventHooks)||void 0===r?void 0:r.currentPage.getContextPage())||l.growingIO.minipInstance.getCurrentPage()},this.traverseListen=function(e,n){var r,i;void 0===n&&(n=l.getOwnerPage(e));var o=l.growingIO.minipInstance;if(t.isFunction(null==e?void 0:e.selectAllComponents)){var a=null==e?void 0:e.selectAllComponents(".growing_collect_imp_component");t.isEmpty(a)||a.forEach(function(e){l.traverseListen(e,n)})}var s=null===(i=null===(r=l.growingIO.dataStore)||void 0===r?void 0:r.eventHooks)||void 0===i?void 0:i.currentPage,c=function(){return o.initImpression(e)};n&&(null==s?void 0:s.withPageContext)?s.withPageContext(n,c):c()},this.isEqualRects=function(e,t,n){var r,i,o,a,c=(null!==(i=(null!==(r=l.rects[t])&&void 0!==r?r:{})[n])&&void 0!==i?i:[]).map(function(e){return m(JSON.stringify(e))}),u=(null!=e?e:[]).map(function(e){return m(JSON.stringify(e))});return a=u,!(!s(o=c)||!s(a)||o.length!==a.length)&&o.every(function(e,t){return e===a[t]})},this.getNodeId=function(e){var t=l.growingIO.gioPlatform,n=l.getPagePath(e);switch(t){case"wx":case"qq":case"ks":case"jd":return e.__wxExparserNodeId__;case"my":case"tb":return e.$page?"".concat(e.$page.$id,"-").concat(e.$id):e.$id;case"swan":return n?u(m(n)):e.nodeId;case"tt":return n?u(m(n)):e.__nodeId__;case"xhs":return n?e.pageId:e.componentId}},this.rectObserve=function(e,n,r,i){var o,a,s=l.growingIO.gioPlatform;if("tt"===s&&n.__nodeId__||"ks"===s&&n.is||"xhs"===s&&n.componentId)return!1;var c=l.getNodeId(n),u=l.getOwnerPage(n,i),g=l.getPagePath(u),v=!1;if(g){var d=l.isEqualRects(e,g,c),p=null===(a=null===(o=l.observerIds[g])||void 0===o?void 0:o[c])||void 0===a?void 0:a._disconnected;v=!d||!1!==p}t.isArray(e)&&!t.isEmpty(e)&&!t.isNil(e[0])&&v&&(t.isEmpty(l.rects[g])&&(l.rects[g]={}),l.rects[g][c]=e,l.createObserver(n,r,u))},this.main=function(e,n){var r,i,o=l.growingIO.gioPlatform,a=l.getOwnerPage(e),s=l.isPageTarget(e)?t.isFunction(e.createSelectorQuery)?e.createSelectorQuery():null===(r=l.growingIO.minipInstance.minip)||void 0===r?void 0:r.createSelectorQuery():null===(i=l.growingIO.minipInstance.minip)||void 0===i?void 0:i.createSelectorQuery().in(e);["ks","qq"].includes(o)?(s.selectAll(".growing_collect_imp").boundingClientRect(function(r){var i=r[0],o=void 0===i?[]:i;o=t.isArray(o)?o:[o],v(o)||l.rectObserve(o,e,n,a)}),s.exec()):(s.selectAll(".growing_collect_imp").boundingClientRect(),s.exec(function(t){var r=t[0];v(r)||l.rectObserve(r,e,n,a)}))},this.createObserver=function(e,n,r){var i,o,a=l.growingIO,s=a.gioPlatform,c=a.minipInstance,u=((i={thresholds:[a.vdsConfig.impressionScale||1e-13]})[n]=!0,i);["tb","my"].includes(s)&&t.compareVersion(my.SDKVersion,"2.7.0")>=0&&(u.dataset=!0);var g=l.getNodeId(e),v=l.getOwnerPage(e,r),d=l.getPagePath(v);if(d){l.observerIds[d]||(l.observerIds[d]={});var f,m=l.observerIds[d][g];m&&!m._disconnected&&m.disconnect(),["swan","jd","xhs"].includes(s)?f=null===(o=c.minip)||void 0===o?void 0:o.createIntersectionObserver(e,u):(f=p(function(){return e.createIntersectionObserver(u)}))||(f=p(function(){var t;return null===(t=c.minip)||void 0===t?void 0:t.createIntersectionObserver(e,u)})),(null==f?void 0:f.relativeToViewport)?(f=f.relativeToViewport(),l.observerIds[d][g]=f,l.targetObserve(f,v)):t.consoleText("创建曝光监听失败,当前环境不支持 createIntersectionObserver: ".concat(s),"warn")}},this.targetObserve=function(e,n){var r=l.growingIO.vdsConfig,i=r.taro,a=r.impressionScale||1e-13;e.observe(".growing_collect_imp",function(e){if(!t.isEmpty(e)&&e.intersectionRatio>=a){var r=e.dataset;if(i&&t.isTaro3(i)&&(r=l.getTaro3Dataset(l.getPagePath(n),e.id)),!t.isObject(r))return void t.consoleText("曝光节点缺少有效的 dataset,已跳过本次采集!","warn");var u=l.getImpressionProperties(r),g=e.id;if(g){if("once"===r.gioImpType&&t.has(l.sentImps,g))return;l.sentImps[g]=u}if(u.eventName){var d=[];if(r.gioImpSendto){var f=r.gioImpSendto;s(f)?d=c(f):o(f)&&(d=c(p(function(){return JSON.parse(f)})||[]),v(d)&&f.split(",").forEach(function(e){(e=o(e)&&e.trim().replace("[","").replace("]",""))&&d.push(e)}))}l.buildImpEvent(u,d,n)}else t.consoleText("曝光事件格式不正确,事件名只能包含数字、字母和下划线,且不以数字开头!","warn")}})},this.getImpressionProperties=function(e){var i,a,s={eventName:void 0,properties:{}};if(!(null==e?void 0:e.gioImpTrack))return s;if(s.eventName=e.gioImpTrack,t.has(e,"gioImpAttrs"))s.properties=t.niceTry(function(){return t.isObject(e.gioImpAttrs)?e.gioImpAttrs:JSON.parse(e.gioImpAttrs)});else for(var c in e){var u=void 0,l=c.match(n);l&&"track"!==(u=t.lowerFirst(l[1]))&&(s.properties[u]=e[c])}return s.properties=t.limitObject(s.properties),i=s.eventName,a=function(){return s},(o(i)&&!v(i)&&i.match(r)?a():(console.log("%c[GrowingIO]:事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!","color: #EF4444"),!1))||(s.eventName=null,s={}),s},this.getTaro3Dataset=function(e,n){var r,i,o=null===(i=null===(r=l.growingIO)||void 0===r?void 0:r.taro3VMs)||void 0===i?void 0:i[e];if(!o)return!1;var a={},s=function(e){e.some(function(e){var r;return e.uid!==n&&e.sid!==n||-1>=(null===(r=e.props)||void 0===r?void 0:r.class.indexOf("growing_collect_imp"))||t.isEmpty(e.dataset)?!!Array.isArray(e.childNodes)&&s(e.childNodes):(a=e.dataset,!0)})};return s(o.childNodes),a},this.buildImpEvent=function(t,n,r){var i,o,s=t.eventName,c=t.properties,u=l.growingIO,g=u.trackingId,d=u.dataStore,p=d.eventContextBuilder,m=d.eventConverter,I=u.plugins,h=null===(i=l.growingIO.dataStore.eventHooks)||void 0===i?void 0:i.currentPage,O=function(){return p(g)},w=r&&(null==h?void 0:h.withPageContext)?h.withPageContext(r,O):O(),P=e({eventType:"CUSTOM",eventName:s},w);P.attributes=f(e(e({},null!==(o=P.attributes)&&void 0!==o?o:{}),a(c)&&!v(c)?c:{})),I.gioMultipleInstances&&!v(n)&&(P["&&sendTo"]=n),m(P)},this.pluginVersion="4.6.1",t=this.growingIO.utils,this.observerIds={},this.rects={},this.sentImps={};var g=this.growingIO,d=g.emitter,O=g.minipInstance;this.growingIO.updateImpression=function(e){e||(e=O.getCurrentPage()),O.initImpression(e)},d.on("MINIP_LIFECYCLE",function(e){var t,n=e.event,r=e.params,i=l.growingIO.minipInstance;if("Page onShowEnd"===n){var o=(null==r?void 0:r.page)||(null==r?void 0:r.instance)||i.getCurrentPage();l.traverseListen(o,o)}if(["Page onHide","Page onUnload"].includes(n)){var a=l.getPagePath((null==r?void 0:r.page)||(null==r?void 0:r.instance));Object.values(null!==(t=l.observerIds[a])&&void 0!==t?t:{}).forEach(function(e){return e.disconnect()})}})}};export{O as default};
@@ -1 +1 @@
1
- var n=function(){return n=Object.assign||function(n){for(var r,t=1,i=arguments.length;i>t;t++)for(var e in r=arguments[t])({}).hasOwnProperty.call(r,e)&&(n[e]=r[e]);return n},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var r=function(n){return"[object Object]"==={}.toString.call(n)&&!function(n){return["undefined","null"].includes(i(n))}(n)},t=function(n,e){if(!r(n))return!1;try{if("string"===i(e))return delete n[e];if("array"===i(e))return e.map(function(r){return delete n[r]});"object"===i(e)&&e.constructor===RegExp&&function(n){return r(n)?Object.keys(n):[]}(n).forEach(function(r){e.test(r)&&t(n,r)})}catch(n){return!1}},i=function(n){return{}.toString.call(n).slice(8,-1).toLowerCase()},e=function(n){try{return n()}catch(n){return}},o=function(){var n;return null!==(n=e(function(){var n;return null!==(n=e(function(){var n;return null!==(n=e(function(){return $global}))&&void 0!==n?n:global}))&&void 0!==n?n:window}))&&void 0!==n?n:globalThis},a=function(r){var a=this;this.growingIO=r,this.getTrackerType=function(n,r){return r.trackingId&&r.trackingId!==n?0:1},this.rewriteDataStore=function(){a.growingIO.dataStore.getTrackerVds=function(r){if(a.growingIO.trackingId===r){var i=n({},a.growingIO.vdsConfig);return t(i,"subInstance"),a.growingIO.plugins.gioTaobaoAdapter||t(i,"tbConfig"),i}return a.growingIO.subInstance[r]?n({},a.growingIO.subInstance[r]):void 0},a.growingIO.dataStore.initTrackerOptions=function(n){var r,i=a.growingIO.dataStore.initOptions(n),e=a.getTrackerType(n.trackingId,a.growingIO);return i.trackingId=n.trackingId,e?(a.growingIO.trackingId=n.trackingId,a.growingIO.vdsConfig=i,o().vdsConfig=i):(t(i,["autotrack","debug","forceLogin","impressionScale","keepAlive","mpx","originalSource","performance","pluginMode","sessionExpires","taro","taroVue","tbConfig","uniVue"]),a.growingIO.subInstance[n.trackingId]=i,(null===(r=o().vdsConfig)||void 0===r?void 0:r.subInstance)||(o().vdsConfig.subInstance={}),o().vdsConfig.subInstance[n.trackingId]=i),i},a.growingIO.dataStore.initTrackerHooker=function(n){var r,t,i,e=a.getTrackerType(n.trackingId,a.growingIO),o=a.growingIO,g=o.platformConfig,u=o.inPlugin,c=o.minipInstance,s=o.plugins,d=o.dataStore,I=n.uniVue,l=n.taro,f=n.mpx;(e||f)&&(I||l||(g.canHook=!0),u&&!["tbp","jdp"].includes(c.platform)||d.eventHooks.initEventHooks()),I&&(null===(r=null==s?void 0:s.gioUniAppAdapter)||void 0===r||r.main()),l&&(null===(t=null==s?void 0:s.gioTaroAdapter)||void 0===t||t.main()),f&&(null===(i=null==s?void 0:s.gioMpxAdapter)||void 0===i||i.main())};var r=a.growingIO.dataStore.eventConverter,g=a;a.growingIO.dataStore.eventConverter=function(){for(var o=this,a=[],u=0;arguments.length>u;u++)a[u]=arguments[u];var c=a[0];if("CUSTOM"===c.eventType){var s=[c.trackingId];e(function(){c["&&sendTo"].forEach(function(n){"string"===i(n)&&g.growingIO.dataStore.getTrackerVds(n)&&!s.includes(n)&&s.push(n)})}),t(c,"&&sendTo"),s.forEach(function(t){var i=g.growingIO.dataStore.eventContextBuilder,e=n(n({},c),i(t,void 0,c.trackingId!==t));e.attributes=n(n({},e.attributes),c.attributes),r.call(o,e)})}else r.call(this,c)}},this.onSendBefore=function(n){var r=n.eventsQueue,t=n.requestData;n.trackingId!==a.growingIO.trackingId&&a.growingIO.uploader.sendEvent(r,t)},this.pluginVersion="4.5.1",this.subTrackingIds=[],this.growingIO.emitter.on("ON_SDK_INITIALIZE_BEFORE",function(){a.growingIO.trackingId||a.rewriteDataStore(),a.growingIO.subInstance||(a.growingIO.subInstance={})}),this.growingIO.emitter.on("OPTION_INITIALIZED",function(n){var r=n.trackingId;a.growingIO.trackingId&&a.growingIO.trackingId!==r&&a.subTrackingIds.push(r)})},g={name:"gioMultipleInstances",method:a};export{a as GioMultipleInstances,g as default};
1
+ var n=function(){return n=Object.assign||function(n){for(var t,r=1,i=arguments.length;i>r;r++)for(var e in t=arguments[r])({}).hasOwnProperty.call(t,e)&&(n[e]=t[e]);return n},n.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t=function(n){return"[object Object]"==={}.toString.call(n)&&!function(n){return["undefined","null"].includes(i(n))}(n)},r=function(n,e){if(!t(n))return!1;try{if("string"===i(e))return delete n[e];if("array"===i(e))return e.map(function(t){return delete n[t]});"object"===i(e)&&e.constructor===RegExp&&function(n){return t(n)?Object.keys(n):[]}(n).forEach(function(t){e.test(t)&&r(n,t)})}catch(n){return!1}},i=function(n){return{}.toString.call(n).slice(8,-1).toLowerCase()},e=function(n){try{return n()}catch(n){return}},o=function(){var n;return null!==(n=e(function(){var n;return null!==(n=e(function(){var n;return null!==(n=e(function(){return $global}))&&void 0!==n?n:global}))&&void 0!==n?n:window}))&&void 0!==n?n:globalThis},a=function(t){var a=this;this.growingIO=t,this.dataStoreRewritten=!1,this.getTrackerType=function(n,t){return t.trackingId&&t.trackingId!==n?0:1},this.rewriteDataStore=function(){a.growingIO.dataStore.getTrackerVds=function(t){if(a.growingIO.trackingId===t){var i=n({},a.growingIO.vdsConfig);return r(i,"subInstance"),a.growingIO.plugins.gioTaobaoAdapter||r(i,"tbConfig"),i}return a.growingIO.subInstance[t]?n({},a.growingIO.subInstance[t]):void 0},a.growingIO.dataStore.initTrackerOptions=function(n){var t,i=a.growingIO.dataStore.initOptions(n),e=a.getTrackerType(n.trackingId,a.growingIO);return i.trackingId=n.trackingId,e?(a.growingIO.trackingId=n.trackingId,a.growingIO.vdsConfig=i,o().vdsConfig=i):(r(i,["autotrack","debug","forceLogin","impressionScale","keepAlive","mpvue","mpx","originalSource","performance","pluginMode","sessionExpires","taro","taroVue","tbConfig","uniVue"]),a.growingIO.subInstance[n.trackingId]=i,(null===(t=o().vdsConfig)||void 0===t?void 0:t.subInstance)||(o().vdsConfig.subInstance={}),o().vdsConfig.subInstance[n.trackingId]=i),i},a.growingIO.dataStore.initTrackerHooker=function(n){var t=a.getTrackerType(n.trackingId,a.growingIO),r=a.growingIO,i=r.platformConfig,e=r.inPlugin,o=r.minipInstance,g=r.plugins,u=r.dataStore,c=n.uniVue,s=n.taro,d=n.mpvue,I=n.mpx;return u.validateTrackerFramework(n),(t||I)&&(c||s||d||(i.canHook=!0),e&&!["tbp","jdp"].includes(o.platform)||u.eventHooks.initEventHooks()),c&&g.gioUniAppAdapter.main(),s&&g.gioTaroAdapter.main(),d&&g.gioMpvueAdapter.main(),I&&g.gioMpxAdapter.main(),!0};var t=a.growingIO.dataStore.eventConverter,g=a;a.growingIO.dataStore.eventConverter=function(){for(var o=this,a=[],u=0;arguments.length>u;u++)a[u]=arguments[u];var c=a[0];if("CUSTOM"===c.eventType){var s=[c.trackingId];e(function(){c["&&sendTo"].forEach(function(n){"string"===i(n)&&g.growingIO.dataStore.getTrackerVds(n)&&!s.includes(n)&&s.push(n)})}),r(c,"&&sendTo"),s.forEach(function(r){var i=g.growingIO.dataStore.eventContextBuilder,e=n(n({},c),i(r,{path:c.path,query:c.query,title:c.title,timestamp:c.timestamp},c.trackingId!==r));e.attributes=n(n({},e.attributes),c.attributes),t.call(o,e)})}else t.call(this,c)}},this.pluginVersion="4.6.1",this.subTrackingIds=[],this.growingIO.emitter.on("ON_SDK_INITIALIZE_BEFORE",function(){a.growingIO.trackingId||a.dataStoreRewritten||(a.rewriteDataStore(),a.dataStoreRewritten=!0),a.growingIO.subInstance||(a.growingIO.subInstance={})}),this.growingIO.emitter.on("SDK_INITIALIZED",function(n){var t=n.trackingId;a.growingIO.trackingId&&a.growingIO.trackingId!==t&&!a.subTrackingIds.includes(t)&&a.subTrackingIds.push(t)})},g={name:"gioMultipleInstances",method:a};export{a as GioMultipleInstances,g as default};
@@ -1 +1 @@
1
- var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;r>n;n++)for(var i in t=arguments[n])({}).hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;o>i;i++)!r&&i in t||(r||(r=[].slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||[].slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var n,r=function(e){return["undefined","null"].includes(P(e))},i=function(e){return"string"===P(e)},o=function(e){return"[object Object]"==={}.toString.call(e)&&!r(e)},a=function(e){return"[object RegExp]"==={}.toString.call(e)},s=function(e){return["function","asyncfunction"].includes(P(e))},u=function(e){return Array.isArray(e)&&"array"===P(e)},c=function(e){try{return Array.from(e)[0]}catch(e){return}},l=function(e,t){if(void 0===t&&(t=!1),u(e)){for(var n=0,r=[],i=0,o=e;i<o.length;i++){var a=o[i];a&&!v(a)&&(r[n++]=a),t&&0===a&&(r[n++]=a)}return r}return e},d=function(e){return r(e)?"":"".concat(e)},h={}.hasOwnProperty,f=function(e,t){return null!=e&&("object"==typeof e||"function"==typeof e)&&h.call(e,t)},p=function(e){return o(e)?Object.keys(e):[]},m=function(e,t){p(e).forEach(function(n){return t(e[n],n)})},g=function(e,t){if(!o(e))return!1;try{if("string"===P(t))return delete e[t];if("array"===P(t))return t.map(function(t){return delete e[t]});"object"===P(t)&&t.constructor===RegExp&&p(e).forEach(function(n){t.test(n)&&g(e,n)})}catch(e){return!1}},v=function(e){return u(e)?0===e.length:o(e)?0===p(e).length:!e},P=function(e){return{}.toString.call(e).slice(8,-1).toLowerCase()},E=function(e){var t=function(e){if(i(e)){var t=e.indexOf("?");return-1!==t?[e.substring(0,t),e.substring(t+1)]:[e,""]}return["",""]}(e)[0];return((null==t?void 0:t.replace(/^\/+/,""))||"").replace(/\.html$/,"")},b=function(e,t,n){if("number"==typeof e)return"number"!=typeof t||t>e?"number"!=typeof n||n>e?0:e-n:e-t},w=function(e){var t={};return o(e)&&(g(e,"&&sendTo"),m(e,function(e,n){var i=d(n).slice(0,100);o(e)?t[i]=w(e):u(e)?(t[i]=l(e.slice(0,100),!0),t[i]=t[i].join("||").slice(0,1e3)):function(e){return"date"===P(e)}(e)?t[i]=function(e){function t(e){return 10>e?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+" "+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+t(e.getMilliseconds())}(e):t[i]=r(e)?"":d(e).slice(0,1e3)})),t},S="SDK_INITIALIZED",y=function(t){var n,r,i,o,a=this;this.growingIO=t,this.listenerSet=!1,this.setListeners=function(){var e,t,n;a.listenerSet||(a.minipInst.canIUse("onError")&&(null===(e=a.minipInst)||void 0===e||e.onError(function(e){a.errorParse(e)})),a.minipInst.canIUse("onUnhandledRejection")&&(null===(t=a.minipInst)||void 0===t||t.onUnhandledRejection(function(e){e.reason.stack&&a.errorParse(e.reason.stack,e.reason.message)})),a.minipInst.canIUse("onLazyLoadError")&&(null===(n=a.minipInst)||void 0===n||n.onLazyLoadError(function(e){a.buildErrorEvent({error_type:e.errMsg,error_content:d(e.subpackage)})}))),a.listenerSet=!0},this.hookNavigate=function(){var t=a;["switchTab","reLaunch","redirectTo","navigateTo","navigateBack"].forEach(function(n){var r=a.minipInst[n];Object.defineProperty(a.minipInst,n,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var i,o=[],a=0;arguments.length>a;a++)o[a]=arguments[a];var s=null!==(i=o[0])&&void 0!==i?i:{},u=null==s?void 0:s.fail;return r.call(this,e(e({},s),{fail:function(e){var r;if(null===(r=t.growingIO.plugins.gioPerformance)||void 0===r||r.buildPerfEvent("Error",{error_type:"".concat(n," Error"),error_content:e.errMsg}),"function"==typeof u)return u(e)}}))}})})},this.errorParse=function(e,t){var n,r,i=e.split("\n");i.length?(i.find(function(e,t){var o=e.match(/at (.*?) \((.*):(\d{1,}):(\d{1,})\)/);if(u(o))return n=i[t-1],r=e.trim(),o.length}),n||(n=i[0]),r||(r=i[1])):(n=t||"Error",r=e.substring(0,100)),a.buildErrorEvent({error_type:t||n,error_content:r})},this.minipInst=this.growingIO.minipInstance.minip,this.cacheQueue=[],this.buildErrorEvent=function(e){var t;return null===(t=a.growingIO.plugins.gioPerformance)||void 0===t?void 0:t.buildPerfEvent("apm_system_error",e)},this.setListeners(),this.hookNavigate(),s(null===(n=this.minipInst)||void 0===n?void 0:n.onAppShow)&&(null===(r=this.minipInst)||void 0===r||r.onAppShow(this.setListeners)),s(null===(i=this.minipInst)||void 0===i?void 0:i.onAppHide)&&(null===(o=this.minipInst)||void 0===o||o.onAppHide(function(){a.minipInst.canIUse("offError")&&a.minipInst.offError(),a.minipInst.canIUse("offUnhandledRejection")&&a.minipInst.offUnhandledRejection(),a.minipInst.canIUse("offLazyLoadError")&&a.minipInst.offLazyLoadError(),a.listenerSet=!1})),this.growingIO.emitter.on(S,function(){v(a.cacheQueue)||a.cacheQueue.forEach(function(e){a.buildErrorEvent(e)})})},T=function(t){var n=this;this.monitor=t,this.markIfNeeded=function(t){n.monitor.referrerPath||"cold"!==n.monitor.bootType||(n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{isColdStart:!0,coldAppLaunch:n.monitor.appPerf.onLaunch,coldAppStartTime:n.monitor.appPerf.appStartTime}))},this.isVisit=function(e){return!(!e.isColdStart&&(n.monitor.referrerPath||"cold"!==n.monitor.bootType))},this.appendMetrics=function(e,t,r){var i,o,a=t.onReadyEnd,s=null!==(i=t.coldAppLaunch)&&void 0!==i?i:n.monitor.appPerf.onLaunch,u=null!==(o=t.coldAppStartTime)&&void 0!==o?o:n.monitor.appPerf.appStartTime;e.page_launch_duration=b(a,s,r),e.reboot_duration=b(a,u,s),e.reboot_mode="cold",n.monitor.bootType="warm"}},I=["firstContentfulPaint","largestContentfulPaint","route"],O="firstContentfulPaint",k="largestContentfulPaint",L=["onShow","onShowEnd","onReady","onReadyEnd"],A=["onShowEnd","onReadyEnd"],C=["onHide","onUnload"],R=function(t){var n=this;this.monitor=t,this.observerWaitTimers={},this.init=function(){if(n.canObservePerformance()){var e=n.monitor.minipInst.getPerformance(),t=null==e?void 0:e.createObserver(n.handleObserverEntries);null==t||t.observe({entryTypes:["render","script","navigation"]})}},this.canObservePerformance=function(){var e=n.monitor.minipInst,t="function"==typeof(null==e?void 0:e.getPerformance),r="function"!=typeof(null==e?void 0:e.canIUse)||e.canIUse("getPerformance");return t&&r},this.handleObserverEntries=function(e){var t=n.pickObserverEntries(e),r=n.getObserverPath(c(t.routeEntries),c(t.fcpEntries),c(t.lcpEntries),t.launchEntry),i={};n.markTouchedPath(i,r),n.handleLaunch(t.launchEntry);for(var o=0,a=t.fcpEntries;o<a.length;o++){var s=a[o];n.markTouchedPath(i,n.handleFCP(s,r))}for(var u=0,l=t.lcpEntries;u<l.length;u++)s=l[u],n.markTouchedPath(i,n.handleLCP(s,r));for(var d=0,h=t.routeEntries;d<h.length;d++)s=h[d],n.markTouchedPath(i,n.handleRoute(s,r));n.finalizeTouchedObserverPaths(i)},this.pickObserverEntries=function(e){return{launchEntry:n.getEntry(e,["appLaunch"]),fcpEntries:n.getEntries(e,[O]),lcpEntries:n.getEntries(e,[k]),routeEntries:n.getEntries(e,["route"])}},this.finalizeTouchedObserverPaths=function(e){m(e,function(e,t){n.markObserverRound(t)}),m(e,function(e,t){n.finalizeObserverRound(t)})},this.handleLaunch=function(t){n.hasPerformanceEntry(t)&&(n.monitor.appPerf=e(e({},n.monitor.appPerf),{appStartTime:t.startTime,appDuration:t.duration,firstPath:t.path}))},this.handleFCP=function(e,t){if(n.hasPaintEntry(e))return n.recordObserverMetric(e,t,O,{FCPStartTime:e.startTime})},this.handleLCP=function(e,t){if(n.hasPaintEntry(e))return n.recordObserverMetric(e,t,k,{LCPStartTime:e.startTime})},this.handleRoute=function(e,t){if(n.hasPerformanceEntry(e))return n.recordObserverMetric(e,t,"route",{navigationStart:e.startTime,routeDuration:e.duration})},this.recordObserverMetric=function(t,r,i,o){var a=n.extractEntryPath(t)||r;if(a)return n.monitor.ensurePagePerf(a),n.monitor.pagePerf[a]=e(e({},n.monitor.pagePerf[a]),o),n.markEntryHandled(a,i),a},this.markObserverRound=function(e){n.monitor.ensurePagePerf(e),n.monitor.pagePerf[e].firstObserverTimestamp||(n.monitor.pagePerf[e].firstObserverTimestamp=Date.now()),n.monitor.pagePerf[e].observerTriggerCount=(n.monitor.pagePerf[e].observerTriggerCount||0)+1},this.finalizeObserverRound=function(e){n.monitor.ensurePagePerf(e),n.monitor.pagePerf[e].observerProcessed=0===n.getWaitableMissingObserverEntries(e).length,n.scheduleObserverFallback(e),n.monitor.tryHandleEvent(e)},this.scheduleObserverFallback=function(e){n.monitor.ensurePagePerf(e);var t=n.monitor.pagePerf[e],r=n.getWaitableMissingObserverEntries(e).length>0,i=n.shouldWaitAlipayObserverRound(t);if(r||i){if(!t.observerFallbackExpired&&!n.observerWaitTimers[e]){var o=Date.now()-(t.firstObserverTimestamp||Date.now()),a=Math.max(0,2e3-o);n.observerWaitTimers[e]=setTimeout(function(){delete n.observerWaitTimers[e],n.markObserverFallbackExpired(e),n.monitor.tryHandleEvent(e)},a)}}else n.clearObserverWaitTimer(e)},this.shouldWaitAlipayObserverRound=function(e){if(void 0===e&&(e={}),!n.isAlipay())return!1;var t=e.observerTriggerCount||0;return 2>t||3>t&&!e.observerProcessed},this.markObserverFallbackExpired=function(e){n.monitor.ensurePagePerf(e);var t=n.monitor.pagePerf[e],r=t.handledEntries||{};I.forEach(function(e){r[e]=!0}),t.handledEntries=r,t.observerProcessed=!0,t.observerFallbackExpired=!0},this.clearObserverWaitTimer=function(e){n.observerWaitTimers[e]&&(clearTimeout(n.observerWaitTimers[e]),delete n.observerWaitTimers[e])},this.hasProcessedObserverEntries=function(e){var t,r,i;return!(n.canObservePerformance()&&(!(null===(t=n.monitor.pagePerf[e])||void 0===t?void 0:t.observerProcessed)||n.isAlipay()&&2>((null===(r=n.monitor.pagePerf[e])||void 0===r?void 0:r.observerTriggerCount)||0)&&!(null===(i=n.monitor.pagePerf[e])||void 0===i?void 0:i.observerFallbackExpired)))},this.hasPerformanceEntry=function(e){return!v(e)||"number"==typeof(null==e?void 0:e.startTime)||"number"==typeof(null==e?void 0:e.duration)},this.hasPaintEntry=function(e){return n.hasPerformanceEntry(e)&&"number"==typeof(null==e?void 0:e.startTime)},this.getEntries=function(e,t){for(var r,i=[],o=0,a=t;o<a.length;o++)for(var s=a[o],u=0,c=(null===(r=null==e?void 0:e.getEntriesByName)||void 0===r?void 0:r.call(e,s))||[];u<c.length;u++){var l=c[u];n.hasPerformanceEntry(l)&&i.push(l)}return i},this.getEntry=function(e,t){return c(n.getEntries(e,t))},this.extractEntryPath=function(e){return E((null==e?void 0:e.path)||(null==e?void 0:e.route)||(null==e?void 0:e.pagePath)||(null==e?void 0:e.pageURL)||(null==e?void 0:e.url))},this.getObserverPath=function(){for(var e=[],t=0;arguments.length>t;t++)e[t]=arguments[t];for(var r=0,i=e;r<i.length;r++){var o=i[r],a=n.extractEntryPath(o);if(a)return a}return n.getPendingObserverPath()||E(n.monitor.getCurrentPath())},this.getPendingObserverPath=function(){var e="",t=1/0;return m(n.monitor.pagePerf,function(r,i){if(r&&!r.eventSent&&!n.hasProcessedObserverEntries(i)&&n.monitor.hasReadyPagePerf(i)){var o=n.monitor.getPageReadyTimestamp(i);"number"==typeof o&&t>o&&(t=o,e=i)}}),e},this.getMissingObserverEntries=function(e){var t,r=(null===(t=n.monitor.pagePerf[e])||void 0===t?void 0:t.handledEntries)||{};return I.filter(function(e){return!r[e]})},this.getWaitableMissingObserverEntries=function(e){var t=n.getMissingObserverEntries(e);return n.shouldWaitPaintEntries()?t.filter(function(e){return e===O||e===k}):[]},this.shouldWaitPaintEntries=function(){return n.isWeChat()||n.isAlipay()},this.isAlipay=function(){return"alip"===n.monitor.growingIO.minipInstance.platform},this.isWeChat=function(){return"MinP"===n.monitor.growingIO.minipInstance.platform},this.markEntryHandled=function(e,t){if(e){n.monitor.ensurePagePerf(e);var r=n.monitor.pagePerf[e],i=r.handledEntries||{};i[t]=!0,r.handledEntries=i}},this.markTouchedPath=function(e,t){t&&(e[t]=!0)}},W=function(e){this.monitor=e,this.appendMetrics=function(e,t,n){e.page_launch_duration=b(t.onReadyEnd,t.navigationStart,n)}},M=function(t){var n=this;this.monitor=t,this.lastWarm=!1,this.warmLandingPath="",this.appShowEndFallbackTimer=null,this.staleMarkerTimer=null,this.syntheticAppShowEnd=void 0,this.handleAppHide=function(){n.lastWarm=!1,n.warmLandingPath="",n.syntheticAppShowEnd=void 0,n.clearAppShowEndFallback(),n.clearStaleMarkerCleanup(),n.monitor.bootType="warm"},this.handleAppShow=function(e,t){n.isAppWarmForeground(e)&&(n.cacheLandingPath(t),n.lastWarm=!0,n.scheduleAppShowEndFallback(),n.scheduleStaleMarkerCleanup())},this.handleAppShowEnd=function(e,t){n.isAppWarmForeground(e)&&(n.clearAppShowEndFallback(),n.cacheLandingPath(t),n.hasPendingWarmStart()||(n.lastWarm=!0,n.scheduleStaleMarkerCleanup()),n.completeAfterAppShowEnd())},this.markIfMatched=function(t,r){var i;return!(!n.lastWarm||n.warmLandingPath&&n.warmLandingPath!==t||(null===(i=n.monitor.pagePerf[t])||void 0===i?void 0:i.eventSent)||(n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{isWarmStart:!0,warmAppShowEnd:null!=r?r:n.getCurrentAppShowEnd(),warmWaitReadyEnd:n.hasNewLoadAfterWarmStart(t)}),n.consumeMarker(),0))},this.isVisit=function(e){return!(!e.isWarmStart||!n.hasAppShowEnd(e))},this.canSend=function(e){var t=n.monitor.pagePerf[e];return!!(t&&t.isWarmStart&&n.hasAppShowEnd(t)&&(t.warmWaitReadyEnd?t.onReadyEnd:t.onShowEnd))},this.getReadyTimestamp=function(e){return e.warmWaitReadyEnd?e.onReadyEnd:e.onShowEnd},this.appendMetrics=function(e,t){var r=n.getPageEnd(t),i=t.warmAppShowEnd,o=n.getCurrentAppShow();e.page_launch_duration=b(r,i,o),e.reboot_duration=b(r,i,o),e.reboot_mode="warm"},this.getPageEnd=function(e){return e.warmWaitReadyEnd?e.onReadyEnd:e.onShowEnd},this.scheduleAppShowEndFallback=function(){n.clearAppShowEndFallback(),n.appShowEndFallbackTimer=setTimeout(function(){var e;if(n.appShowEndFallbackTimer=null,(n.lastWarm||n.hasPendingWarmStart())&&!n.getCurrentAppShowEnd()){var t=null!==(e=n.monitor.appPerf.onShow)&&void 0!==e?e:Date.now();n.syntheticAppShowEnd=t,n.completeAfterAppShowEnd(t)}},0)},this.clearAppShowEndFallback=function(){n.appShowEndFallbackTimer&&(clearTimeout(n.appShowEndFallbackTimer),n.appShowEndFallbackTimer=null)},this.scheduleStaleMarkerCleanup=function(){n.clearStaleMarkerCleanup(),n.staleMarkerTimer=setTimeout(function(){n.staleMarkerTimer=null,n.lastWarm=!1,n.warmLandingPath=""},5e3)},this.clearStaleMarkerCleanup=function(){n.staleMarkerTimer&&(clearTimeout(n.staleMarkerTimer),n.staleMarkerTimer=null)},this.completeAfterAppShowEnd=function(e){var t=n.getPendingPath();if(t)return n.bindAppShowEnd(t,e),void n.monitor.tryHandleEvent(t);var r=E(n.monitor.getCurrentPath());r&&n.lastWarm&&n.hasPageShownAfterWarmStart(r)&&n.markIfMatched(r,e)&&n.monitor.tryHandleEvent(r)},this.getPendingPath=function(){var e=n.getWarmStartBeginTimestamp(),t="",r=1/0;return m(n.monitor.pagePerf,function(i,o){(null==i?void 0:i.isWarmStart)&&!n.hasAppShowEnd(i)&&"number"==typeof i.onShowEnd&&("number"==typeof e&&i.onShowEnd<e||i.onShowEnd<r&&(r=i.onShowEnd,t=o))}),t},this.bindAppShowEnd=function(t,r){n.monitor.ensurePagePerf(t),n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{warmAppShowEnd:null!=r?r:n.getCurrentAppShowEnd()})},this.hasPendingWarmStart=function(){var e=n.getWarmStartBeginTimestamp(),t=!1;return m(n.monitor.pagePerf,function(r){(null==r?void 0:r.isWarmStart)&&!n.hasAppShowEnd(r)&&("number"==typeof e&&"number"==typeof r.onShowEnd&&r.onShowEnd<e||(t=!0))}),t},this.hasAppShowEnd=function(e){return"number"==typeof(null==e?void 0:e.warmAppShowEnd)},this.cacheLandingPath=function(e){var t=n.getLandingPath(e);t&&(n.warmLandingPath=t)},this.getLandingPath=function(e){var t,n=(null===(t=null==e?void 0:e.arguments)||void 0===t?void 0:t[0])||e;return E(null==n?void 0:n.path)},this.consumeMarker=function(){n.lastWarm&&(n.lastWarm=!1),n.warmLandingPath="",n.clearStaleMarkerCleanup()},this.isAppWarmForeground=function(e){return"number"==typeof n.monitor.appPerf.onHide&&e>=n.monitor.appPerf.onHide},this.getWarmStartBeginTimestamp=function(){var e,t;return null!==(t=null!==(e=n.monitor.appPerf.onHide)&&void 0!==e?e:n.monitor.appPerf.onShow)&&void 0!==t?t:n.monitor.appPerf.onShowEnd},this.getCurrentAppShowEnd=function(){var e=n.getWarmStartBeginTimestamp(),t=n.monitor.appPerf.onShowEnd;if("number"==typeof t&&("number"!=typeof e||t>=e))return t;var r=n.syntheticAppShowEnd;return"number"!=typeof r||"number"==typeof e&&e>r?void 0:r},this.getCurrentAppShow=function(){var e=n.monitor.appPerf.onShow,t=n.monitor.appPerf.onHide;if("number"==typeof e&&("number"!=typeof t||e>=t))return e},this.hasPageShownAfterWarmStart=function(e){var t=n.monitor.pagePerf[e],r=n.getWarmStartBeginTimestamp();return"number"==typeof(null==t?void 0:t.onShowEnd)&&"number"==typeof r&&t.onShowEnd>=r},this.hasNewLoadAfterWarmStart=function(e){var t=n.monitor.pagePerf[e],r=n.getWarmStartBeginTimestamp();return"number"==typeof(null==t?void 0:t.onLoad)&&"number"==typeof r&&t.onLoad>=r}},x=function(t){var n=this;this.growingIO=t,this.appPerf={},this.pagePerf={},this.bootType="cold",this.referrerPath="",this.initLifecycleListener=function(){n.growingIO.emitter.on("MINIP_LIFECYCLE",n.handleLifecycleEvent)},this.handleLifecycleEvent=function(e){var t=e.event,r=e.timestamp,i=e.params,o=t.split(" "),a=o[0],s=o[1];"App"!==a?"Page"===a&&n.handlePageLifecycle(s,r,i):n.handleAppLifecycle(s,r,i)},this.handleAppLifecycle=function(t,r,i){var o;n.appPerf=e(e({},n.appPerf),((o={})[t]=r,o)),"onHide"!==t?"onShow"!==t?"onShowEnd"===t&&n.warmStart.handleAppShowEnd(r,i):n.warmStart.handleAppShow(r,i):n.warmStart.handleAppHide()},this.handlePageLifecycle=function(e,t,r){var i=n.getLifecyclePath(r);i&&(n.shouldResetForNewVisit(i,e)&&n.resetPagePerf(i),n.recordPageLifecycle(i,e,t),n.shouldCachePageContext(e)&&n.cachePageContext(i),"onShowEnd"===e&&(n.coldStart.markIfNeeded(i),n.warmStart.markIfMatched(i)),n.shouldCheckSendOnLifecycle(e)&&n.tryHandleEvent(i),n.shouldUpdateReferrer(e)&&(n.referrerPath=i))},this.getLifecyclePath=function(e){var t=(null==e?void 0:e.page)||(null==e?void 0:e.instance);return E(null==t?void 0:t.route)||E(n.getCurrentPath())},this.shouldResetForNewVisit=function(e,t){var r=n.pagePerf[e];return!!r&&("onLoad"===t?!!(r.onLoad||r.onShow||r.onReady||r.onHide||r.onUnload||r.eventSent):"onShow"===t&&!!(r.onHide||r.onUnload||r.eventSent))},this.resetPagePerf=function(e){n.observer.clearObserverWaitTimer(e),n.pagePerf[e]={path:e}},this.recordPageLifecycle=function(t,r,i){var o;n.ensurePagePerf(t),n.pagePerf[t]=e(e({},n.pagePerf[t]),((o={})[r]=i,o))},this.cachePageContext=function(t){var r=n.growingIO.dataStore.eventHooks.currentPage,i=r.getPagePath();n.ensurePagePerf(t),n.pagePerf[t]=e(e({},n.pagePerf[t]),{pagePath:t,pageQuery:i===t?r.getPageQuery():"",pageTitle:i===t?r.getPageTitle():""})},this.ensurePagePerf=function(e){n.pagePerf[e]||(n.pagePerf[e]={path:e})},this.tryHandleEvent=function(e){return!(!e||!n.hasReadyPagePerf(e)||!n.warmStart.isVisit(n.pagePerf[e])&&!n.observer.hasProcessedObserverEntries(e))&&n.handleEvent(e)},this.handleEvent=function(e){var t;if(null===(t=n.pagePerf[e])||void 0===t?void 0:t.eventSent)return!1;var r=n.pagePerf[e]||{},i=n.buildPerfData(e);return n.cleanPerfData(i),!!f(i,"page_launch_duration")&&(n.emitPerfEvent(e,r,i),n.observer.clearObserverWaitTimer(e),n.pagePerf[e].eventSent=!0,!0)},this.buildPerfData=function(e){var t=n.pagePerf[e]||{},r={title:t.pageTitle||""},i=t.onLoad;return n.appendPaintMetrics(r,t,i),n.warmStart.isVisit(t)?n.warmStart.appendMetrics(r,t):n.coldStart.isVisit(t)?n.coldStart.appendMetrics(r,t,i):n.referrerPath&&n.pageLoad.appendMetrics(r,t,i),r},this.appendPaintMetrics=function(e,t,n){"number"==typeof t.FCPStartTime&&(e.first_contentful_paint_duration=b(t.FCPStartTime,n)),"number"==typeof t.LCPStartTime&&(e.largest_contentful_paint_duration=b(t.LCPStartTime,n))},this.cleanPerfData=function(e){m(e,function(t,r){n.isInvalidPerfValue(t)&&g(e,r)}),e.reboot_mode&&!f(e,"reboot_duration")&&g(e,"reboot_mode")},this.isInvalidPerfValue=function(e){return null===e||"null"===e||"NaN"===e||"number"==typeof e&&isNaN(e)},this.emitPerfEvent=function(e,t,r){n.buildMonitorEvent(r,{timestamp:+Date.now(),path:t.pagePath||e,query:t.pageQuery||"",title:r.title})},this.getCurrentPath=function(){return n.growingIO.minipInstance.getCurrentPath()},this.hasReadyPagePerf=function(e){var t=n.pagePerf[e];return!!t&&(t.isWarmStart?n.warmStart.canSend(e):!!t.onReadyEnd)},this.getPageReadyTimestamp=function(e){var t=n.pagePerf[e];if(t)return n.warmStart.canSend(e)?n.warmStart.getReadyTimestamp(t):t.onReadyEnd},this.shouldCachePageContext=function(e){return L.includes(e)},this.shouldCheckSendOnLifecycle=function(e){return A.includes(e)},this.shouldUpdateReferrer=function(e){return C.includes(e)},this.minipInst=this.growingIO.minipInstance.minip,this.observer=new R(this),this.coldStart=new T(this),this.warmStart=new M(this),this.pageLoad=new W(this),this.buildMonitorEvent=function(e,t){var r;return null===(r=n.growingIO.plugins.gioPerformance)||void 0===r?void 0:r.buildPerfEvent("apm_app_launch",e,t)},this.observer.init(),this.initLifecycleListener()},_=function(t,n){void 0===n&&(n={});var o,s=this;this.growingIO=t,this.options=n,this.verifyUrl=function(e){if(e.indexOf(s.gdpRequestURL)>-1)return!0;if(u(s.excludeRegExp)){var t=l(s.excludeRegExp.map(function(t){return a(t)?t.test(e):i(t)?e.indexOf(t)>-1:void 0}));return!v(t)}return i(s.excludeRegExp)?e.indexOf(s.excludeRegExp)>-1:!!a(s.excludeRegExp)&&s.excludeRegExp.test(e)},this.hookRequest=function(){var t=s;["request","downloadFile","uploadFile"].forEach(function(n){var r=s.minipInst[n];Object.defineProperty(s.minipInst,n,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var i=[],o=0;arguments.length>o;o++)i[o]=arguments[o];var a=i[0],s=a.url;if(t.verifyUrl(s))return r.call(this,a);var u={header:a.header||{},url:a.url};switch(n){case"request":var c=a.method;u=e(e({},u),{method:c});break;case"downloadFile":case"uploadFile":var l=a.filePath;u=e(e({},u),{filePath:l,method:"downloadFile"===n?"GET":"POST"})}var d=a.fail,h=a.success;return u.startTime=Date.now(),r.call(this,e(e({},a),{success:function(e){if(u.endTime=Date.now(),t.networkPerfBuilder(e,u),"function"==typeof h)return h(e)},fail:function(e){var n;if(u.endTime=Date.now(),null===(n=t.growingIO.plugins.gioPerformance)||void 0===n||n.buildPerfEvent("Error",{error_type:e.errMsg,error_content:u.url}),"function"==typeof d)return d(e)}}))}})})},this.networkPerfBuilder=function(e,t){var n=e.profile,i=void 0===n?{}:n,o=e.statusCode,a=void 0===o?0:o,u=e.errMsg,c=t.url,l=t.filePath,d=t.method,h=i.redirectStart,f=i.redirectEnd,p=i.fetchStart,P=i.domainLookUpStart,E=i.domainLookUpEnd,b=i.connectStart,w=i.connectEnd,S=i.requestStart,y=i.responseStart,T=i.responseEnd,I=!v(i),O={url:c,filePath:l,method:d,statusCode:a,message:u,redirect:I?f-h:0,cache:I?P-p:0,dns:I?E-P:0,tcp:I?w-b:0,request:I?y-S:0,response:I?T-y:0,duration:I?T-p:t.endTime-t.startTime};m(O,function(e,t){return(""===e||r(e))&&g(O,t)}),s.buildNetworkEvent(O)},this.minipInst=this.growingIO.minipInstance.minip,this.buildNetworkEvent=function(e){var t;if(n.network){var r=e.duration,i=e.url,o=e.method,a=e.statusCode;null===(t=s.growingIO.plugins.gioPerformance)||void 0===t||t.buildPerfEvent("apm_network_request",{response_duration:r,request_address:i,request_method:o,http_code:a})}},(null===(o=this.options.network)||void 0===o?void 0:o.exclude)&&(this.excludeRegExp=this.options.network.exclude),this.hookRequest();var c=this,d=this.growingIO.uploader.generateURL;this.growingIO.uploader.generateURL=function(){var e=d.apply(this,arguments);return arguments[0]===c.growingIO.trackingId&&(c.gdpRequestURL=e),e}},F={name:"gioPerformance",method:function(r,i){void 0===i&&(i={});var o,a=this;this.growingIO=r,this.options=i,this.init=function(){var e=a.growingIO.vdsConfig.dataCollect,t=a.options,n=t.monitor,r=t.exception,i=t.network;n&&(a.monitor=new x(a.growingIO)),r&&(a.exception=new y(a.growingIO)),i&&(a.network=new _(a.growingIO,a.options)),e&&a.sendCacheQuene()},this.sendCacheQuene=function(){n.isEmpty(a.cacheQueue)||(a.cacheQueue.forEach(function(e){a.buildPerfEvent(e.eventName,e.attributes,e.extra)}),a.cacheQueue=[])},this.buildPerfEvent=function(r,i,o){var s,u=a.growingIO,c=u.dataStore,l=c.eventContextBuilder,d=c.eventConverter,h=u.gioSDKInitialized,f=u.vdsConfig;if(!h||!f.dataCollect)return a.cacheQueue=t(t([],a.cacheQueue,!0),[{eventName:r,attributes:i,extra:o}],!1),!1;n.forEach(i,function(e,t){var r=Number.isNaN(e)||n.isNil(e)||0>Number(e)?0:e;i[t]=n.fixed(r,0)});var p=e({eventType:"CUSTOM",eventName:r,attributes:i},l(a.growingIO.trackingId));p.attributes=w(e(e({},null!==(s=p.attributes)&&void 0!==s?s:{}),i)),v(o)||(p=e(e({},p),o)),d(p)},this.pluginVersion="4.5.1",n=this.growingIO.utils,this.options=e({monitor:!0,exception:!0,network:!1},this.options),this.cacheQueue=[],this.growingIO.emitter.on(S,function(e){if(e.trackingId===a.growingIO.trackingId){var t=e.performance,n=t.monitor,r=t.exception,i=t.network;n!==a.options.monitor&&(a.options.monitor=n),r!==a.options.exception&&(a.options.exception=r),i!==a.options.network&&(a.options.network=i),a.init()}}),null===(o=this.growingIO.emitter)||void 0===o||o.on("SESSIONID_UPDATE",function(){var e=a.growingIO,t=e.trackingId;(0,e.getOption)(t,"dataCollect")&&a.sendCacheQuene()})}};export{F as default};
1
+ var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;r>n;n++)for(var i in t=arguments[n])({}).hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;o>i;i++)!r&&i in t||(r||(r=[].slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||[].slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var n,r=function(e){return["undefined","null"].includes(P(e))},i=function(e){return"string"===P(e)},o=function(e){return"[object Object]"==={}.toString.call(e)&&!r(e)},a=function(e){return"[object RegExp]"==={}.toString.call(e)},s=function(e){return["function","asyncfunction"].includes(P(e))},u=function(e){return Array.isArray(e)&&"array"===P(e)},c=function(e){try{return Array.from(e)[0]}catch(e){return}},l=function(e,t){if(void 0===t&&(t=!1),u(e)){for(var n=0,r=[],i=0,o=e;i<o.length;i++){var a=o[i];a&&!v(a)&&(r[n++]=a),t&&0===a&&(r[n++]=a)}return r}return e},d=function(e){return r(e)?"":"".concat(e)},h={}.hasOwnProperty,f=function(e,t){return null!=e&&("object"==typeof e||"function"==typeof e)&&h.call(e,t)},p=function(e){return o(e)?Object.keys(e):[]},m=function(e,t){p(e).forEach(function(n){return t(e[n],n)})},g=function(e,t){if(!o(e))return!1;try{if("string"===P(t))return delete e[t];if("array"===P(t))return t.map(function(t){return delete e[t]});"object"===P(t)&&t.constructor===RegExp&&p(e).forEach(function(n){t.test(n)&&g(e,n)})}catch(e){return!1}},v=function(e){return u(e)?0===e.length:o(e)?0===p(e).length:!e},P=function(e){return{}.toString.call(e).slice(8,-1).toLowerCase()},E=function(e){var t=function(e){if(i(e)){var t=e.indexOf("?");return-1!==t?[e.substring(0,t),e.substring(t+1)]:[e,""]}return["",""]}(e)[0];return((null==t?void 0:t.replace(/^\/+/,""))||"").replace(/\.html$/,"")},b=function(e,t,n){if("number"==typeof e)return"number"!=typeof t||t>e?"number"!=typeof n||n>e?0:e-n:e-t},w=function(e){var t={};return o(e)&&(g(e,"&&sendTo"),m(e,function(e,n){var i=d(n).slice(0,100);o(e)?t[i]=w(e):u(e)?(t[i]=l(e.slice(0,100),!0),t[i]=t[i].join("||").slice(0,1e3)):function(e){return"date"===P(e)}(e)?t[i]=function(e){function t(e){return 10>e?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+" "+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+t(e.getMilliseconds())}(e):t[i]=r(e)?"":d(e).slice(0,1e3)})),t},S="SDK_INITIALIZED",y=function(t){var n,r,i,o,a=this;this.growingIO=t,this.listenerSet=!1,this.setListeners=function(){var e,t,n;a.listenerSet||(a.minipInst.canIUse("onError")&&(null===(e=a.minipInst)||void 0===e||e.onError(function(e){a.errorParse(e)})),a.minipInst.canIUse("onUnhandledRejection")&&(null===(t=a.minipInst)||void 0===t||t.onUnhandledRejection(function(e){e.reason.stack&&a.errorParse(e.reason.stack,e.reason.message)})),a.minipInst.canIUse("onLazyLoadError")&&(null===(n=a.minipInst)||void 0===n||n.onLazyLoadError(function(e){a.buildErrorEvent({error_type:e.errMsg,error_content:d(e.subpackage)})}))),a.listenerSet=!0},this.hookNavigate=function(){var t=a;["switchTab","reLaunch","redirectTo","navigateTo","navigateBack"].forEach(function(n){var r=a.minipInst[n];s(r)&&Object.defineProperty(a.minipInst,n,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var i,o=[],a=0;arguments.length>a;a++)o[a]=arguments[a];var s=null!==(i=o[0])&&void 0!==i?i:{},u=null==s?void 0:s.fail;return r.call(this,e(e({},s),{fail:function(e){var r;if(null===(r=t.growingIO.plugins.gioPerformance)||void 0===r||r.buildPerfEvent("Error",{error_type:"".concat(n," Error"),error_content:e.errMsg}),"function"==typeof u)return u(e)}}))}})})},this.errorParse=function(e,t){var n,r,i=e.split("\n");i.length?(i.find(function(e,t){var o=e.match(/at (.*?) \((.*):(\d{1,}):(\d{1,})\)/);if(u(o))return n=i[t-1],r=e.trim(),o.length}),n||(n=i[0]),r||(r=i[1])):(n=t||"Error",r=e.substring(0,100)),a.buildErrorEvent({error_type:t||n,error_content:r})},this.minipInst=this.growingIO.minipInstance.minip,this.cacheQueue=[],this.buildErrorEvent=function(e){var t;return null===(t=a.growingIO.plugins.gioPerformance)||void 0===t?void 0:t.buildPerfEvent("apm_system_error",e)},this.setListeners(),this.hookNavigate(),s(null===(n=this.minipInst)||void 0===n?void 0:n.onAppShow)&&(null===(r=this.minipInst)||void 0===r||r.onAppShow(this.setListeners)),s(null===(i=this.minipInst)||void 0===i?void 0:i.onAppHide)&&(null===(o=this.minipInst)||void 0===o||o.onAppHide(function(){a.minipInst.canIUse("offError")&&a.minipInst.offError(),a.minipInst.canIUse("offUnhandledRejection")&&a.minipInst.offUnhandledRejection(),a.minipInst.canIUse("offLazyLoadError")&&a.minipInst.offLazyLoadError(),a.listenerSet=!1})),this.growingIO.emitter.on(S,function(){v(a.cacheQueue)||a.cacheQueue.forEach(function(e){a.buildErrorEvent(e)})})},I=function(t){var n=this;this.monitor=t,this.markIfNeeded=function(t){n.monitor.referrerPath||"cold"!==n.monitor.bootType||(n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{isColdStart:!0,coldAppLaunch:n.monitor.appPerf.onLaunch,coldAppStartTime:n.monitor.appPerf.appStartTime}))},this.isVisit=function(e){return!(!e.isColdStart&&(n.monitor.referrerPath||"cold"!==n.monitor.bootType))},this.appendMetrics=function(e,t,r){var i,o,a=t.onReadyEnd,s=null!==(i=t.coldAppLaunch)&&void 0!==i?i:n.monitor.appPerf.onLaunch,u=null!==(o=t.coldAppStartTime)&&void 0!==o?o:n.monitor.appPerf.appStartTime;e.page_launch_duration=b(a,s,r),e.reboot_duration=b(a,u,s),e.reboot_mode="cold",n.monitor.bootType="warm"}},T=["firstContentfulPaint","largestContentfulPaint","route"],O="firstContentfulPaint",k="largestContentfulPaint",L=["onShow","onShowEnd","onReady","onReadyEnd"],A=["onShowEnd","onReadyEnd"],C=["onHide","onUnload"],R=function(t){var n=this;this.monitor=t,this.observerWaitTimers={},this.init=function(){if(n.canObservePerformance()){var e=n.monitor.minipInst.getPerformance(),t=null==e?void 0:e.createObserver(n.handleObserverEntries);null==t||t.observe({entryTypes:["render","script","navigation"]})}},this.canObservePerformance=function(){var e=n.monitor.minipInst,t="function"==typeof(null==e?void 0:e.getPerformance),r="function"!=typeof(null==e?void 0:e.canIUse)||e.canIUse("getPerformance");return t&&r},this.handleObserverEntries=function(e){var t=n.pickObserverEntries(e),r=n.getObserverPath(c(t.routeEntries),c(t.fcpEntries),c(t.lcpEntries),t.launchEntry),i={};n.markTouchedPath(i,r),n.handleLaunch(t.launchEntry);for(var o=0,a=t.fcpEntries;o<a.length;o++){var s=a[o];n.markTouchedPath(i,n.handleFCP(s,r))}for(var u=0,l=t.lcpEntries;u<l.length;u++)s=l[u],n.markTouchedPath(i,n.handleLCP(s,r));for(var d=0,h=t.routeEntries;d<h.length;d++)s=h[d],n.markTouchedPath(i,n.handleRoute(s,r));n.finalizeTouchedObserverPaths(i)},this.pickObserverEntries=function(e){return{launchEntry:n.getEntry(e,["appLaunch"]),fcpEntries:n.getEntries(e,[O]),lcpEntries:n.getEntries(e,[k]),routeEntries:n.getEntries(e,["route"])}},this.finalizeTouchedObserverPaths=function(e){m(e,function(e,t){n.markObserverRound(t)}),m(e,function(e,t){n.finalizeObserverRound(t)})},this.handleLaunch=function(t){n.hasPerformanceEntry(t)&&(n.monitor.appPerf=e(e({},n.monitor.appPerf),{appStartTime:t.startTime,appDuration:t.duration,firstPath:t.path}))},this.handleFCP=function(e,t){if(n.hasPaintEntry(e))return n.recordObserverMetric(e,t,O,{FCPStartTime:e.startTime})},this.handleLCP=function(e,t){if(n.hasPaintEntry(e))return n.recordObserverMetric(e,t,k,{LCPStartTime:e.startTime})},this.handleRoute=function(e,t){if(n.hasPerformanceEntry(e))return n.recordObserverMetric(e,t,"route",{navigationStart:e.startTime,routeDuration:e.duration})},this.recordObserverMetric=function(t,r,i,o){var a=n.extractEntryPath(t)||r;if(a)return n.monitor.ensurePagePerf(a),n.monitor.pagePerf[a]=e(e({},n.monitor.pagePerf[a]),o),n.markEntryHandled(a,i),a},this.markObserverRound=function(e){n.monitor.ensurePagePerf(e),n.monitor.pagePerf[e].firstObserverTimestamp||(n.monitor.pagePerf[e].firstObserverTimestamp=Date.now()),n.monitor.pagePerf[e].observerTriggerCount=(n.monitor.pagePerf[e].observerTriggerCount||0)+1},this.finalizeObserverRound=function(e){n.monitor.ensurePagePerf(e),n.monitor.pagePerf[e].observerProcessed=0===n.getWaitableMissingObserverEntries(e).length,n.scheduleObserverFallback(e),n.monitor.tryHandleEvent(e)},this.scheduleObserverFallback=function(e){n.monitor.ensurePagePerf(e);var t=n.monitor.pagePerf[e],r=n.getWaitableMissingObserverEntries(e).length>0,i=n.shouldWaitAlipayObserverRound(t);if(r||i){if(!t.observerFallbackExpired&&!n.observerWaitTimers[e]){var o=Date.now()-(t.firstObserverTimestamp||Date.now()),a=Math.max(0,2e3-o);n.observerWaitTimers[e]=setTimeout(function(){delete n.observerWaitTimers[e],n.markObserverFallbackExpired(e),n.monitor.tryHandleEvent(e)},a)}}else n.clearObserverWaitTimer(e)},this.shouldWaitAlipayObserverRound=function(e){if(void 0===e&&(e={}),!n.isAlipay())return!1;var t=e.observerTriggerCount||0;return 2>t||3>t&&!e.observerProcessed},this.markObserverFallbackExpired=function(e){n.monitor.ensurePagePerf(e);var t=n.monitor.pagePerf[e],r=t.handledEntries||{};T.forEach(function(e){r[e]=!0}),t.handledEntries=r,t.observerProcessed=!0,t.observerFallbackExpired=!0},this.clearObserverWaitTimer=function(e){n.observerWaitTimers[e]&&(clearTimeout(n.observerWaitTimers[e]),delete n.observerWaitTimers[e])},this.hasProcessedObserverEntries=function(e){var t,r,i;return!(n.canObservePerformance()&&(!(null===(t=n.monitor.pagePerf[e])||void 0===t?void 0:t.observerProcessed)||n.isAlipay()&&2>((null===(r=n.monitor.pagePerf[e])||void 0===r?void 0:r.observerTriggerCount)||0)&&!(null===(i=n.monitor.pagePerf[e])||void 0===i?void 0:i.observerFallbackExpired)))},this.hasPerformanceEntry=function(e){return!v(e)||"number"==typeof(null==e?void 0:e.startTime)||"number"==typeof(null==e?void 0:e.duration)},this.hasPaintEntry=function(e){return n.hasPerformanceEntry(e)&&"number"==typeof(null==e?void 0:e.startTime)},this.getEntries=function(e,t){for(var r,i=[],o=0,a=t;o<a.length;o++)for(var s=a[o],u=0,c=(null===(r=null==e?void 0:e.getEntriesByName)||void 0===r?void 0:r.call(e,s))||[];u<c.length;u++){var l=c[u];n.hasPerformanceEntry(l)&&i.push(l)}return i},this.getEntry=function(e,t){return c(n.getEntries(e,t))},this.extractEntryPath=function(e){return E((null==e?void 0:e.path)||(null==e?void 0:e.route)||(null==e?void 0:e.pagePath)||(null==e?void 0:e.pageURL)||(null==e?void 0:e.url))},this.getObserverPath=function(){for(var e=[],t=0;arguments.length>t;t++)e[t]=arguments[t];for(var r=0,i=e;r<i.length;r++){var o=i[r],a=n.extractEntryPath(o);if(a)return a}return n.getPendingObserverPath()||E(n.monitor.getCurrentPath())},this.getPendingObserverPath=function(){var e="",t=1/0;return m(n.monitor.pagePerf,function(r,i){if(r&&!r.eventSent&&!n.hasProcessedObserverEntries(i)&&n.monitor.hasReadyPagePerf(i)){var o=n.monitor.getPageReadyTimestamp(i);"number"==typeof o&&t>o&&(t=o,e=i)}}),e},this.getMissingObserverEntries=function(e){var t,r=(null===(t=n.monitor.pagePerf[e])||void 0===t?void 0:t.handledEntries)||{};return T.filter(function(e){return!r[e]})},this.getWaitableMissingObserverEntries=function(e){var t=n.getMissingObserverEntries(e);return n.shouldWaitPaintEntries()?t.filter(function(e){return e===O||e===k}):[]},this.shouldWaitPaintEntries=function(){return n.isWeChat()||n.isAlipay()},this.isAlipay=function(){return"alip"===n.monitor.growingIO.minipInstance.platform},this.isWeChat=function(){return"MinP"===n.monitor.growingIO.minipInstance.platform},this.markEntryHandled=function(e,t){if(e){n.monitor.ensurePagePerf(e);var r=n.monitor.pagePerf[e],i=r.handledEntries||{};i[t]=!0,r.handledEntries=i}},this.markTouchedPath=function(e,t){t&&(e[t]=!0)}},W=function(e){this.monitor=e,this.appendMetrics=function(e,t,n){e.page_launch_duration=b(t.onReadyEnd,t.navigationStart,n)}},M=function(t){var n=this;this.monitor=t,this.lastWarm=!1,this.warmLandingPath="",this.appShowEndFallbackTimer=null,this.staleMarkerTimer=null,this.syntheticAppShowEnd=void 0,this.handleAppHide=function(){n.lastWarm=!1,n.warmLandingPath="",n.syntheticAppShowEnd=void 0,n.clearAppShowEndFallback(),n.clearStaleMarkerCleanup(),n.monitor.bootType="warm"},this.handleAppShow=function(e,t){n.isAppWarmForeground(e)&&(n.cacheLandingPath(t),n.lastWarm=!0,n.scheduleAppShowEndFallback(),n.scheduleStaleMarkerCleanup())},this.handleAppShowEnd=function(e,t){n.isAppWarmForeground(e)&&(n.clearAppShowEndFallback(),n.cacheLandingPath(t),n.hasPendingWarmStart()||(n.lastWarm=!0,n.scheduleStaleMarkerCleanup()),n.completeAfterAppShowEnd())},this.markIfMatched=function(t,r){var i;return!(!n.lastWarm||n.warmLandingPath&&n.warmLandingPath!==t||(null===(i=n.monitor.pagePerf[t])||void 0===i?void 0:i.eventSent)||(n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{isWarmStart:!0,warmAppShowEnd:null!=r?r:n.getCurrentAppShowEnd(),warmWaitReadyEnd:n.hasNewLoadAfterWarmStart(t)}),n.consumeMarker(),0))},this.isVisit=function(e){return!(!e.isWarmStart||!n.hasAppShowEnd(e))},this.canSend=function(e){var t=n.monitor.pagePerf[e];return!!(t&&t.isWarmStart&&n.hasAppShowEnd(t)&&(t.warmWaitReadyEnd?t.onReadyEnd:t.onShowEnd))},this.getReadyTimestamp=function(e){return e.warmWaitReadyEnd?e.onReadyEnd:e.onShowEnd},this.appendMetrics=function(e,t){var r=n.getPageEnd(t),i=t.warmAppShowEnd,o=n.getCurrentAppShow();e.page_launch_duration=b(r,i,o),e.reboot_duration=b(r,i,o),e.reboot_mode="warm"},this.getPageEnd=function(e){return e.warmWaitReadyEnd?e.onReadyEnd:e.onShowEnd},this.scheduleAppShowEndFallback=function(){n.clearAppShowEndFallback(),n.appShowEndFallbackTimer=setTimeout(function(){var e;if(n.appShowEndFallbackTimer=null,(n.lastWarm||n.hasPendingWarmStart())&&!n.getCurrentAppShowEnd()){var t=null!==(e=n.monitor.appPerf.onShow)&&void 0!==e?e:Date.now();n.syntheticAppShowEnd=t,n.completeAfterAppShowEnd(t)}},0)},this.clearAppShowEndFallback=function(){n.appShowEndFallbackTimer&&(clearTimeout(n.appShowEndFallbackTimer),n.appShowEndFallbackTimer=null)},this.scheduleStaleMarkerCleanup=function(){n.clearStaleMarkerCleanup(),n.staleMarkerTimer=setTimeout(function(){n.staleMarkerTimer=null,n.lastWarm=!1,n.warmLandingPath=""},5e3)},this.clearStaleMarkerCleanup=function(){n.staleMarkerTimer&&(clearTimeout(n.staleMarkerTimer),n.staleMarkerTimer=null)},this.completeAfterAppShowEnd=function(e){var t=n.getPendingPath();if(t)return n.bindAppShowEnd(t,e),void n.monitor.tryHandleEvent(t);var r=E(n.monitor.getCurrentPath());r&&n.lastWarm&&n.hasPageShownAfterWarmStart(r)&&n.markIfMatched(r,e)&&n.monitor.tryHandleEvent(r)},this.getPendingPath=function(){var e=n.getWarmStartBeginTimestamp(),t="",r=1/0;return m(n.monitor.pagePerf,function(i,o){(null==i?void 0:i.isWarmStart)&&!n.hasAppShowEnd(i)&&"number"==typeof i.onShowEnd&&("number"==typeof e&&i.onShowEnd<e||i.onShowEnd<r&&(r=i.onShowEnd,t=o))}),t},this.bindAppShowEnd=function(t,r){n.monitor.ensurePagePerf(t),n.monitor.pagePerf[t]=e(e({},n.monitor.pagePerf[t]),{warmAppShowEnd:null!=r?r:n.getCurrentAppShowEnd()})},this.hasPendingWarmStart=function(){var e=n.getWarmStartBeginTimestamp(),t=!1;return m(n.monitor.pagePerf,function(r){(null==r?void 0:r.isWarmStart)&&!n.hasAppShowEnd(r)&&("number"==typeof e&&"number"==typeof r.onShowEnd&&r.onShowEnd<e||(t=!0))}),t},this.hasAppShowEnd=function(e){return"number"==typeof(null==e?void 0:e.warmAppShowEnd)},this.cacheLandingPath=function(e){var t=n.getLandingPath(e);t&&(n.warmLandingPath=t)},this.getLandingPath=function(e){var t,n=(null===(t=null==e?void 0:e.arguments)||void 0===t?void 0:t[0])||e;return E(null==n?void 0:n.path)},this.consumeMarker=function(){n.lastWarm&&(n.lastWarm=!1),n.warmLandingPath="",n.clearStaleMarkerCleanup()},this.isAppWarmForeground=function(e){return"number"==typeof n.monitor.appPerf.onHide&&e>=n.monitor.appPerf.onHide},this.getWarmStartBeginTimestamp=function(){var e,t;return null!==(t=null!==(e=n.monitor.appPerf.onHide)&&void 0!==e?e:n.monitor.appPerf.onShow)&&void 0!==t?t:n.monitor.appPerf.onShowEnd},this.getCurrentAppShowEnd=function(){var e=n.getWarmStartBeginTimestamp(),t=n.monitor.appPerf.onShowEnd;if("number"==typeof t&&("number"!=typeof e||t>=e))return t;var r=n.syntheticAppShowEnd;return"number"!=typeof r||"number"==typeof e&&e>r?void 0:r},this.getCurrentAppShow=function(){var e=n.monitor.appPerf.onShow,t=n.monitor.appPerf.onHide;if("number"==typeof e&&("number"!=typeof t||e>=t))return e},this.hasPageShownAfterWarmStart=function(e){var t=n.monitor.pagePerf[e],r=n.getWarmStartBeginTimestamp();return"number"==typeof(null==t?void 0:t.onShowEnd)&&"number"==typeof r&&t.onShowEnd>=r},this.hasNewLoadAfterWarmStart=function(e){var t=n.monitor.pagePerf[e],r=n.getWarmStartBeginTimestamp();return"number"==typeof(null==t?void 0:t.onLoad)&&"number"==typeof r&&t.onLoad>=r}},x=function(t){var n=this;this.growingIO=t,this.appPerf={},this.pagePerf={},this.bootType="cold",this.referrerPath="",this.initLifecycleListener=function(){n.growingIO.emitter.on("MINIP_LIFECYCLE",n.handleLifecycleEvent)},this.handleLifecycleEvent=function(e){var t=e.event,r=e.timestamp,i=e.params,o=t.split(" "),a=o[0],s=o[1];"App"!==a?"Page"===a&&n.handlePageLifecycle(s,r,i):n.handleAppLifecycle(s,r,i)},this.handleAppLifecycle=function(t,r,i){var o;n.appPerf=e(e({},n.appPerf),((o={})[t]=r,o)),"onHide"!==t?"onShow"!==t?"onShowEnd"===t&&n.warmStart.handleAppShowEnd(r,i):n.warmStart.handleAppShow(r,i):n.warmStart.handleAppHide()},this.handlePageLifecycle=function(e,t,r){var i=n.getLifecyclePath(r);i&&(n.shouldResetForNewVisit(i,e)&&n.resetPagePerf(i),n.recordPageLifecycle(i,e,t),n.shouldCachePageContext(e)&&n.cachePageContext(i),"onShowEnd"===e&&(n.coldStart.markIfNeeded(i),n.warmStart.markIfMatched(i)),n.shouldCheckSendOnLifecycle(e)&&n.tryHandleEvent(i),n.shouldUpdateReferrer(e)&&(n.referrerPath=i))},this.getLifecyclePath=function(e){var t=(null==e?void 0:e.page)||(null==e?void 0:e.instance);return E(null==t?void 0:t.route)||E(n.getCurrentPath())},this.shouldResetForNewVisit=function(e,t){var r=n.pagePerf[e];return!!r&&("onLoad"===t?!!(r.onLoad||r.onShow||r.onReady||r.onHide||r.onUnload||r.eventSent):"onShow"===t&&!!(r.onHide||r.onUnload||r.eventSent))},this.resetPagePerf=function(e){n.observer.clearObserverWaitTimer(e),n.pagePerf[e]={path:e}},this.recordPageLifecycle=function(t,r,i){var o;n.ensurePagePerf(t),n.pagePerf[t]=e(e({},n.pagePerf[t]),((o={})[r]=i,o))},this.cachePageContext=function(t){var r=n.growingIO.dataStore.eventHooks.currentPage.getPageContext();n.ensurePagePerf(t),n.pagePerf[t]=e(e({},n.pagePerf[t]),{pagePath:t,pageQuery:r.path===t?r.query:"",pageTitle:r.path===t?r.title:""})},this.ensurePagePerf=function(e){n.pagePerf[e]||(n.pagePerf[e]={path:e})},this.tryHandleEvent=function(e){return!(!e||!n.hasReadyPagePerf(e)||!n.warmStart.isVisit(n.pagePerf[e])&&!n.observer.hasProcessedObserverEntries(e))&&n.handleEvent(e)},this.handleEvent=function(e){var t;if(null===(t=n.pagePerf[e])||void 0===t?void 0:t.eventSent)return!1;var r=n.pagePerf[e]||{},i=n.buildPerfData(e);return n.cleanPerfData(i),!!f(i,"page_launch_duration")&&(n.emitPerfEvent(e,r,i),n.observer.clearObserverWaitTimer(e),n.pagePerf[e].eventSent=!0,!0)},this.buildPerfData=function(e){var t=n.pagePerf[e]||{},r={title:t.pageTitle||""},i=t.onLoad;return n.appendPaintMetrics(r,t,i),n.warmStart.isVisit(t)?n.warmStart.appendMetrics(r,t):n.coldStart.isVisit(t)?n.coldStart.appendMetrics(r,t,i):n.referrerPath&&n.pageLoad.appendMetrics(r,t,i),r},this.appendPaintMetrics=function(e,t,n){"number"==typeof t.FCPStartTime&&(e.first_contentful_paint_duration=b(t.FCPStartTime,n)),"number"==typeof t.LCPStartTime&&(e.largest_contentful_paint_duration=b(t.LCPStartTime,n))},this.cleanPerfData=function(e){m(e,function(t,r){n.isInvalidPerfValue(t)&&g(e,r)}),e.reboot_mode&&!f(e,"reboot_duration")&&g(e,"reboot_mode")},this.isInvalidPerfValue=function(e){return null===e||"null"===e||"NaN"===e||"number"==typeof e&&isNaN(e)},this.emitPerfEvent=function(e,t,r){n.buildMonitorEvent(r,{timestamp:+Date.now(),path:t.pagePath||e,query:t.pageQuery||"",title:r.title})},this.getCurrentPath=function(){return n.growingIO.minipInstance.getCurrentPath()},this.hasReadyPagePerf=function(e){var t=n.pagePerf[e];return!!t&&(t.isWarmStart?n.warmStart.canSend(e):!!t.onReadyEnd)},this.getPageReadyTimestamp=function(e){var t=n.pagePerf[e];if(t)return n.warmStart.canSend(e)?n.warmStart.getReadyTimestamp(t):t.onReadyEnd},this.shouldCachePageContext=function(e){return L.includes(e)},this.shouldCheckSendOnLifecycle=function(e){return A.includes(e)},this.shouldUpdateReferrer=function(e){return C.includes(e)},this.minipInst=this.growingIO.minipInstance.minip,this.observer=new R(this),this.coldStart=new I(this),this.warmStart=new M(this),this.pageLoad=new W(this),this.buildMonitorEvent=function(e,t){var r;return null===(r=n.growingIO.plugins.gioPerformance)||void 0===r?void 0:r.buildPerfEvent("apm_app_launch",e,t)},this.observer.init(),this.initLifecycleListener()},_=function(t,n){void 0===n&&(n={});var o,c=this;this.growingIO=t,this.options=n,this.verifyUrl=function(e){if(e.indexOf(c.gdpRequestURL)>-1)return!0;if(u(c.excludeRegExp)){var t=l(c.excludeRegExp.map(function(t){return a(t)?t.test(e):i(t)?e.indexOf(t)>-1:void 0}));return!v(t)}return i(c.excludeRegExp)?e.indexOf(c.excludeRegExp)>-1:!!a(c.excludeRegExp)&&c.excludeRegExp.test(e)},this.hookRequest=function(){var t=c;["request","downloadFile","uploadFile"].forEach(function(n){var r=c.minipInst[n];s(r)&&Object.defineProperty(c.minipInst,n,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var i=[],o=0;arguments.length>o;o++)i[o]=arguments[o];var a=i[0],s=a.url;if(t.verifyUrl(s))return r.call(this,a);var u={header:a.header||{},url:a.url};switch(n){case"request":var c=a.method;u=e(e({},u),{method:c});break;case"downloadFile":case"uploadFile":var l=a.filePath;u=e(e({},u),{filePath:l,method:"downloadFile"===n?"GET":"POST"})}var d=a.fail,h=a.success;return u.startTime=Date.now(),r.call(this,e(e({},a),{success:function(e){if(u.endTime=Date.now(),t.networkPerfBuilder(e,u),"function"==typeof h)return h(e)},fail:function(e){var n;if(u.endTime=Date.now(),null===(n=t.growingIO.plugins.gioPerformance)||void 0===n||n.buildPerfEvent("Error",{error_type:e.errMsg,error_content:u.url}),"function"==typeof d)return d(e)}}))}})})},this.networkPerfBuilder=function(e,t){var n=e.profile,i=void 0===n?{}:n,o=e.statusCode,a=void 0===o?0:o,s=e.errMsg,u=t.url,l=t.filePath,d=t.method,h=i.redirectStart,f=i.redirectEnd,p=i.fetchStart,P=i.domainLookUpStart,E=i.domainLookUpEnd,b=i.connectStart,w=i.connectEnd,S=i.requestStart,y=i.responseStart,I=i.responseEnd,T=!v(i),O={url:u,filePath:l,method:d,statusCode:a,message:s,redirect:T?f-h:0,cache:T?P-p:0,dns:T?E-P:0,tcp:T?w-b:0,request:T?y-S:0,response:T?I-y:0,duration:T?I-p:t.endTime-t.startTime};m(O,function(e,t){return(""===e||r(e))&&g(O,t)}),c.buildNetworkEvent(O)},this.minipInst=this.growingIO.minipInstance.minip,this.buildNetworkEvent=function(e){var t;if(n.network){var r=e.duration,i=e.url,o=e.method,a=e.statusCode;null===(t=c.growingIO.plugins.gioPerformance)||void 0===t||t.buildPerfEvent("apm_network_request",{response_duration:r,request_address:i,request_method:o,http_code:a})}},(null===(o=this.options.network)||void 0===o?void 0:o.exclude)&&(this.excludeRegExp=this.options.network.exclude),this.hookRequest();var d=this,h=this.growingIO.uploader.generateURL;this.growingIO.uploader.generateURL=function(){var e=h.apply(this,arguments);return arguments[0]===d.growingIO.trackingId&&(d.gdpRequestURL=e),e}},F={name:"gioPerformance",method:function(r,i){void 0===i&&(i={});var o,a=this;this.growingIO=r,this.options=i,this.init=function(){var e=a.growingIO.vdsConfig.dataCollect,t=a.options,n=t.monitor,r=t.exception,i=t.network;n&&(a.monitor=new x(a.growingIO)),r&&(a.exception=new y(a.growingIO)),i&&(a.network=new _(a.growingIO,a.options)),e&&a.sendCacheQuene()},this.sendCacheQuene=function(){n.isEmpty(a.cacheQueue)||(a.cacheQueue.forEach(function(e){a.buildPerfEvent(e.eventName,e.attributes,e.extra)}),a.cacheQueue=[])},this.buildPerfEvent=function(r,i,o){var s,u=a.growingIO,c=u.dataStore,l=c.eventContextBuilder,d=c.eventConverter,h=u.gioSDKInitialized,f=u.vdsConfig;if(!h||!f.dataCollect)return a.cacheQueue=t(t([],a.cacheQueue,!0),[{eventName:r,attributes:i,extra:o}],!1),!1;n.forEach(i,function(e,t){var r=Number.isNaN(e)||n.isNil(e)||0>Number(e)?0:e;i[t]=n.fixed(r,0)});var p=e({eventType:"CUSTOM",eventName:r,attributes:i},l(a.growingIO.trackingId));p.attributes=w(e(e({},null!==(s=p.attributes)&&void 0!==s?s:{}),i)),v(o)||(p=e(e({},p),o)),d(p)},this.pluginVersion="4.6.1",n=this.growingIO.utils,this.options=e({monitor:!0,exception:!0,network:!1},this.options),this.cacheQueue=[],this.growingIO.emitter.on(S,function(e){if(e.trackingId===a.growingIO.trackingId){var t=e.performance,n=t.monitor,r=t.exception,i=t.network;n!==a.options.monitor&&(a.options.monitor=n),r!==a.options.exception&&(a.options.exception=r),i!==a.options.network&&(a.options.network=i),a.init()}}),null===(o=this.growingIO.emitter)||void 0===o||o.on("SESSIONID_UPDATE",function(){var e=a.growingIO,t=e.trackingId;(0,e.getOption)(t,"dataCollect")&&a.sendCacheQuene()})}};export{F as default};