gio-miniprogram-sdk 4.0.0 → 4.1.0

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.
Files changed (78) hide show
  1. package/dist/alipay.js +1 -1
  2. package/dist/baidu.js +1 -1
  3. package/dist/bytedance.js +1 -1
  4. package/dist/jingdong.js +1 -1
  5. package/dist/kuaishou.js +1 -1
  6. package/dist/plugins/gioABTest.js +1 -1
  7. package/dist/plugins/gioCompress.js +1 -1
  8. package/dist/plugins/gioEventAutoTracking.js +1 -1
  9. package/dist/plugins/gioImpressionTracking.js +1 -1
  10. package/dist/plugins/gioMultipleInstances.js +1 -0
  11. package/dist/qq.js +1 -1
  12. package/dist/quickapp.js +1 -1
  13. package/dist/taobao.js +1 -1
  14. package/dist/taro.js +1 -1
  15. package/dist/uniapp.js +1 -1
  16. package/dist/wechat.js +1 -1
  17. package/package.json +39 -42
  18. package/rollup.config.js +11 -6
  19. package/rollup.plugins.config.js +13 -10
  20. package/src/{pluginsOut/frameworks → adapters}/gioTaobaoAdapter.ts +47 -44
  21. package/src/adapters/gioTaroAdapter.ts +459 -0
  22. package/src/{pluginsOut/frameworks → adapters}/gioUniAppAdapter.ts +35 -6
  23. package/src/constants/config.ts +49 -20
  24. package/src/constants/emitMsg.ts +23 -0
  25. package/src/constants/regex.ts +14 -0
  26. package/src/core/dataStore/eventContextBuilder.ts +28 -17
  27. package/src/core/dataStore/eventHooks/appEffects.ts +50 -31
  28. package/src/core/dataStore/eventHooks/index.ts +7 -5
  29. package/src/core/dataStore/eventHooks/minipPage.ts +2 -11
  30. package/src/core/dataStore/eventHooks/pageEffects.ts +61 -27
  31. package/src/core/dataStore/index.ts +266 -181
  32. package/src/core/growingIO.ts +312 -179
  33. package/src/core/pluginsInstance/base.ts +157 -0
  34. package/src/core/pluginsInstance/taro.ts +15 -0
  35. package/src/core/pluginsInstance/tb.ts +15 -0
  36. package/src/core/pluginsInstance/uniapp.ts +15 -0
  37. package/src/core/uploader.ts +131 -87
  38. package/src/core/userStore.ts +160 -121
  39. package/src/index.ts +37 -28
  40. package/src/minipInstance/base.ts +2 -1
  41. package/src/minipInstance/quickapp.ts +5 -19
  42. package/src/platformConfig/base.ts +0 -4
  43. package/src/{pluginsOut/ordinary → plugins}/gioABTest.ts +74 -37
  44. package/src/{pluginsOut/ordinary → plugins}/gioEventAutoTracking.ts +25 -18
  45. package/src/{pluginsOut/ordinary → plugins}/gioImpressionTracking.ts +109 -41
  46. package/src/plugins/gioMultipleInstances.ts +176 -0
  47. package/src/types/base.ts +12 -3
  48. package/src/types/dataStore.ts +31 -16
  49. package/src/types/eventHooks.ts +8 -9
  50. package/src/types/growingIO.ts +30 -14
  51. package/src/types/platforms.ts +0 -4
  52. package/src/types/plugins.ts +1 -1
  53. package/src/types/uploader.ts +16 -12
  54. package/src/types/userStore.ts +21 -17
  55. package/src/utils/glodash.ts +10 -3
  56. package/src/utils/tools.ts +27 -6
  57. package/src/utils/verifiers.ts +25 -50
  58. package/typings/global.d.ts +5 -0
  59. package/.babelrc +0 -4
  60. package/bin/build/full.sh +0 -32
  61. package/bin/build/jd.sh +0 -14
  62. package/bin/build/ks.sh +0 -14
  63. package/bin/build/my.sh +0 -14
  64. package/bin/build/plugins.sh +0 -5
  65. package/bin/build/qq.sh +0 -14
  66. package/bin/build/quickapp.sh +0 -14
  67. package/bin/build/swan.sh +0 -14
  68. package/bin/build/taro.sh +0 -18
  69. package/bin/build/tb.sh +0 -18
  70. package/bin/build/tt.sh +0 -14
  71. package/bin/build/uniapp.sh +0 -18
  72. package/bin/build/wx.sh +0 -14
  73. package/src/core/plugins.ts +0 -152
  74. package/src/pluginsOut/README.md +0 -50
  75. package/src/pluginsOut/frameworks/gioTaroAdapter.ts +0 -358
  76. package/src/pluginsOut/ordinary/gioCustomTracking.ts +0 -71
  77. package/bin/{build/all.sh → build.sh} +3 -3
  78. /package/src/{pluginsOut/ordinary → plugins}/gioCompress.ts +0 -0
package/dist/wechat.js CHANGED
@@ -1 +1 @@
1
- const e=e=>["undefined","null"].includes(T(e)),t=e=>"string"===T(e),i=e=>"number"===T(e),n=e=>"boolean"===T(e),s=t=>"[object Object]"==={}.toString.call(t)&&!e(t),r=e=>["function","asyncfunction"].includes(T(e)),o=e=>Array.isArray(e)&&"array"===T(e),a=e=>{try{return Array.from(e)[0]}catch(e){return}},l=e=>{try{const t=Array.from(e);return t[t.length-1]}catch(e){return}},u=(e,t=1)=>o(e)&&i(t)?e.slice(t>0?t:1,e.length):e,g=e=>{if(o(e)){let t=0;const i=[];for(const n of e)n&&!P(n)&&(i[t++]=n);return i}return e},h=(e,t)=>{if(o(e)){const i=e.findIndex(t);return 0>i?void 0:e[i]}},c=t=>e(t)?"":""+t,d=(e,t)=>"string"===T(e)?e.split(t):e,p=e=>{if(t(e)){const t=d(e,"");return`${a(t).toLowerCase()}${u(t).join("")}`}return e},v=(e,t)=>e.slice(0,t.length)===t,m={}.hasOwnProperty,f=(t,i)=>!e(t)&&m.call(t,i),I=e=>s(e)?Object.keys(e):[],S=(e,t)=>{I(e).forEach((i=>t(e[i],i)))},y=(e,t)=>{const i=I(e);return!(!s(e)||!s(t)||i.length!==I(t).length||i.map(((i,n)=>s(e[i])?y(e[i],t[i]):e[i]===t[i])).includes(!1))},w=(e,t,i)=>{let n=e;return s(e)?(t.split(".").forEach((e=>{n=n?n[e]:i})),n):i},O=(e,t)=>{if(!s(e))return!1;try{if("string"===T(t))return delete e[t];if("array"===T(t))return t.map((t=>delete e[t]));"object"===T(t)&&t.constructor===RegExp&&I(e).forEach((i=>{t.test(i)&&O(e,i)}))}catch(e){return!1}},b=(e,t=250,i,n)=>{let s,r=0;return"boolean"!==T(i)&&(n=e,e=i,i=void 0),function(...o){let a=this,l=Date.now()-r;function u(){r=Date.now(),e.apply(a,o)}n&&!s&&u(),s&&clearTimeout(s),void 0===n&&l>t?u():!0!==i&&(s=setTimeout(n?function(){s=void 0}:u,void 0===n?t-l:t))}},P=e=>o(e)?0===e.length:s(e)?0===I(e).length:!e,T=e=>({}.toString.call(e).slice(8,-1).toLowerCase());var C=Object.freeze({__proto__:null,isNil:e,isString:t,isNaN:e=>"NaN"===c(Number(e)),isNumber:i,isBoolean:n,isObject:s,isRegExp:e=>"[object RegExp]"==={}.toString.call(e),isFunction:r,isArray:o,isDate:e=>"date"===T(e),fixed:(e,n)=>i(e)?Number(e.toFixed(i(n)?n:2)):t(e)&&"NaN"!==c(Number(e))?Number(Number(e).toFixed(i(n)?n:2)):e,head:a,last:l,drop:u,dropWhile:(e,t)=>o(e)?e.filter((e=>!t(e))):e,compact:g,find:h,isEqualArray:(e,t)=>!(!o(e)||!o(t)||e.length!==t.length)&&e.every(((e,i)=>e===t[i])),toString:c,split:d,lowerFirst:p,upperFirst:e=>{if(t(e)){const t=d(e,"");return`${a(t).toUpperCase()}${u(t).join("")}`}return e},startsWith:v,endsWith:(e,t)=>{const{length:i}=e;let n=i;n>i&&(n=i);const s=n;return n-=t.length,n>=0&&e.slice(n,s)===t},hasOwnProperty:m,has:f,keys:I,forEach:S,isEqual:y,get:w,unset:O,throttle:b,isEmpty:P,typeOf:T,formatDate: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())}});const _=(e,t)=>{console.log("%c[GrowingIO]:"+e,{info:"color: #3B82F6;",error:"color: #EF4444",warn:"color: #F59E0B",success:"color: #10B981"}[t]||"")},E=(e,t=!0,i="参数不合法")=>_(`${t?"调用":"设置"} ${e} 失败,${i}!`,"warn"),k=e=>{try{return e()}catch(e){return}},A=e=>t(e)?e.trim().substring(0,100):e,N=(e,i)=>t(e)&&!P(e)&&e.match(/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/)?i():(_("事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!","error"),!1),q=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),x=e=>e.pixelRatio?Math.round(e.screenHeight*e.pixelRatio):e.screenHeight,j=e=>e.pixelRatio?Math.round(e.screenWidth*e.pixelRatio):e.screenWidth,D=(e,t)=>{if(e){const i=e.toLowerCase();return-1!==i.indexOf("android")?t+"-Android":-1!==i.indexOf("ios")?t+"-iOS":e}},H=e=>{if(t(e)){const t=e.indexOf("?");return-1!==t?[e.substring(0,t),e.substring(t+1)]:[e,""]}return["",""]},$=e=>t(e)?e.startsWith("/")?e:"/"+e:"",U=e=>k((()=>{switch(e){case"wx":return wx;case"my":case"tb":return my;case"swan":return swan;case"tt":return tt;case"qq":return qq;case"ks":return ks;case"jd":return jd;default:{let e;return e||(e=k((()=>swan))),e||(e=k((()=>my))),e||(e=k((()=>tt))),e||(e=k((()=>qq))),e||(e=k((()=>ks))),e||(e=k((()=>jd))),e||(e=k((()=>wx))),e}}})),L=e=>k((()=>{switch(e){case"wx":return __wxConfig;case"swan":return appConfig;case"tt":return __ttConfig;case"qq":return __qqConfig;case"ks":return __ksConfig;case"jd":return __jdConfig;default:return}})),B=()=>{let e;return!e&&k((()=>swan))&&(e="swan"),!e&&k((()=>tt))&&(e="tt"),!e&&k((()=>qq))&&(e="qq"),!e&&k((()=>my.tb))&&(e="tb"),!e&&k((()=>my))&&(e="my"),!e&&k((()=>ks))&&(e="ks"),!e&&k((()=>jd))&&(e="jd"),!e&&k((()=>wx))&&(e="wx"),e||h(I(global),(e=>c(e).toLowerCase().includes("quickapp")))&&(e="quickapp"),e},F=e=>I(e).filter((e=>e.indexOf("__sub")>-1&&e.indexOf("gio__")>-1)).sort(),R=()=>{let e=k((()=>getApp({allowDefault:!0})));return e||(e=K()),e},K=()=>{var e;return null!==(e=k((()=>$global)))&&void 0!==e?e:global},G=t=>{const i={};return s(t)&&S(t,((t,n)=>{const r=c(n).slice(0,100);s(t)?i[r]=G(t):o(t)?(i[r]=t.slice(0,100),i[r]=i[r].join("||").slice(0,1e3)):i[r]=e(t)?"":c(t).slice(0,1e3)})),i},M=(e,t)=>{const i=()=>t.map((t=>e.getStorageSync(t)));try{return e.minip.canIUse("batchGetStorageSync")?e.minip.batchGetStorageSync(t):i()}catch(e){return i()}},V=(e,t)=>{const i=()=>t.map((({key:t,value:i})=>e.setStorageSync(t,i)));try{return e.minip.canIUse("batchSetStorageSync")?e.minip.batchSetStorageSync(t):i()}catch(e){return i()}},Q=t=>I(t||{}).map((i=>i?`${i}=${e(t[i])?"":t[i]}`:"")).join("&"),W=e=>{(v(e,"?")||v(e,"&"))&&(e=e.slice(1,e.length));const t={};return e.split("&").forEach((e=>{const i=e.split("=");i[0]&&(t[i[0]]=i[1])})),t};var z=Object.freeze({__proto__:null,consoleText:_,callError:E,niceTry:k,niceCallback:(e,t)=>{if(r(e))try{e(t)}catch(e){_("回调执行失败!"+e,"error")}},limitString:A,eventNameValidate:N,guid:q,getScreenHeight:x,getScreenWidth:j,getOS:D,compareVersion:(e="",t="")=>{const i=e=>e.replace(/\s+/g,""),n=e=>e.replace(/[vV]/g,""),s=i(n(e)),r=i(n(t)),o=s.split("."),a=r.split(".");for(let e=0;3>e;e++){let t=Number(o[e]),i=Number(a[e]);if(t>i)return 1;if(i>t)return-1;if(!isNaN(t)&&isNaN(i))return 1;if(isNaN(t)&&!isNaN(i))return-1}return 0},getVueVersion:e=>{if(e){const t=Number.parseInt(a(d(e.version,".")),10);return Number.isNaN(t)?0:t}return 0},splitPath:H,normalPath:$,isTaro3:e=>{const{Current:t,createComponent:i}=e;return!(!e||!t||i)},getPlainMinip:U,getPlainConfig:L,getPlainPlatform:B,getSubKeys:F,getAppInst:R,getGlobal:K,limitObject:G,batchGetStorageSync:M,batchSetStorageSync:V,qsStringify:Q,qsParse:W,hashCode:e=>{let t=0;if(P(e)||"boolean"==typeof e)return t;let i=0;for(;i<e.length;)t=(t<<5)-t+e.charCodeAt(i),t&=t,i++;return t}});const J=e=>t(e)&&e.length>0||i(e)&&e>0,Y={autotrack:{type:"boolean",default:!0},compress:{type:"boolean",default:!0},dataCollect:{type:"boolean",default:!0},debug:{type:"boolean",default:!1},idMapping:{type:"boolean",default:!1},enableIdMapping:{type:"boolean",default:!1},extraParams:{type:"array",default:[]},followShare:{type:"boolean",default:!0},forceLogin:{type:"boolean",default:!1},ignoreFields:{type:"array",default:[]},pluginMode:{type:"boolean",default:!1},originalSource:{type:"boolean",default:!0},keepAlive:{type:"number",default:3e5},performance:{type:"object",default:{monitor:!0,exception:!0}},serverUrl:{type:"string",default:"https://napi.growingio.com"},subpackage:{type:"boolean",default:!1},taro:{type:["object","module"],default:!1},taroVue:{type:["object","function"],default:!1},tbConfig:{type:"object",default:{cloud:void 0,cloudFuncSend:!1,cloudFuncName:"httpTunnel",cloudFuncHandler:"main",cloudAppId:void 0,path:void 0}},uniVue:{type:["object","function"],default:!1},uploadInterval:{type:"number",default:1e3},version:{type:"string",default:"1.0.0"}},Z=["clearGeneralProps","clearTrackTimer","clearUserId","getDeviceId","getGioInfo","getOption","identify","init","registerPlugins","removeTimer","setGeneralProps","setLocation","setOption","setPageAttributes","setUserAttributes","setUserId","track","trackTimerEnd","trackTimerPause","trackTimerResume","trackTimerStart","updateImpression","getABTest"],X={autotrack:"无埋点",dataCollect:"数据采集",debug:"调试模式",serverUrl:"数据上报服务地址"},ee=["enableDebug","setAutotrack","setDataCollect","setTrackerHost","setTrackerScheme","setConfig","collectImp","setPlatformProfile","getLocation"],te=["deviceBrand","deviceModel","deviceType","networkState","screenHeight","screenWidth","operatingSystem"],ie=[...te,"appChannel","language","platformVersion"];class ne{constructor(e){this.growingIO=e,this.main=e=>{var t,i,n,s,r;const{sdkVersion:o,vdsConfig:a,platformConfig:l,minipInstance:u,userStore:g,dataStore:{scene:h,eventHooks:c,locationData:d,lastVisitEvent:p}}=this.growingIO,{systemInfo:v={},network:m={}}=u,{brand:f,model:I,platform:S,language:y,version:w}=v,b={appChannel:"scn:"+(h||"NA"),appVersion:a.version,dataSourceId:a.dataSourceId,deviceBrand:f,deviceId:g.uid,deviceModel:I,deviceType:D(S,l.name),domain:a.appId,language:y,latitude:null==d?void 0:d.latitude,longitude:null==d?void 0:d.longitude,networkState:(null==m?void 0:m.networkType)||(null==m?void 0:m.type)||(null==m?void 0:m.subtype),operatingSystem:D(S,l.name),path:(null===(t=c.currentPage)||void 0===t?void 0:t.path)?null===(i=c.currentPage)||void 0===i?void 0:i.path:p.path,platform:l.platform,platformVersion:l.name+(w?" "+w:""),query:(null===(n=c.currentPage)||void 0===n?void 0:n.path)?null===(s=c.currentPage)||void 0===s?void 0:s.query:p.query,screenHeight:x(v),screenWidth:j(v),sdkVersion:o,sessionId:g.sessionId,title:(null===(r=c.currentPage)||void 0===r?void 0:r.title)||u.getPageTitle(u.getCurrentPage()),timestamp:Date.now(),timezoneOffset:(new Date).getTimezoneOffset(),userId:g.userId};return a.idMapping&&(b.userKey=g.userKey),P(a.ignoreFields)||a.ignoreFields.forEach((e=>{O(b,e)})),P(e)?b:Object.assign(Object.assign({},b),e)}}}function se(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{l(n.next(e))}catch(e){r(e)}}function a(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))}class re{constructor(t){this.growingIO=t,this.main=(e,t)=>{var i,n;const s=Date.now(),{emitter:r,userStore:o,vdsConfig:a,platformConfig:l,uploader:u,dataStore:g,dataStore:{shareOut:h,keepAlive:c,lastCloseTime:d,eventHooks:p,saveStorageInfo:v}}=this.growingIO;r.emit("minipLifecycle",{event:"App "+e,timestamp:s,params:null!==(i=t[0])&&void 0!==i?i:{}}),a.debug&&console.log("App:",e,s);const m=l.listeners.app;switch(r.emit("onComposeBefore",{event:"App "+e,params:null!==(n=t[0])&&void 0!==n?n:{}}),e){case m.appCreate:case m.appShow:{const{path:e,query:i}=this.enterParamsParse(t[0]);!h&&a.originalSource&&g.setOriginalSource({path:e,query:i}),d?(Date.now()-d>c||g.lastScene&&g.scene!==g.lastScene)&&(o.sessionId="",p.currentPage.time=void 0,this.buildVisitEvent({path:e,query:i})):(this.growingIO.dataStore.lastVisitEvent={path:e,query:i},this.buildVisitEvent({path:e,query:i}));break}case m.appClose:g.lastScene=g.scene,g.lastCloseTime=Date.now(),v(),o.saveUserInfo(),this.buildCloseEvent(),a.forceLogin||u.initiateRequest(!0)}},this.enterParamsParse=e=>{const{gioPlatform:t,minipInstance:i,dataStore:n}=this.growingIO;let r="",o="";const a=(e,t={})=>{r=e,o=I(t).map((e=>`${e}=${t[e]}`)).join("&")};if("quickapp"!==t&&i.minip.canIUse("getEnterOptionsSync")){const{path:t,query:r,scene:l,referrerInfo:u}=i.minip.getEnterOptionsSync()||{},g=e.query||r;if(a(e.path||t,g),n.scene=e.scene||l,!P(u)&&s(null==u?void 0:u.extraData)){let e=[];S(u.extraData,((t,i)=>{!f(g,i)&&["string","number","boolean"].includes(T(t))&&e.push(`${i}=${t}`)}));const t=e.join("&");o=o&&t?`${o}&${t}`:o||t}}else{const{path:t,query:i}=e;a(t,i),this.parseScene(e)}return{path:r,query:o}},this.parseScene=e=>{var t;const{minipInstance:i,gioPlatform:n,dataStore:s}=this.growingIO;let r;if("quickapp"===n){const{extra:e,type:t}=i.getAppSource();r=(null==e?void 0:e.scene)||t}else P(e)||((null===(t=null==e?void 0:e.query)||void 0===t?void 0:t.wxShoppingListScene)?r=e.query.wxShoppingListScene:(null==e?void 0:e.scene)?r=e.scene:s.scene="NA");s.scene=r},this.buildVisitEvent=t=>{const{dataStore:i,vdsConfig:n,minipInstance:s}=this.growingIO,{originalSourceName:r,getOriginalSource:o,eventContextBuilder:a,eventInterceptor:l}=i,u=o(),g=(null==t?void 0:t.query)||"";let h=Object.assign({eventType:"VISIT"},a({path:(null==t?void 0:t.path)||"",query:"string"===T(g)?g:Q(g)}));n.originalSource&&!e(u)&&(h=Object.assign(Object.assign({},h),u),n.dataCollect&&s.removeStorageSync(r)),l(h)},this.buildCloseEvent=()=>{const{dataStore:{eventContextBuilder:e,eventInterceptor:t}}=this.growingIO;t(Object.assign({eventType:"APP_CLOSED"},e()))}}}class oe{constructor(e){this.growingIO=e,this.parsePage=(e,t)=>{var i;const n=e.route||e.uri||e.__route__||(null===(i=null==e?void 0:e.$page)||void 0===i?void 0:i.fullPath)||"";P(t)?this.query=void 0:this.query=this.getQuery(t),this.path!==n&&(this.time=Date.now()),this.path=n,this.title=this.settedTitle[this.path]||this.growingIO.minipInstance.getPageTitle(e||this.growingIO.minipInstance.getCurrentPage())},this.getQuery=e=>{const t=Object.assign({},e);return O(t,"wxShoppingListScene"),Q(t)},this.getReferralPage=()=>{const{minipInstance:e,dataStore:{lastPageEvent:t,scene:i}}=this.growingIO;return(null==t?void 0:t.path)||(i?`scn:${e.scnPrefix}${i}`:null)},this.saveShareId=e=>{(null==e?void 0:e.gioShareId)&&(this.queryShareId=e.gioShareId)},this.updateShareResult=e=>{const[t,i]=this.buildShareQuery(e);return e.path=$(t+(i?"?"+i:"")),e.query=i,e},this.updateAppMessageResult=this.updateShareResult,this.updateTimelineResult=this.updateShareResult,this.updateAddFavoritesResult=e=>{const[t,i]=this.buildShareQuery(e);return e.path=$(t+(i?"?"+i:"")),e.query=i,e},this.query=void 0,this.settedTitle={},this.pageProps={}}buildShareQuery(e){var t,i,n;const s=H(null!==(t=e.path)&&void 0!==t?t:"");let r=this.path,o={},u=f(e,"path");return u&&(r=a(s),o=W(l(s))||{}),P(o)&&(o=W(null!==(i=e.query)&&void 0!==i?i:"")||{}),!u&&P(o)&&(o=W(null!==(n=this.query)&&void 0!==n?n:"")||{}),[r,Q(o)]}}class ae{constructor(e){this.growingIO=e,this.main=(e,t,i)=>{var n,s;const o=Date.now(),{emitter:a,minipInstance:l,plugins:u,vdsConfig:g,platformConfig:h,dataStore:{shareOut:c,eventHooks:d,toggleShareOut:p,buildAppMessageEvent:v,buildTimelineEvent:m,buildAddFavorites:f},inPlugin:I}=this.growingIO,{currentPage:S}=d;if(this.prevEvent[t]&&50>Date.now()-Number(this.prevEvent[t]))return;e||(e=l.getCurrentPage()),e.route||(e.route=l.getCurrentPath(e));const y=e.route||e.uri||e.__route__||(null===(n=null==e?void 0:e.$page)||void 0===n?void 0:n.fullPath)||"";a.emit("minipLifecycle",{event:"Page "+t,timestamp:o,params:{page:e,args:i[0]}}),g.debug&&console.log("Page:",y,"#",t,o),this.prevEvent[t]=Date.now();const b=h.listeners.page;switch(a.emit("onComposeBefore",{page:e,event:"Page "+t,params:{page:e,args:i[0]}}),S.lastLifecycle=S.currentLifecycle,S.currentLifecycle=t,t){case b.pageLoad:this.argQuery[y]=w(e,"options")||w(e,"__displayReporter.query")||w(e,"$page.query")||w(e,"$wx.__displayReporter.query")||i[0]||{},O(this.argQuery[y],"$taroTimestamp"),S.parsePage(e,this.argQuery[y]);break;case b.pageShow:I?(S.parsePage(e,this.argQuery[y]),S.path||(S.path=`/插件${g.appId}}`,S.title=`/插件${g.appId}}`),this.buildPageEvent()):c&&d.currentPage.time||(S.parsePage(e,this.argQuery[y]),d.currentPage.time=Date.now(),this.buildPageEvent()),p(!1),S.saveShareId(this.argQuery[y]);break;case b.pageHide:case b.pageUnload:break;case b.shareApp:p(!0),g.followShare&&v(i);break;case b.shareTime:g.followShare&&m(i);break;case b.addFavorites:f(i);break;case b.tabTap:{const e=null===(s=null==u?void 0:u.gioEventAutoTracking)||void 0===s?void 0:s.buildTabClickEvent;g.autotrack&&e&&r(e)&&e(i[0]);break}}t===b.pageUnload&&(S.pageProps[y]=void 0)},this.buildPageEvent=e=>{var t;const{dataStore:{eventContextBuilder:i,eventInterceptor:n,eventHooks:s}}=this.growingIO,{currentPage:r}=s,o=Object.assign(Object.assign({eventType:"PAGE",referralPage:r.getReferralPage()},i()),{timestamp:r.time});P(r.pageProps[o.path])||(o.attributes=r.pageProps[o.path]),!P(e)&&e.path&&(o.path=e.path,o.query=e.query,o.title=null!==(t=e.title)&&void 0!==t?t:o.title),n(o)},this.prevEvent={},this.argQuery={}}}class le{constructor(e){var t,i;this.growingIO=e,this.isNormalFc=(e,t)=>r(t)&&"constructor"!==e,this.objectTraverse=(e,t)=>{Object.getOwnPropertyNames(e).forEach((i=>t(i,e))),f(e,"methods")&&Object.getOwnPropertyNames(e.methods).forEach((i=>{e[i]||t(i,e.methods)})),f(e,"lifetimes")&&Object.getOwnPropertyNames(e.lifetimes).forEach((i=>{e[i]||t(i,e.lifetimes)})),f(e,"pageLifetimes")&&Object.getOwnPropertyNames(e.pageLifetimes).forEach((i=>{e[i]||t(i,e.pageLifetimes)}))},this.supLifeFcs=(e,t)=>{o(this[t+"Handlers"])&&this[t+"Handlers"].forEach((t=>{r(e[t])||["onShareAppMessage","onShareTimeline"].includes(t)||(e[t]=()=>{})}))},this.lifeFcEffects=(e,t,i)=>{const n=this;return["onShareTimeline","onAddToFavorites"].includes(e)?function(...s){let r=t.apply(this,s);"onShareTimeline"===e&&n.growingIO.vdsConfig.followShare&&(r=n.currentPage.updateTimelineResult(null!=r?r:{})),"onAddToFavorites"===e&&(r=n.currentPage.updateAddFavoritesResult(null!=r?r:{}));const o=[].slice.call(s);return r&&o.push(r),n[`def${i}Cbs`][e].apply(this,o),r}:function(...s){var r;return se(this,void 0,void 0,(function*(){let o;try{if("onShareAppMessage"===e){if(o=null!==(r=yield t.apply(this,s))&&void 0!==r?r:{},"promise"===T(o.promise)){const e=function(){return se(this,void 0,void 0,(function*(){let e=o;return new Promise((t=>{let i=setTimeout((()=>{t(Object.assign({},e)),clearTimeout(i),i=void 0}),3e3);o.promise.then((n=>{e=n,t(Object.assign({},e)),clearTimeout(i),i=void 0}))}))}))};o=Object.assign(Object.assign({},o),yield e()),O(o,"promise")}n.growingIO.vdsConfig.followShare&&(o=n.currentPage.updateAppMessageResult(null!=o?o:{}))}const a=[].slice.call(s);o&&a.push(o),n[`def${i}Cbs`][e].apply(this,a)}catch(e){_(e,"error")}return"onShareAppMessage"!==e&&(o=t.apply(this,s)),n.growingIO.emitter.emit("minipLifecycle",{event:`${i} ${e}End`,timestamp:Date.now(),params:{instance:this,arguments:Array.from(s)}}),o}))}},this.customFcEffects=(e,t)=>{const i=this;return function(...n){var s,o;let a;if(i.growingIO.vdsConfig.autotrack&&i.growingIO.plugins.gioEventAutoTracking)try{let t=n[0]||{};f(t,"type")&&((null==t?void 0:t.currentTarget)||(null==t?void 0:t.target))||(t=n[n.length-1]),((null==t?void 0:t.currentTarget)||(null==t?void 0:t.target))&&i.actionEventTypes.includes(t.type)&&(r(i.actionEffects)||(i.actionEffects=(null===(o=null===(s=i.growingIO.plugins)||void 0===s?void 0:s.gioEventAutoTracking)||void 0===o?void 0:o.main)||function(){}),null==i||i.actionEffects(t,e))}catch(e){_(e,"error")}return a=t.apply(this,n),a}},this.appApplyProxy=(e,t)=>this.appHandlers.includes(e)?this.lifeFcEffects(e,t,"App"):this.customFcEffects(e,t),this.pageApplyProxy=(e,t)=>this.pageHandlers.includes(e)?this.lifeFcEffects(e,t,"Page"):this.customFcEffects(e,t),this.appOverriding=e=>(this.setAppEffectCbs(),this.supLifeFcs(e,"app"),this.objectTraverse(e,((e,t)=>{this.isNormalFc(e,t[e])&&(t[e]=this.appApplyProxy(e,t[e]))})),e),this.pageOverriding=e=>(this.setPageEffectCbs(),this.supLifeFcs(e,"page"),this.objectTraverse(e,((e,t)=>{this.isNormalFc(e,t[e])&&(t[e]=this.pageApplyProxy(e,t[e]))})),e),this.componentOverriding=e=>(this.setPageEffectCbs(),e.methods||(e.methods={}),this.supLifeFcs(this.growingIO.inPlugin?e:e.methods,"page"),this.objectTraverse(this.growingIO.inPlugin?e:e.methods,((e,t)=>{this.isNormalFc(e,t[e])&&(t[e]=this.pageApplyProxy(e,t[e]))})),e),this.setAppEffectCbs=()=>{const e=this;this.appHandlers.forEach((t=>{this.defAppCbs[t]=function(...i){e.appEffects.main(t,i)}}))},this.setPageEffectCbs=()=>{const e=this;this.pageHandlers.forEach((t=>{this.defPageCbs[t]=function(...i){e.pageEffects.main(this,t,i)}}))},this.growingApp=e=>this.originalApp(this.appOverriding(e)),this.growingPage=e=>this.originalPage(this.pageOverriding(e)),this.growingComponent=e=>this.originalComponent(this.componentOverriding(e)),this.growingBehavior=e=>this.originalBehavior(this.componentOverriding(e)),this.nativeGrowing=(e=["App","Page","Component","Behavior"])=>{const t=this,{platformConfig:i}=this.growingIO,n=i.hooks;if(this.setAppEffectCbs(),this.setPageEffectCbs(),e.includes("App"))try{n.App&&!this.appHooked&&(App=function(...e){return t.growingApp(e[0])},this.appHooked=!0)}catch(e){}if(e.includes("Page"))try{n.Page&&!this.pageHooked&&(Page=function(...e){return t.growingPage(e[0])},this.pageHooked=!0)}catch(e){}if(e.includes("Component"))try{n.Component&&!this.componentHooked&&(Component=function(...e){return t.growingComponent(e[0])},this.componentHooked=!0)}catch(e){}if(e.includes("Behavior"))try{n.Behavior&&!this.behaviorHooked&&(Behavior=function(...e){return t.growingBehavior(e[0])},this.behaviorHooked=!0)}catch(e){}},this.initEventHooks=()=>{const e=this,{platformConfig:t,gioPlatform:i}=this.growingIO;t.canHook?(this.nativeGrowing(),K().GioApp=k((()=>null!==App&&void 0!==App?App:window.GioApp)),K().GioPage=k((()=>null!==Page&&void 0!==Page?Page:window.GioPage)),K().GioComponent=k((()=>null!==Component&&void 0!==Component?Component:window.GioComponent)),K().GioBehavior=k((()=>Behavior))):"quickapp"===i&&(window.GioApp=function(...t){return e.appOverriding(t[0])},window.GioPage=function(...t){return e.pageOverriding(t[0])},window.GioComponent=function(...t){return e.pageOverriding(t[0])})};const n=null===(t=this.growingIO)||void 0===t?void 0:t.platformConfig;this.defAppCbs={},this.defPageCbs={},this.appHandlers=n.appHandlers,this.pageHandlers=n.pageHandlers,this.actionEventTypes=n.actionEventTypes,this.originalApp=n.originalApp,this.originalPage=n.originalPage,this.originalComponent=n.originalComponent,this.originalBehavior=null!==(i=n.originalBehavior)&&void 0!==i?i:function(){},this.appEffects=new re(this.growingIO),this.pageEffects=new ae(this.growingIO),this.currentPage=new oe(this.growingIO)}}class ue{constructor(i){var s,l;this.growingIO=i,this.ALLOW_SETTING_KEYS=I(Y),this.gsidStorageName="_growing_gsid_",this.originalSourceName="gdp_original_source",this.initStorageInfo=()=>{const{minipInstance:e}=this.growingIO,t=R(),i=t.gio_gsid?t.gio_gsid:Number.parseInt(e.getStorageSync(this.gsidStorageName),10);this._gsid=Number.isNaN(i)||i>=1e9||1>i?1:i,this._stid=this._gsid,i!==this._gsid&&e.setStorageSync(this.gsidStorageName,this._gsid)},this.saveStorageInfo=()=>{const{minipInstance:e}=this.growingIO;this._stid=this._gsid,V(e,[{key:this.gsidStorageName,value:this._gsid}])},this.setOriginalSource=({path:t,query:i})=>{const{minipInstance:n}=this.growingIO;if(e(this.getOriginalSource())){const e={path:t,query:i,title:""};n.setStorageSync(this.originalSourceName,JSON.stringify(e))}},this.getOriginalSource=()=>{const{minipInstance:e}=this.growingIO;return k((()=>JSON.parse(e.getStorageSync(this.originalSourceName))))},this.initOptions=e=>{var t,i,n,s,r,a,l,u;const{projectId:g,dataSourceId:h,appId:c}=e,d={};this.ALLOW_SETTING_KEYS.forEach((t=>{const i=Y[t].type;(o(i)?i.includes(T(e[t])):T(e[t])===Y[t].type)?"ignoreFields"===t?d.ignoreFields=e.ignoreFields.filter((e=>te.includes(e))):"extraParams"===t?d.extraParams=e.extraParams.filter((e=>ie.includes(e))):d[t]=e[t]:d[t]=Y[t].default})),d.uploadInterval=Math.round(d.uploadInterval),(Number.isNaN(d.uploadInterval)||0>d.uploadInterval||d.uploadInterval>2e3)&&(d.uploadInterval=1e3),d.enableIdMapping&&!d.idMapping&&(d.idMapping=!0),d.pluginMode&&(this.growingIO.inPlugin=!0),this.growingIO.vdsConfig=Object.assign(Object.assign({},d),{projectId:g,dataSourceId:h,appId:c,performance:{monitor:null===(i=null===(t=d.performance)||void 0===t?void 0:t.monitor)||void 0===i||i,exception:null===(s=null===(n=d.performance)||void 0===n?void 0:n.exception)||void 0===s||s,network:null!==(a=null===(r=d.performance)||void 0===r?void 0:r.network)&&void 0!==a&&a}}),this.keepAlive=d.keepAlive,d.dataCollect||_("已关闭数据采集","info"),d.autotrack||_("已关闭无埋点","info");const{plugins:p,inPlugin:v,minipInstance:m}=this.growingIO,{uniVue:f,taro:I}=d;f||I||(this.growingIO.platformConfig.canHook=!0),v&&!["tbp","jdp"].includes(m.platform)||this.eventHooks.initEventHooks(),f&&(null===(l=null==p?void 0:p.gioUniAppAdapter)||void 0===l||l.main()),I&&(null===(u=null==p?void 0:p.gioTaroAdapter)||void 0===u||u.main())},this.setOption=(e,i)=>{var n;const{vdsConfig:s,userStore:r,uploader:o,emitter:a}=this.growingIO,l=t(e)&&this.ALLOW_SETTING_KEYS.includes(e),u=l&&typeof i===(null===(n=Y[e])||void 0===n?void 0:n.type);if(l&&u){if("dataCollect"===e&&!1===s.dataCollect&&!0===i){let e=setTimeout((()=>{r.sessionId="";const{path:t,query:i,settedTitle:n}=this.eventHooks.currentPage;this.eventHooks.currentPage.title=n[t]||this.growingIO.minipInstance.getPageTitle(this.growingIO.minipInstance.getCurrentPage()),this.sendVisit({path:t,query:i}),this.eventHooks.currentPage.time=Date.now(),this.sendPage({path:t,query:i}),clearTimeout(e),e=null}),0)}return s[e]=i,"serverUrl"===e&&(null==o||o.generateURL()),a.emit("OPTION_CHANGE",{optionName:e,optionValue:i}),!0}return E("setOption > "+e),!1},this.getOption=t=>{const{vdsConfig:i}=this.growingIO;return t&&f(i,c(t))?i[c(t)]:e(t)?Object.assign({},i):void E("getOption > "+t)},this.toggleShareOut=e=>{n(e)?this.shareOut=e:this.shareOut=!this.shareOut},this.sendVisit=e=>{this.eventHooks.appEffects.buildVisitEvent(null!=e?e:this.lastVisitEvent),this.eventHooks.currentPage.time=Date.now()},this.sendPage=e=>{this.eventHooks.pageEffects.buildPageEvent(e)},this.eventConverter=e=>{const{vdsConfig:t,dataStore:i,uploader:n}=this.growingIO;if(t.dataCollect){["LOGIN_USER_ATTRIBUTES","APP_CLOSED"].includes(e.eventType)||(e.eventSequenceId=i.gsid,this.growingIO.dataStore.gsid+=1);const t={};S(e,((e,i)=>{var n;if("element"===i){const i=null!==(n=a(e))&&void 0!==n?n:{};S(i,((e,i)=>{P(e)&&0!==e||(t[i]=e)}))}else P(e)&&0!==e||(t[i]=e)})),this.growingIO.emitter.emit("onComposeAfter",{composedEvent:t}),n.commitRequest(Object.assign(Object.assign({},t),{requestId:q()}))}},this.eventInterceptor=e=>{const{systemInfo:t,network:i}=this.growingIO.minipInstance;P(t)||P(i)?this.interceptEvents.push(e):P(this.interceptEvents)?this.eventConverter(e):([...this.interceptEvents,e].forEach((e=>{const t=Object.assign(Object.assign({},e),this.eventContextBuilder({path:e.path,query:e.query,timestamp:e.timestamp}));this.eventConverter(t)})),this.interceptEvents=[])},this.eventReleaseInspector=()=>{const{minipInstance:{systemInfo:e,network:t}}=this.growingIO;e&&t&&!P(this.interceptEvents)&&([...this.interceptEvents].forEach((e=>{const t=Object.assign(Object.assign({},e),this.eventContextBuilder({path:e.path,query:e.query,timestamp:e.timestamp}));this.eventConverter(t)})),this.interceptEvents=[])},this.buildAppMessageEvent=e=>{var t;const i=e[0];let n;2>e.length?1===e.length&&(n=i):n=e[1];const{dataStore:{eventContextBuilder:s,eventInterceptor:r}}=this.growingIO,o=((null==n?void 0:n.path)||"").split("?");r(Object.assign({eventType:"CUSTOM",eventName:"$mp_on_share",attributes:Object.assign({$from:i.from,$target:null===(t=null==i?void 0:i.target)||void 0===t?void 0:t.id,$share_title:null==n?void 0:n.title,$share_path:a(o),$share_query:o[1]},null==n?void 0:n.attributes)},s()))},this.buildTimelineEvent=e=>{var t;const i=e[0];let n;2>e.length?1===e.length&&(n=i):n=e[1];const{dataStore:{eventContextBuilder:s,eventInterceptor:r}}=this.growingIO,o=((null==n?void 0:n.path)||"").split("?");r(Object.assign({eventType:"CUSTOM",eventName:"$mp_share_timeline",attributes:Object.assign({$target:null===(t=null==i?void 0:i.target)||void 0===t?void 0:t.id,$share_title:null==n?void 0:n.title,$share_path:a(o),$share_query:o[1]},null==n?void 0:n.attributes)},s()))},this.buildAddFavorites=e=>{const t=e[0];let i;2>e.length?1===e.length&&(i=t):i=e[1];const{dataStore:{eventContextBuilder:n,eventInterceptor:s}}=this.growingIO,r=((null==i?void 0:i.path)||"").split("?");s(Object.assign({eventType:"CUSTOM",eventName:"$mp_add_favorites",attributes:{$share_title:null==i?void 0:i.title,$share_path:a(r),$share_query:r[1]}},n()))},this.initStorageInfo(),this.eventContextBuilder=new ne(this.growingIO).main,this.shareOut=!1,this.lastVisitEvent={},this.lastPageEvent={},this.locationData={},this.generalProps={},this.trackTimers={},this.interceptEvents=[],this.eventHooks=new le(this.growingIO),this.growingIO.emitter.on("onComposeAfter",(({composedEvent:e})=>{"VISIT"!==e.eventType&&"vst"!==e.t||(this.lastVisitEvent=e),"PAGE"!==e.eventType&&"page"!==e.t||(this.lastPageEvent=e)})),r(null===(s=this.growingIO.minipInstance.minip)||void 0===s?void 0:s.onAppHide)&&this.growingIO.minipInstance.minip.onAppHide((()=>{S(this.trackTimers,(e=>{e.start&&(e.leng=e.leng+(+Date.now()-e.start))}))})),r(null===(l=this.growingIO.minipInstance.minip)||void 0===l?void 0:l.onAppShow)&&this.growingIO.minipInstance.minip.onAppShow((()=>{S(this.trackTimers,(e=>{e.start&&(e.start=+Date.now())}))})),this.growingIO.emitter.on("OPTION_CHANGE",(({optionName:e,optionValue:t})=>{"dataCollect"===e&&!1===t&&this.growingIO.clearTrackTimer()}))}get gsid(){const e=R(),t=F(e);return!P(t)&&e.gio_gsid?e.gio_gsid:this._gsid}set gsid(e){const t=Number.parseInt(e,10);this._gsid=Number.isNaN(t)||e>=1e9||1>e?1:e,R().gio_gsid=this._gsid,10>this._gsid-this._stid||this.saveStorageInfo()}get scene(){return this._scene}set scene(e){const t=this._scene;this._scene=e,t!==this._scene&&this.growingIO.emitter.emit("SCENE_UPDATE",{newScene:e,oldScene:t})}}const ge={scnPrefix:"",appHandlers:["onLaunch","onShow","onHide","onError","onPageNotFound","onUnhandledRejection","onThemeChange"],pageHandlers:["onLoad","onShow","onReady","onHide","onShareAppMessage","onTabItemTap","onUnload","onPullDownRefresh","onReachBottom","onResize"],actionEventTypes:["onclick","tap","onTap","longpress","longTap","blur","change","onChange","submit","confirm","getuserinfo","getphonenumber","contact","mouseup"],originalApp:k((()=>App)),originalPage:k((()=>Page)),originalComponent:k((()=>Component)),originalBehavior:k((()=>Behavior)),canHook:!0,hooks:{App:!0,Page:!0,Component:!0,Behavior:!0},listeners:{app:{appLaunch:"onLaunch",appShow:"onShow",appClose:"onHide"},page:{pageLoad:"onLoad",pageShow:"onShow",pageReady:"onReady",pageHide:"onHide",pageUnload:"onUnload",tabTap:"onTabItemTap",shareApp:"onShareAppMessage"},actions:{click:["onclick","tap","longpress","longTap","getuserinfo","getphonenumber","contact","mouseup"],change:["blur","change","confirm"],submit:["submit"]}}},he=Object.assign(Object.assign({},ge),{listeners:Object.assign({},ge.listeners),name:"Weixin",platform:"MinP"});he.pageHandlers=[...ge.pageHandlers,"onShareTimeline","onAddToFavorites"],he.listeners.page=Object.assign(Object.assign({},ge.listeners.page),{shareTime:"onShareTimeline",addFavorites:"onAddToFavorites"});class ce{constructor(e){this.growingIO=e,this.minip=U("wx"),this.hookSetTitle=()=>{var e;const t=null===(e=this.minip)||void 0===e?void 0:e.setNavigationBarTitle,i=this;t&&Object.defineProperty(this.minip,"setNavigationBarTitle",{writable:!0,enumerable:!0,configurable:!0,value:function(){if(i.growingIO.gioSDKInitialized){const e=i.getCurrentPath(),{title:t}=arguments[0]||{};i.growingIO.dataStore.eventHooks.currentPage.settedTitle[e]=t}return t.apply(this,arguments)}})},this.navigateTo=e=>{var t;return null===(t=this.minip)||void 0===t?void 0:t.navigateTo(e)},this.switchTab=e=>{var t;null===(t=this.minip)||void 0===t||t.switchTab(e)},this.navigateToMiniProgram=e=>{var t;return null===(t=this.minip)||void 0===t?void 0:t.navigateToMiniProgram(e)},this.getImageInfo=({src:e,success:t,fail:i,complete:n})=>{var s;return null===(s=this.minip)||void 0===s?void 0:s.getImageInfo({src:e,success:t,fail:i,complete:n})},this.initImpression=e=>{var t,i;null===(i=null===(t=this.growingIO.plugins)||void 0===t?void 0:t.gioImpressionTracking)||void 0===i||i.main(e,"observeAll")},this.getCurrentPage=()=>k((()=>l(getCurrentPages())))||{},this.getCurrentPath=()=>{const e=this.getCurrentPage();return(null==e?void 0:e.route)||(null==e?void 0:e.uri)||(null==e?void 0:e.__route__)||""},this.getPageTitle=e=>{var i,n;let s="";const r=L(B());try{const o=(null==e?void 0:e.data)||e.$data||{};if(s=t(null==o?void 0:o.gioPageTitle)?null==o?void 0:o.gioPageTitle:"",0===s.length){const t=r.page[e.route]||r.page[e.route+".html"];s=t?t.window.navigationBarTitleText:r.global.window.navigationBarTitleText}if(0===s.length){const t=null===(n=null===(i=null==r?void 0:r.tabBar)||void 0===i?void 0:i.list)||void 0===n?void 0:n.find((t=>t.pagePath===e.route||t.pagePath===e.route+".html"));s=(null==t?void 0:t.text)||""}}catch(e){return""}return A(s)},this.getStorageSync=e=>{var t;let i=null===(t=this.minip)||void 0===t?void 0:t.getStorageSync(e);return s(i)&&i.expiredAt?i.expiredAt<Date.now()?"":i.value:i},this.getStorage=e=>new Promise((t=>{var i;null===(i=this.minip)||void 0===i||i.getStorage({key:e,success:({data:e})=>t(e),fail:()=>t("")})})),this.setStorageSync=(e,t,i)=>{var n;i&&(t={value:t,expiredAt:i}),null===(n=this.minip)||void 0===n||n.setStorageSync(e,t)},this.setStorage=(e,t)=>{var i;null===(i=this.minip)||void 0===i||i.setStorage({key:e,data:t})},this.removeStorageSync=e=>{var t;null===(t=this.minip)||void 0===t||t.removeStorageSync(e)},this.removeStorage=e=>{var t;null===(t=this.minip)||void 0===t||t.removeStorage(e)},this.getNetworkType=()=>{const e=this;return new Promise((t=>{var i;null===(i=this.minip)||void 0===i||i.getNetworkType({success:i=>{e.network=i,t(i)},fail:()=>t(null)})}))},this.request=({url:e,data:t,header:i,timeout:n,method:s,success:o,fail:a,complete:l})=>{var u;const g=null===(u=this.minip)||void 0===u?void 0:u.request({url:e,data:t,header:i,headers:i,timeout:n,method:s,success:o,fail:a,complete:l});let h=setTimeout((()=>{(null==g?void 0:g.abort)&&r(null==g?void 0:g.abort)&&(null==g||g.abort()),clearTimeout(h),h=null}),(n||1e4)+10);return g},this.getSystemInfo=()=>{const e=this;return new Promise((t=>{var i;null===(i=this.minip)||void 0===i||i.getSystemInfo({success:i=>{e.systemInfo=i,t(i)},fail:()=>t(null)})}))},this.getSetting=()=>new Promise((e=>{var t;null===(t=this.minip)||void 0===t||t.getSetting({success:e,fail:e})}));const{platformConfig:{platform:i,scnPrefix:n}}=this.growingIO;this.platform=i,this.scnPrefix=n,this.growingIO.emitter.on("OPTION_INITIALIZED",(()=>{this.getNetworkType().then((()=>{var e;return null===(e=this.growingIO.dataStore)||void 0===e?void 0:e.eventReleaseInspector()})),this.getSystemInfo().then((()=>{var e;return null===(e=this.growingIO.dataStore)||void 0===e?void 0:e.eventReleaseInspector()}))}))}}class de extends ce{constructor(e){super(e),this.growingIO=e,this.hookSetTitle()}}let pe;const ve={};var me,fe,Ie;fe={name:"gioCustomTracking",method:class{constructor(e){this.growingIO=e,this.getDynamicAttributes=e=>(pe.isNil(e)||pe.keys(e).forEach((t=>{pe.isFunction(e[t])?e[t]=e[t]():pe.isArray(e[t])||(e[t]=pe.toString(e[t]))})),e),this.buildCustomEvent=(e,t)=>{pe.eventNameValidate(e,(()=>{const{dataStore:{eventContextBuilder:i,eventInterceptor:n}}=this.growingIO;n(Object.assign({eventType:"CUSTOM",eventName:e,attributes:pe.limitObject(this.getDynamicAttributes(pe.isObject(t)&&!pe.isEmpty(t)?t:void 0))},i()))}))},this.buildUserAttributesEvent=e=>{const{dataStore:{eventContextBuilder:t,eventInterceptor:i,lastVisitEvent:n}}=this.growingIO,s=Object.assign({eventType:"LOGIN_USER_ATTRIBUTES",attributes:pe.limitObject(e)},t());s.path||(s.path=n.path,s.query=n.query,s.title=n.title),i(s)},pe=this.growingIO.utils}}},Ie=ve,(me=["pluginsIn","gioCustomTracking"]).map((function(e,t){Ie[e]=t==me.length-1?fe:Ie[e]||{},Ie=Ie[e]}));class Se{constructor(e){this.growingIO=e,this.innerPluginInit=()=>{I(ve.pluginsIn).forEach((e=>{const{name:t,method:i}=ve.pluginsIn[e],n=this.pluginItems.find((e=>e.name===t));n||this.pluginItems.push({name:p(t||e),method:i||(e=>{})})})),P(this.pluginItems)||this.installAll()},this.install=(e,t,i)=>{var n;const s=t||this.pluginItems.find((t=>t.name===e));if(null===(n=this.growingIO)||void 0===n?void 0:n.plugins[e])return _(`重复加载插件 ${e} 或插件重名,已跳过加载!`,"warn"),!1;if(!s)return _(`插件加载失败!不存在名为 ${e} 的插件!`,"error"),!1;try{return this.growingIO.plugins[e]=new s.method(this.growingIO,i),t&&_("加载插件:"+e,"info"),!0}catch(t){return _(`插件【${e}】加载异常 ${t}`,"error"),!1}},this.installAll=e=>{(e||this.pluginItems).forEach((t=>this.install(t.name,e?t:void 0,t.options)))},this.uninstall=e=>{var t;O(this.pluginItems,e);const i=O(null===(t=this.growingIO)||void 0===t?void 0:t.plugins,e);return i||_(`卸载插件 ${e} 失败!`,"error"),i},this.uninstallAll=()=>{this.pluginItems.forEach((e=>this.uninstall(e.name)))},this.lifeError=(e,t)=>_(`插件执行错误 ${e.name} ${t}`,"error"),this.onComposeBefore=e=>{this.pluginItems.forEach((t=>{var i;const n=null===(i=this.growingIO.plugins[t.name])||void 0===i?void 0:i.onComposeBefore;if(n&&r(n))try{n(e)}catch(e){this.lifeError(t,e)}}))},this.onComposeAfter=e=>{this.pluginItems.forEach((t=>{var i;const n=null===(i=this.growingIO.plugins[t.name])||void 0===i?void 0:i.onComposeAfter;if(n&&r(n))try{n(e)}catch(e){this.lifeError(t,e)}}))},this.onSendBefore=e=>{this.pluginItems.forEach((t=>{var i;const n=null===(i=this.growingIO.plugins[t.name])||void 0===i?void 0:i.onSendBefore;if(n&&r(n))try{n(e)}catch(e){this.lifeError(t,e)}}))},this.onSendAfter=e=>{this.pluginItems.forEach((t=>{var i;const n=null===(i=this.growingIO.plugins[t.name])||void 0===i?void 0:i.onSendAfter;if(n&&r(n))try{n(e)}catch(e){this.lifeError(t,e)}}))},this.pluginItems=[],this.growingIO.emitter.on("onComposeBefore",this.onComposeBefore),this.growingIO.emitter.on("onComposeAfter",this.onComposeAfter),this.growingIO.emitter.on("onSendBefore",this.onSendBefore),this.growingIO.emitter.on("onSendAfter",this.onSendAfter)}}var ye={},we={}.hasOwnProperty;function Oe(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function be(e){try{return encodeURIComponent(e)}catch(e){return null}}ye.stringify=function(e,t){t=t||"";var i,n,s=[];for(n in"string"!=typeof t&&(t="?"),e)if(we.call(e,n)){if((i=e[n])||null!=i&&!isNaN(i)||(i=""),n=be(n),i=be(i),null===n||null===i)continue;s.push(n+"="+i)}return s.length?t+s.join("&"):""},ye.parse=function(e){for(var t,i=/([^=?#&]+)=?([^&]*)/g,n={};t=i.exec(e);){var s=Oe(t[1]),r=Oe(t[2]);null===s||null===r||s in n||(n[s]=r)}return n};class Pe{constructor(e){this.growingIO=e,this.generateURL=()=>{const{serverUrl:e,projectId:t}=this.growingIO.vdsConfig;return v(e,"http")?`${e}/v3/projects/${t}/collect`:`https://${e}/v3/projects/${t}/collect`},this.commitRequest=e=>{const t=Object.assign({},e),{vdsConfig:i}=this.growingIO;i.forceLogin?this.hoardingQueue.push(t):(this.requestQueue.push(t),this.initiateRequest())},this.initiateRequest=e=>{var t,i;const{plugins:n,vdsConfig:s}=this.growingIO;[...this.hoardingQueue,...this.requestQueue].length>0&&this.requestingNum<this.requestLimit&&((null===(t=null==s?void 0:s.tbConfig)||void 0===t?void 0:t.cloudFuncSend)?null===(i=null==n?void 0:n.gioTaobaoAdapter)||void 0===i||i.singleInvoke():e?this.batchInvoke():this.batchInvokeThrottle())},this.batchInvoke=()=>{var e,t;const{vdsConfig:i,plugins:n,emitter:s}=this.growingIO;let r=[...this.hoardingQueue,...this.requestQueue];r.length>50?(r=r.slice(0,50),this.hoardingQueue.length>50?this.hoardingQueue=this.hoardingQueue.slice(50):(this.hoardingQueue=[],this.requestQueue=this.requestQueue.slice(50-this.hoardingQueue.length))):(this.hoardingQueue=[],this.requestQueue=[]);let o=r.filter((e=>(this.retryIds[e.requestId]||0)<=this.retryLimit));if(P(o))return;const a=o.map((e=>{const t=Object.assign({},e);return O(t,"requestId"),t}));i.debug&&console.log("[GrowingIO Debug]:",JSON.stringify(a,null,2)),s.emit("onSendBefore",{requestData:a}),(null===(e=null==i?void 0:i.tbConfig)||void 0===e?void 0:e.cloudAppId)?null===(t=null==n?void 0:n.gioTaobaoAdapter)||void 0===t||t.tbCloudAppInvoke(a):this.normalBatchInvoke(o,a)},this.batchInvokeThrottle=b(this.batchInvoke,this.growingIO.vdsConfig.uploadInterval,!1,!1),this.normalBatchInvoke=(e,t)=>{var i;const{minipInstance:n,vdsConfig:s,emitter:r,plugins:a}=this.growingIO;this.requestingNum+=1;const l={"content-type":"jdp"===n.platform?"application/json":"application/json;charset=UTF-8"};let u=[...t];const g=s.compress&&(null===(i=null==a?void 0:a.gioCompress)||void 0===i?void 0:i.compressToUTF16);g&&(u=a.gioCompress.compressToUTF16(JSON.stringify(t)),l["X-Compress-Codec"]="1"),n.request({url:`${this.requestURL}?stm=${Date.now()}&compress=${g?"1":"0"}`,header:l,method:"POST",data:u,timeout:this.requestTimeout,fail:t=>{[200,204].includes(t.code)||(o(e)?e.forEach((e=>{this.requestFailFn(e)})):this.requestFailFn(e),_("请求失败!"+JSON.stringify(t),"error"))},complete:e=>{this.requestingNum-=1,r.emit("onSendAfter",{result:e}),this.initiateRequest()}})},this.requestFailFn=e=>{this.retryIds[e.requestId]||(this.retryIds[e.requestId]=0),this.retryIds[e.requestId]+=1;const t=this.requestQueue.some((t=>t.requestId===e.requestId));if(!t){let t=setTimeout((()=>{P(this.requestQueue)?(this.requestQueue.push(e),this.initiateRequest()):this.requestQueue.push(e),clearTimeout(t),t=null}),800)}},this.hoardingQueue=[],this.requestQueue=[],this.requestLimit=3,this.requestTimeout=5e3,this.retryLimit=2,this.retryIds={},this.requestingNum=0,this.requestURL=this.generateURL()}}class Te{constructor(e){var t;this.growingIO=e,this.initUserInfo=()=>{var e;const{minipInstance:t}=this.growingIO,i=[this.uidStorageName,this.userIdStorageName,this.userKeyStorageName,this.gioIdStorageName],n=null!==(e=M(t,i))&&void 0!==e?e:[];["_uid","_userId","_userKey","_gioId"].forEach(((e,t)=>{this[e]=n[t],"_uid"!==e||this[e]||(this.uid=q())}))},this.saveUserInfo=()=>{const{minipInstance:e}=this.growingIO;V(e,[{key:this.uidStorageName,value:this.uid},{key:this.userIdStorageName,value:this.userId},{key:this.userKeyStorageName,value:this.userKey},{key:this.gioIdStorageName,value:this.gioId}])};const{inPlugin:i}=this.growingIO;this.uidStorageName=i?"_growing_plugin_uid_":"_growing_uid_",this.userIdStorageName=i?"_growing_plugin_userId_":"_growing_userId_",this.userKeyStorageName=i?"_growing_plugin_userKey_":"_growing_userKey_",this.gioIdStorageName=i?"_growing_plugin_gioId_":"_growing_gioId_",this._sessionId=q(),this._uid=void 0,this._userId=void 0,this._userKey=void 0,this._gioId=void 0,"quickapp"!==(null===(t=this.growingIO)||void 0===t?void 0:t.gioPlatform)&&this.initUserInfo()}get sessionId(){return this._sessionId||(this._sessionId=q()),this._sessionId}set sessionId(e){const t=this._sessionId;this._sessionId=e||q(),t!==this._sessionId&&this.growingIO.emitter.emit("SESSIONID_UPDATE",{newSessionId:this._sessionId,oldSessionId:t})}get uid(){return this._uid}set uid(e){const t=this._uid;this._uid=e,t!==this._uid&&(this.growingIO.minipInstance.setStorage(this.uidStorageName,this._uid),this.growingIO.emitter.emit("UID_UPDATE",{newUId:e,oldUId:t}))}get userId(){return this._userId}set userId(e){const t=this._userId;this._userId=e,t!==this._userId&&(this.growingIO.minipInstance.setStorage(this.userIdStorageName,this._userId),this.growingIO.emitter.emit("USERID_UPDATE",{newUserId:e,oldUserId:t})),e&&(this.gioId=e)}get userKey(){return this._userKey}set userKey(e){const t=this._userKey;this._userKey=e,t!==this._userKey&&(this.growingIO.minipInstance.setStorage(this.userKeyStorageName,this._userKey),this.growingIO.emitter.emit("USERKEY_UPDATE",{newUserKey:e,oldUserKey:t}))}get gioId(){return this._gioId}set gioId(e){const t=this._gioId;this._gioId=e,t!==this._gioId&&(this.growingIO.minipInstance.setStorage(this.gioIdStorageName,this._gioId),this.growingIO.emitter.emit("GIOID_UPDATE",{newGioId:e,oldGioId:t}))}}const Ce=new class{constructor(){var t;this.registerPlugins=e=>{this.plugins.pluginItems=[...this.plugins.pluginItems,...e],this.plugins.installAll(e)},this.init=e=>{var t;return _("Gio小程序SDK 初始化中...","info"),this.dataStore.initOptions(e),null===(t=this.emitter)||void 0===t||t.emit("OPTION_INITIALIZED",this),this.gioSDKInitialized=!0,this.vdsConfig.subpackage||(R().__gio__=()=>this),this.uploader=new Pe(this),this.vdsConfig.idMapping||(this.userStore.userKey=""),this.emitter.emit("SDK_INITIALIZED",this),_("Gio小程序SDK 初始化完成!","success"),this.vdsConfig.forceLogin&&_("forceLogin已开启,请调用 identify 方法设置 openId 以继续上报!","info"),this.inPlugin&&"tbp"!==this.minipInstance.platform&&this.dataStore.sendVisit(),!0},this.getOption=e=>this.dataStore.getOption(e),this.setOption=(e,t)=>{if(I(X).includes(e)){const i=this.dataStore.setOption(e,t);return i&&X[e]&&_(`已${t?"开启":"关闭"}${X[e]}`,"info"),i}return _(`不存在可修改的配置项:${e},请检查后重试!`,"warn"),!1},this.getDeviceId=()=>this.userStore.uid,this.identify=e=>{if(this.vdsConfig.forceLogin){if(!J(e))return void E("identify");const t=c(e).slice(0,1e3);this.userStore.uid=t,this.uploader.hoardingQueue.forEach(((e,i)=>this.uploader.hoardingQueue[i].deviceId=t)),this.dataStore.setOption("forceLogin",!1),this.uploader.initiateRequest(!0)}else E("identify",!1,"forceLogin未开启")},this.setUserId=(t,i)=>{if(J(t)){const n=this.userStore.gioId;if(t=c(t).slice(0,1e3),i=c(i).slice(0,1e3),this.userStore.userId=t,this.vdsConfig.idMapping&&(this.userStore.userKey=e(i)?"":i),n&&n!==t){this.userStore.sessionId="";const{path:e,query:t,settedTitle:i}=this.dataStore.eventHooks.currentPage;this.dataStore.eventHooks.currentPage.title=i[e]||this.minipInstance.getPageTitle(this.minipInstance.getCurrentPage()),this.dataStore.sendVisit({path:e,query:t})}}else E("setUserId")},this.clearUserId=()=>{this.userStore.userId=void 0,this.userStore.userKey=void 0},this.setUserAttributes=e=>{var t,i;!P(e)&&s(e)?null===(i=null===(t=this.plugins)||void 0===t?void 0:t.gioCustomTracking)||void 0===i||i.buildUserAttributesEvent(e):E("setUserAttributes")},this.track=(e,t)=>{var i,n;((null===(n=null===(i=this.plugins)||void 0===i?void 0:i.gioCustomTracking)||void 0===n?void 0:n.buildCustomEvent)||function(){})(e,Object.assign(Object.assign({},this.dataStore.generalProps),s(t)&&!P(t)?t:{}))},this.trackTimerStart=e=>!!this.vdsConfig.dataCollect&&N(e,(()=>{const t=q();return this.dataStore.trackTimers[t]={eventName:e,leng:0,start:+Date.now()},t})),this.trackTimerPause=e=>{if(e&&this.dataStore.trackTimers[e]){const t=this.dataStore.trackTimers[e];return t.start&&(t.leng=t.leng+(+Date.now()-t.start)),t.start=0,!0}return!1},this.trackTimerResume=e=>{if(e&&this.dataStore.trackTimers[e]){const t=this.dataStore.trackTimers[e];return 0===t.start&&(t.start=+Date.now()),!0}return!1},this.trackTimerEnd=(e,t)=>{if(this.vdsConfig.dataCollect){const i=864e5;if(e&&this.dataStore.trackTimers[e]){const n=this.dataStore.trackTimers[e];if(0!==n.start){const e=+Date.now()-n.start;n.leng=e>0?n.leng+e:0}const{eventContextBuilder:s,eventInterceptor:r}=this.dataStore;return r(Object.assign(Object.assign({eventType:"CUSTOM",eventName:n.eventName,attributes:G(Object.assign(Object.assign({},t),{event_duration:n.leng>i?0:n.leng/1e3}))},s()),{customEventType:0})),this.removeTimer(e),!0}return _("未查找到对应的计时器,请检查!","error"),!1}return!1},this.removeTimer=e=>!(!e||!this.dataStore.trackTimers[e]||(delete this.dataStore.trackTimers[e],0)),this.clearTrackTimer=()=>{this.dataStore.trackTimers={}},this.setGeneralProps=e=>{s(e)&&!P(e)?(this.dataStore.generalProps=Object.assign(Object.assign({},this.dataStore.generalProps),e),I(this.dataStore.generalProps).forEach((e=>{[void 0,null].includes(this.dataStore.generalProps[e])&&(this.dataStore.generalProps[e]="")}))):E("setGeneralProps")},this.clearGeneralProps=e=>{o(e)&&!P(e)?e.forEach((e=>{O(this.dataStore.generalProps,e)})):this.dataStore.generalProps={}},this.setPageAttributes=e=>{const{currentPage:t}=this.dataStore.eventHooks,i=this.minipInstance.getCurrentPath();["onLoad","attached"].includes(t.currentLifecycle)&&(t.pageProps[i]=G(e))},this.updateImpression=()=>{_("当前未集成半自动浏览插件,请集成插件后再调用 updateImpression!","warn")},this.setLocation=(e,t)=>{const i={latitude:e,longitude:t},n=this.dataStore.locationData,s=e=>e>=-180&&180>=e;s(e)&&s(t)&&(n.latitude!==e||n.longitude!==t)&&(this.dataStore.locationData=i)},this.getGioInfo=()=>{const{uid:e,userId:t,userKey:i,sessionId:n}=this.userStore,{projectId:s,appId:r,dataSourceId:o,dataCollect:a,idMapping:l,extraParams:u,ignoreFields:g}=this.vdsConfig,h={gioappid:r,giocs1:t||"",gioplatform:this.platformConfig.platform,gioprojectid:s,gios:n,giou:e};return h.giodatacollect=a,h.giodatasourceid=o,l&&(h.giouserkey=i),P(u)||u.forEach((e=>{g.includes(e)||(h["gio"+e]=this.dataStore.lastVisitEvent[e])})),ye.stringify(h)},this.utils=Object.assign(Object.assign(Object.assign({},C),z),{qs:ye}),this.emitter={all:t=t||new Map,on:function(e,i){var n=t.get(e);n?n.push(i):t.set(e,[i])},off:function(e,i){var n=t.get(e);n&&(i?n.splice(n.indexOf(i)>>>0,1):t.set(e,[]))},emit:function(e,i){var n=t.get(e);n&&n.slice().map((function(e){e(i)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,i)}))}},this.gioPlatform="wx",this.gioFramework="native",this.sdkVersion="4.0.0";try{"quickapp"===this.gioPlatform||r(getApp)&&r(App)?this.inPlugin=!1:this.inPlugin=!0}catch(e){this.inPlugin=!0}this.inPlugin&&_("未检测到小程序实例,自动切换为插件模式!","info"),this.platformConfig=he,this.minipInstance=new de(this),this.dataStore=new ue(this),this.userStore=new Te(this),this.plugins=new Se(this),this.plugins.innerPluginInit()}},_e=function(){const e=arguments[0];if(t(e)&&Z.includes(e)&&Ce[e]){const n=u(Array.from(arguments));if("init"===e){const e=!(i=Ce).vdsConfig&&!i.gioSDKInitialized||(_("SDK重复初始化,请检查是否重复加载SDK或接入其他平台SDK导致冲突!","warn"),!1),r=(e=>!!g(e)||(_('SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "你的应用 AppId", options); 进行初始化!',"error"),!1))(n),o=(e=>{const t=e[0];let i=l(e);return J(t)?(s(i)&&i||(i={}),{projectId:t,userOptions:i}):(_("SDK初始化失败,accountId 参数不合法!","error"),!1)})(n),a=(e=>{const i=e[1];let n=e[2];const s=l(e);return i&&t(i)?J(n)?{dataSourceId:i,appId:n,options:s}:(_("SDK初始化失败,appId 参数不合法!","error"),!1):(_("SDK初始化失败,dataSourceId 参数不合法!","error"),!1)})(n);if(e&&r&&o&&a){const{projectId:e}=o,{dataSourceId:t,appId:i,options:n}=a;return Ce.init(Object.assign(Object.assign({},n),{projectId:e,dataSourceId:t,appId:i}))}}else if("registerPlugins"===e)Ce.registerPlugins(n[0]);else{if(Ce.gioSDKInitialized&&Ce.vdsConfig)return Ce[e](...n);_("SDK未初始化!","error")}}else ee.includes(e)?_(`方法 ${c(e)} 已被弃用!`,"warn"):_(`不存在名为 ${c(e)} 的方法调用!`,"error");var i};K().gdp=_e,K().gioSDKVersion=Ce.sdkVersion;const Ee=k((()=>{var e;return null!==(e=Ce.dataStore.eventHooks.growingApp)&&void 0!==e?e:App})),ke=k((()=>{var e;return null!==(e=Ce.dataStore.eventHooks.growingPage)&&void 0!==e?e:Page})),Ae=k((()=>{var e;return null!==(e=Ce.dataStore.eventHooks.growingComponent)&&void 0!==e?e:Component})),Ne=k((()=>{var e;return null!==(e=Ce.dataStore.eventHooks.growingBehavior)&&void 0!==e?e:Behavior}));export default _e;export{Ee as GioApp,Ne as GioBehavior,Ae as GioComponent,ke as GioPage};
1
+ const t=/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/,e=t=>["undefined","null"].includes(P(t)),i=t=>"string"===P(t),n=t=>"number"===P(t),s=t=>"boolean"===P(t),r=t=>"[object Object]"==={}.toString.call(t)&&!e(t),o=t=>["function","asyncfunction"].includes(P(t)),a=t=>Array.isArray(t)&&"array"===P(t),g=t=>{try{return Array.from(t)[0]}catch(t){return}},l=t=>{try{const e=Array.from(t);return e[e.length-1]}catch(t){return}},u=(t,e=1)=>a(t)&&n(e)?t.slice(e>0?e:1,t.length):t,c=(t,e=!1)=>{if(a(t)){let i=0;const n=[];for(const s of t)s&&!k(s)&&(n[i++]=s),e&&0===s&&(n[i++]=s);return n}return t},h=(t,e)=>{if(a(t)){const i=t.findIndex(e);return 0>i?void 0:t[i]}},d=t=>e(t)?"":""+t,p=(t,e)=>"string"===P(t)?t.split(e):t,v=t=>{if(i(t)){const e=p(t,"");return`${g(e).toLowerCase()}${u(e).join("")}`}return t},m=(t,e)=>(i(t)||(t=d(t)),t.slice(0,e.length)===e),I={}.hasOwnProperty,f=(t,i)=>!e(t)&&I.call(t,i),y=t=>r(t)?Object.keys(t):[],S=(t,e)=>{y(t).forEach((i=>e(t[i],i)))},O=(t,e)=>{const i=y(t);return!(!r(t)||!r(e)||i.length!==y(e).length||i.map(((i,n)=>r(t[i])?O(t[i],e[i]):t[i]===e[i])).includes(!1))},w=(t,e,i)=>{let n=t;return r(t)?(e.split(".").forEach((t=>{n=n?n[t]:i})),n):i},b=(t,e)=>{if(!r(t))return!1;try{if("string"===P(e))return delete t[e];if("array"===P(e))return e.map((e=>delete t[e]));"object"===P(e)&&e.constructor===RegExp&&y(t).forEach((i=>{e.test(i)&&b(t,i)}))}catch(t){return!1}},_=(t,e=250,i,n)=>{let s,r=0;return"boolean"!==P(i)&&(n=t,t=i,i=void 0),function(...o){let a=this,g=Date.now()-r;function l(){r=Date.now(),t.apply(a,o)}n&&!s&&l(),s&&clearTimeout(s),void 0===n&&g>e?l():!0!==i&&(s=setTimeout(n?function(){s=void 0}:l,void 0===n?e-g:e))}},k=t=>a(t)?0===t.length:r(t)?0===y(t).length:!t,P=t=>({}.toString.call(t).slice(8,-1).toLowerCase());var T=Object.freeze({__proto__:null,isNil:e,isString:i,isNaN:t=>"NaN"===d(Number(t)),isNumber:n,isBoolean:s,isObject:r,isRegExp:t=>"[object RegExp]"==={}.toString.call(t),isFunction:o,isArray:a,isDate:t=>"date"===P(t),fixed:(t,e)=>n(t)?Number(t.toFixed(n(e)?e:2)):i(t)&&"NaN"!==d(Number(t))?Number(Number(t).toFixed(n(e)?e:2)):t,head:g,last:l,drop:u,dropWhile:(t,e)=>a(t)?t.filter((t=>!e(t))):t,compact:c,find:h,isEqualArray:(t,e)=>!(!a(t)||!a(e)||t.length!==e.length)&&t.every(((t,i)=>t===e[i])),toString:d,split:p,lowerFirst:v,upperFirst:t=>{if(i(t)){const e=p(t,"");return`${g(e).toUpperCase()}${u(e).join("")}`}return t},startsWith:m,endsWith:(t,e)=>{const{length:i}=t;let n=i;n>i&&(n=i);const s=n;return n-=e.length,n>=0&&t.slice(n,s)===e},hasOwnProperty:I,has:f,keys:y,forEach:S,isEqual:O,get:w,unset:b,throttle:_,isEmpty:k,typeOf:P,formatDate:t=>{function e(t){return 10>t?"0"+t:t}return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+" "+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())+"."+e(t.getMilliseconds())}});const E=(t,e)=>{console.log("%c[GrowingIO]:"+t,{info:"color: #3B82F6;",error:"color: #EF4444",warn:"color: #F59E0B",success:"color: #10B981"}[e]||"")},C=(t,e=!0,i="参数不合法")=>E(`${e?"调用":"设置"} ${t} 失败,${i}!`,"warn"),A=t=>{try{return t()}catch(t){return}},q=(t,e)=>{if(o(t))try{t(e)}catch(t){E("回调执行失败!"+t,"error")}},x=t=>i(t)?t.trim().substring(0,100):t,j=(e,n)=>i(e)&&!k(e)&&e.match(t)?n():(E("事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!","error"),!1),N=t=>(e(t)||y(t).forEach((e=>{o(t[e])?t[e]=A((()=>t[e]())):r(t[e])?b(t,e):a(t[e])||(t[e]=d(t[e]))})),t),U=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})),K=t=>t.pixelRatio?Math.round(t.screenHeight*t.pixelRatio):t.screenHeight,D=t=>t.pixelRatio?Math.round(t.screenWidth*t.pixelRatio):t.screenWidth,H=(t,e)=>{if(t){const i=t.toLowerCase();return-1!==i.indexOf("android")?e+"-Android":-1!==i.indexOf("ios")?e+"-iOS":t}},$=t=>{if(i(t)){const e=t.indexOf("?");return-1!==e?[t.substring(0,e),t.substring(e+1)]:[t,""]}return["",""]},L=t=>i(t)?t.startsWith("/")?t:"/"+t:"",R=t=>A((()=>{switch(t){case"wx":return wx;case"my":case"tb":return my;case"swan":return swan;case"tt":return tt;case"qq":return qq;case"ks":return ks;case"jd":return jd;default:{let t;return t||(t=A((()=>swan))),t||(t=A((()=>my))),t||(t=A((()=>tt))),t||(t=A((()=>qq))),t||(t=A((()=>ks))),t||(t=A((()=>jd))),t||(t=A((()=>wx))),t}}})),F=t=>A((()=>{switch(t){case"wx":return __wxConfig;case"swan":return appConfig;case"tt":return __ttConfig;case"qq":return __qqConfig;case"ks":return __ksConfig;case"jd":return __jdConfig;default:return}})),G=()=>{let t;return!t&&A((()=>swan))&&(t="swan"),!t&&A((()=>tt))&&(t="tt"),!t&&A((()=>qq))&&(t="qq"),!t&&A((()=>my.tb))&&(t="tb"),!t&&A((()=>my))&&(t="my"),!t&&A((()=>ks))&&(t="ks"),!t&&A((()=>jd))&&(t="jd"),!t&&A((()=>wx))&&(t="wx"),t||h(y(global),(t=>d(t).toLowerCase().includes("quickapp")))&&(t="quickapp"),t},V=()=>{var t;return null!==(t=A((()=>$global)))&&void 0!==t?t:global},B=t=>{const i={};return r(t)&&(b(t,"&&sendTo"),S(t,((t,n)=>{const s=d(n).slice(0,100);r(t)?i[s]=B(t):a(t)?(i[s]=c(t.slice(0,100),!0),i[s]=i[s].join("||").slice(0,1e3)):i[s]=e(t)?"":d(t).slice(0,1e3)}))),i},M=(t,e)=>{const i=()=>e.map((e=>t.getStorageSync(e)));try{return t.minip.canIUse("batchGetStorageSync")?t.minip.batchGetStorageSync(e):i()}catch(t){return i()}},Q=(t,e)=>{const i=()=>e.map((({key:e,value:i})=>t.setStorageSync(e,i)));try{return t.minip.canIUse("batchSetStorageSync")?t.minip.batchSetStorageSync(e):i()}catch(t){return i()}},z=t=>y(t||{}).map((i=>i?`${i}=${e(t[i])?"":t[i]}`:"")).join("&"),W=t=>{(m(t,"?")||m(t,"&"))&&(t=t.slice(1,t.length));const e={};return t.split("&").forEach((t=>{const i=t.split("=");i[0]&&(e[i[0]]=i[1])})),e};var Y=Object.freeze({__proto__:null,consoleText:E,callError:C,niceTry:A,niceCallback:q,limitString:x,eventNameValidate:j,getDynamicAttributes:N,guid:U,getScreenHeight:K,getScreenWidth:D,getOS:H,compareVersion:(t="",e="")=>{const i=t=>t.replace(/\s+/g,""),n=t=>t.replace(/[vV]/g,""),s=i(n(t)),r=i(n(e)),o=s.split("."),a=r.split(".");for(let t=0;3>t;t++){let e=Number(o[t]),i=Number(a[t]);if(e>i)return 1;if(i>e)return-1;if(!isNaN(e)&&isNaN(i))return 1;if(isNaN(e)&&!isNaN(i))return-1}return 0},getVueVersion:t=>{if(t){const e=Number(g(p(t.version,".")));return Number.isNaN(e)?0:e}return 0},splitPath:$,normalPath:L,isTaro3:t=>{const{Current:e,createComponent:i}=t;return!(!t||!e||i)},getPlainMinip:R,getPlainConfig:F,getPlainPlatform:G,getSubKeys:t=>y(t).filter((t=>t.indexOf("__sub")>-1&&t.indexOf("gio__")>-1)).sort(),getAppInst:()=>{let t=A((()=>getApp({allowDefault:!0})));return t||(t=V()),t},getGlobal:V,limitObject:B,batchGetStorageSync:M,batchSetStorageSync:Q,qsStringify:z,qsParse:W,hashCode:(t,e=!1)=>{let i=0;if(k(t)||"boolean"==typeof t)return i;let n=0;for(;n<t.length;)i=(i<<5)-i+t.charCodeAt(n),i|=0,n++;return e?Math.abs(i):i}});const J=t=>i(t)&&t.length>0||n(t)&&t>0,Z={autotrack:{type:"boolean",default:!0},compress:{type:"boolean",default:!0},dataCollect:{type:"boolean",default:!0},debug:{type:"boolean",default:!1},idMapping:{type:"boolean",default:!1},enableIdMapping:{type:"boolean",default:!1},extraParams:{type:"array",default:[]},followShare:{type:"boolean",default:!0},forceLogin:{type:"boolean",default:!1},ignoreFields:{type:"array",default:[]},pluginMode:{type:"boolean",default:!1},originalSource:{type:"boolean",default:!0},keepAlive:{type:"number",default:3e5},performance:{type:"object",default:{monitor:!0,exception:!0}},serverUrl:{type:"string",default:"https://napi.growingio.com"},requestTimeout:{type:"number",default:5e3},taro:{type:["object","module"],default:!1},taroVue:{type:["object","function"],default:!1},tbConfig:{type:"object",default:{cloud:void 0,cloudFuncSend:!1,cloudFuncName:"httpTunnel",cloudFuncHandler:"main",cloudAppId:void 0,path:void 0}},trackPage:{type:"boolean",default:!0},uniVue:{type:["object","function"],default:!1},uploadInterval:{type:"number",default:1e3},version:{type:"string",default:"1.0.0"}},X=["clearGeneralProps","clearTrackTimer","clearUserId","getABTest","getGioInfo","getOption","identify","removeTimer","sendPage","sendVisit","setGeneralProps","setLocation","setOption","setPageAttributes","setUserAttributes","setUserId","track","trackTimerEnd","trackTimerPause","trackTimerResume","trackTimerStart"],et=["init","registerPlugins","getPlugins","getDeviceId","updateImpression",...X],it={autotrack:"无埋点",dataCollect:"数据采集",debug:"调试模式",serverUrl:"数据上报服务地址"},nt=["enableDebug","setAutotrack","setDataCollect","setTrackerHost","setTrackerScheme","setConfig","collectImp","setPlatformProfile","getLocation"],st=["deviceBrand","deviceModel","deviceType","networkState","screenHeight","screenWidth","operatingSystem"],rt=[...st,"appChannel","language","platformVersion"],ot={gsid:"_growing_gsid_",originalSource:"_gdp_original_source_",userId:"_growing_userId_",userKey:"_growing_userKey_",gioId:"_growing_gioId_",plugin_gsid:"_growing_plugin_gsid_",plugin_originalSource:"_gdp_plugin_original_source_",plugin_userId:"_growing_plugin_userId_",plugin_userKey:"_growing_plugin_userKey_",plugin_gioId:"_growing_plugin_gioId_"};var at="MINIP_LIFECYCLE",gt="ON_COMMIT_REQUEST",lt="ON_COMPOSE_AFTER",ut="ON_COMPOSE_BEFORE",ct="ON_ERROR",ht="ON_INSTALL",dt="ON_SEND_AFTER",pt="ON_SEND_BEFORE",vt="OPTION_CHANGE",mt="OPTION_INITIALIZED",It="SDK_INITIALIZED";class ft{constructor(t){this.growingIO=t,this.main=(t,e)=>{var i,n,s,r,o,a;t||(t=this.growingIO.trackingId);const{sdkVersion:g,platformConfig:l,minipInstance:u,userStore:c,dataStore:h,dataStore:{scene:d,eventHooks:p,lastVisitEvent:v,lastPageEvent:m}}=this.growingIO,{version:I,dataSourceId:f,appId:y,idMapping:S,ignoreFields:O}=h.getTrackerVds(t),w=h.locationData[t],{systemInfo:_={},network:P={}}=u,{brand:T,model:E,platform:C,language:A}=_,q={appChannel:"scn:"+(d||"NA"),appVersion:I,dataSourceId:f,deviceBrand:T,deviceId:c.getUid(),deviceModel:E,deviceType:H(C,l.name),domain:y,language:A,latitude:null==w?void 0:w.latitude,longitude:null==w?void 0:w.longitude,networkState:(null==P?void 0:P.networkType)||(null==P?void 0:P.type)||(null==P?void 0:P.subtype),operatingSystem:H(C,l.name),path:(null===(i=p.currentPage)||void 0===i?void 0:i.path)?null===(n=p.currentPage)||void 0===n?void 0:n.path:v.path,platform:l.platform,platformVersion:l.name+(_.version?" "+_.version:""),query:(null===(s=p.currentPage)||void 0===s?void 0:s.path)?null===(r=p.currentPage)||void 0===r?void 0:r.query:v.query,screenHeight:K(_),screenWidth:D(_),sdkVersion:g,sessionId:c.getSessionId(t),title:(null===(o=m[t])||void 0===o?void 0:o.title)||(null===(a=p.currentPage)||void 0===a?void 0:a.title)||u.getPageTitle(u.getCurrentPage()),timestamp:Date.now(),timezoneOffset:(new Date).getTimezoneOffset(),userId:c.getUserId(t)};return S&&(q.userKey=c.getUserKey(t)),k(O)||O.forEach((t=>{b(q,t)})),k(e)?Object.assign(Object.assign({},q),{trackingId:t}):Object.assign(Object.assign(Object.assign({},q),e),{trackingId:t})}}}function yt(t,e,i,n){return new(i||(i=Promise))((function(s,r){function o(t){try{g(n.next(t))}catch(t){r(t)}}function a(t){try{g(n.throw(t))}catch(t){r(t)}}function g(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}g((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class St{constructor(t){this.growingIO=t,this.main=(t,e)=>{var i,n;const s=Date.now(),{emitter:r,userStore:o,vdsConfig:a,platformConfig:g,uploader:l,dataStore:u,dataStore:{trackersExecute:c,shareOut:h,lastCloseTime:d,eventHooks:p,saveStorageInfo:v,setOriginalSource:m}}=this.growingIO;r.emit(at,{event:"App "+t,timestamp:s,params:null!==(i=e[0])&&void 0!==i?i:{}}),a.debug&&console.log("App:",t,s);const I=g.listeners.app;switch(r.emit(ut,{event:"App "+t,params:null!==(n=e[0])&&void 0!==n?n:{}}),t){case I.appCreate:case I.appShow:{const{path:t,query:i}=this.enterParamsParse(e[0]);!h&&a.originalSource&&c((e=>{m(e,{path:t,query:i})})),d?(Date.now()-d>a.keepAlive||u.lastScene&&u.scene!==u.lastScene)&&(c((t=>{o.setSessionId(t)})),p.currentPage.time=void 0,c((e=>{this.buildVisitEvent(e,{path:t,query:i})}))):(u.lastVisitEvent={path:t,query:i},c((e=>{this.buildVisitEvent(e,{path:t,query:i})})));break}case I.appClose:u.lastScene=u.scene,u.lastCloseTime=Date.now(),v(),o.saveUserInfo(),c((t=>{this.buildCloseEvent(t),a.forceLogin||l.initiateRequest(t,!0)}))}},this.enterParamsParse=t=>{const{gioPlatform:e,minipInstance:i,dataStore:n}=this.growingIO;let s="",o="";const a=(t,e={})=>{s=t,o=y(e).map((t=>`${t}=${e[t]}`)).join("&")};if("quickapp"!==e&&i.minip.canIUse("getEnterOptionsSync")){const{path:e,query:s,scene:g,referrerInfo:l}=i.minip.getEnterOptionsSync()||{},u=t.query||s;if(a(t.path||e,u),n.scene=t.scene||g,!k(l)&&r(null==l?void 0:l.extraData)){let t=[];S(l.extraData,((e,i)=>{!f(u,i)&&["string","number","boolean"].includes(P(e))&&t.push(`${i}=${e}`)}));const e=t.join("&");o=o&&e?`${o}&${e}`:o||e}}else{const{path:e,query:i}=t;a(e,i),this.parseScene(t)}return{path:s,query:o}},this.parseScene=t=>{var e;const{minipInstance:i,gioPlatform:n,dataStore:s}=this.growingIO;let r;if("quickapp"===n){const{extra:t,type:e}=i.getAppSource();r=(null==t?void 0:t.scene)||e}else k(t)||((null===(e=null==t?void 0:t.query)||void 0===e?void 0:e.wxShoppingListScene)?r=t.query.wxShoppingListScene:(null==t?void 0:t.scene)?r=t.scene:s.scene="NA");s.scene=r},this.buildVisitEvent=(t,i)=>{var n;const{dataStore:{getOriginalSource:s,eventContextBuilder:r,eventInterceptor:o,eventHooks:a},minipInstance:g,vdsConfig:l}=this.growingIO,u=s(t),c=(null==i?void 0:i.query)||"";let h=Object.assign({eventType:"VISIT"},r(t,{path:(null==i?void 0:i.path)||"",query:"string"===P(c)?c:z(c),title:(null===(n=a.currentPage)||void 0===n?void 0:n.title)||g.getPageTitle(g.getCurrentPage()),timestamp:a.currentPage.time?a.currentPage.time-1:+Date.now()}));l.originalSource&&!e(u)&&(h=Object.assign(Object.assign({},h),u)),o(h)},this.buildCloseEvent=t=>{const{dataStore:{eventContextBuilder:e,eventInterceptor:i}}=this.growingIO;i(Object.assign({eventType:"APP_CLOSED"},e(t)))}}}class Ot{constructor(t){this.growingIO=t,this.parsePage=(t,e)=>{var i;const n=t.route||t.uri||t.__route__||(null===(i=null==t?void 0:t.$page)||void 0===i?void 0:i.fullPath)||"";k(e)?this.query=void 0:this.query=this.getQuery(e),this.path!==n&&(this.time=Date.now()),this.path=n,this.title=this.settedTitle[this.path]||this.growingIO.minipInstance.getPageTitle(t||this.growingIO.minipInstance.getCurrentPage())},this.getQuery=t=>{const e=Object.assign({},t);return b(e,"wxShoppingListScene"),z(e)},this.getReferralPage=t=>{var e;const{minipInstance:i,dataStore:{lastPageEvent:n,scene:s}}=this.growingIO;return(null===(e=n[t])||void 0===e?void 0:e.path)||(s?`scn:${i.scnPrefix}${s}`:null)},this.updateShareResult=t=>{const[e,i]=this.buildShareQuery(t);return t.path=L(e+(i?"?"+i:"")),t.query=i,t},this.updateAppMessageResult=this.updateShareResult,this.updateTimelineResult=this.updateShareResult,this.updateAddFavoritesResult=t=>{const[e,i]=this.buildShareQuery(t);return t.path=L(e+(i?"?"+i:"")),t.query=i,t},this.query=void 0,this.settedTitle={},this.pageProps={}}buildShareQuery(t){var e,i,n;const s=$(null!==(e=t.path)&&void 0!==e?e:"");let r=this.path,o={},a=f(t,"path");return a&&(r=g(s),o=W(l(s))||{}),k(o)&&(o=W(null!==(i=t.query)&&void 0!==i?i:"")||{}),!a&&k(o)&&(o=W(null!==(n=this.query)&&void 0!==n?n:"")||{}),[r,z(o)]}}class wt{constructor(t){this.growingIO=t,this.main=(t,e,i)=>{var n,s;const r=Date.now(),{emitter:a,minipInstance:g,plugins:l,vdsConfig:u,platformConfig:c,dataStore:{getTrackerVds:h,trackersExecute:d,shareOut:p,eventHooks:v,toggleShareOut:m,buildAppMessageEvent:I,buildTimelineEvent:f,buildAddFavorites:y},inPlugin:S}=this.growingIO,{currentPage:O}=v;if(this.prevEvent[e]&&50>Date.now()-Number(this.prevEvent[e]))return;t||(t=g.getCurrentPage()),t.route||(t.route=g.getCurrentPath(t));const _=t.route||t.uri||t.__route__||(null===(n=null==t?void 0:t.$page)||void 0===n?void 0:n.fullPath)||"";a.emit(at,{event:"Page "+e,timestamp:r,params:{page:t,args:i[0]}}),u.debug&&console.log("Page:",_,"#",e,r),this.prevEvent[e]=Date.now();const k=c.listeners.page;switch(a.emit(ut,{page:t,event:"Page "+e,params:{page:t,args:i[0]}}),O.lastLifecycle=O.currentLifecycle,O.currentLifecycle=e,e){case k.pageLoad:this.argQuery[_]=w(t,"options")||w(t,"__displayReporter.query")||w(t,"$page.query")||w(t,"$wx.__displayReporter.query")||i[0]||{},b(this.argQuery[_],"$taroTimestamp"),O.parsePage(t,this.argQuery[_]);break;case k.pageShow:S?(O.parsePage(t,this.argQuery[_]),O.path||(O.path=`/插件${u.appId}}`,O.title=`/插件${u.appId}}`),d((t=>{const{trackPage:e}=h(t);e&&this.buildPageEvent(t)}))):p&&v.currentPage.time||(O.parsePage(t,this.argQuery[_]),v.currentPage.time=Date.now(),d((t=>{const{trackPage:e}=h(t);e&&this.buildPageEvent(t)}))),m(!1);break;case k.pageHide:case k.pageUnload:break;case k.shareApp:m(!0),d((t=>{const{followShare:e}=h(t);e&&I(t,i)}));break;case k.shareTime:d((t=>{const{followShare:e}=h(t);e&&f(t,i)}));break;case k.addFavorites:d((t=>{const{followShare:e}=h(t);e&&y(t,i)}));break;case k.tabTap:{const t=null===(s=null==l?void 0:l.gioEventAutoTracking)||void 0===s?void 0:s.buildTabClickEvent;u.autotrack&&t&&o(t)&&t(this.growingIO.trackingId,i[0]);break}}e===k.pageUnload&&d((t=>{O.pageProps[t]=void 0}))},this.buildPageEvent=(t,e)=>{const{dataStore:{eventContextBuilder:i,eventInterceptor:n,eventHooks:{currentPage:s}},minipInstance:r}=this.growingIO,o=Object.assign(Object.assign({eventType:"PAGE",referralPage:s.getReferralPage(t)},i(t)),{title:(null==s?void 0:s.title)||r.getPageTitle(r.getCurrentPage()),timestamp:s.time});!k(e)&&e.title&&(o.title=e.title);const a=A((()=>s.pageProps[t]));k(a)||(o.attributes=a,s.pageProps[t]=void 0),n(o)},this.prevEvent={},this.argQuery={}}}class bt{constructor(t){var e;this.growingIO=t,this.isNormalFc=(t,e)=>o(e)&&"constructor"!==t,this.objectTraverse=(t,e)=>{Object.getOwnPropertyNames(t).forEach((i=>e(i,t))),f(t,"methods")&&Object.getOwnPropertyNames(t.methods).forEach((i=>{t[i]||e(i,t.methods)})),f(t,"lifetimes")&&Object.getOwnPropertyNames(t.lifetimes).forEach((i=>{t[i]||e(i,t.lifetimes)})),f(t,"pageLifetimes")&&Object.getOwnPropertyNames(t.pageLifetimes).forEach((i=>{t[i]||e(i,t.pageLifetimes)}))},this.supLifeFcs=(t,e)=>{a(this[e+"Handlers"])&&this[e+"Handlers"].forEach((e=>{o(t[e])||["onShareAppMessage","onShareTimeline"].includes(e)||(t[e]=()=>{})}))},this.lifeFcEffects=(t,e,i)=>{const n=this;return["onShareTimeline","onAddToFavorites"].includes(t)?function(...s){let r=e.apply(this,s);"onShareTimeline"===t&&n.growingIO.vdsConfig.followShare&&(r=n.currentPage.updateTimelineResult(null!=r?r:{})),"onAddToFavorites"===t&&(r=n.currentPage.updateAddFavoritesResult(null!=r?r:{}));const o=[].slice.call(s);return r&&o.push(r),n[`def${i}Cbs`][t].apply(this,o),r}:function(...s){var r;return yt(this,void 0,void 0,(function*(){let o;try{if("onShareAppMessage"===t){if(o=null!==(r=yield e.apply(this,s))&&void 0!==r?r:{},"promise"===P(o.promise)){const t=function(){return yt(this,void 0,void 0,(function*(){let t=o;return new Promise((e=>{let i=setTimeout((()=>{e(Object.assign({},t)),clearTimeout(i),i=void 0}),3e3);o.promise.then((n=>{t=n,e(Object.assign({},t)),clearTimeout(i),i=void 0}))}))}))};o=Object.assign(Object.assign({},o),yield t()),b(o,"promise")}n.growingIO.vdsConfig.followShare&&(o=n.currentPage.updateAppMessageResult(null!=o?o:{}))}const a=[].slice.call(s);o&&a.push(o),n[`def${i}Cbs`][t].apply(this,a)}catch(t){E(t,"error")}return"onShareAppMessage"!==t&&(o=e.apply(this,s)),n.growingIO.emitter.emit(at,{event:`${i} ${t}End`,timestamp:Date.now(),params:{instance:this,arguments:Array.from(s)}}),o}))}},this.customFcEffects=(t,e)=>{const i=this;return function(...n){var s,r;let a;if(i.growingIO.vdsConfig.autotrack&&i.growingIO.plugins.gioEventAutoTracking)try{let e=n[0]||{};f(e,"type")&&((null==e?void 0:e.currentTarget)||(null==e?void 0:e.target))||(e=n[n.length-1]),((null==e?void 0:e.currentTarget)||(null==e?void 0:e.target))&&i.actionEventTypes.includes(e.type)&&(o(i.actionEffects)||(i.actionEffects=(null===(r=null===(s=i.growingIO.plugins)||void 0===s?void 0:s.gioEventAutoTracking)||void 0===r?void 0:r.main)||function(){}),null==i||i.actionEffects(e,t))}catch(t){E(t,"error")}return a=e.apply(this,n),a}},this.appApplyProxy=(t,e)=>this.appHandlers.includes(t)?this.lifeFcEffects(t,e,"App"):this.customFcEffects(t,e),this.pageApplyProxy=(t,e)=>this.pageHandlers.includes(t)?this.lifeFcEffects(t,e,"Page"):this.customFcEffects(t,e),this.appOverriding=t=>(this.setAppEffectCbs(),this.supLifeFcs(t,"app"),this.objectTraverse(t,((t,e)=>{this.isNormalFc(t,e[t])&&(e[t]=this.appApplyProxy(t,e[t]))})),t),this.pageOverriding=t=>(this.setPageEffectCbs(),this.supLifeFcs(t,"page"),this.objectTraverse(t,((t,e)=>{this.isNormalFc(t,e[t])&&(e[t]=this.pageApplyProxy(t,e[t]))})),t),this.componentOverriding=t=>(this.setPageEffectCbs(),t.methods||(t.methods={}),this.supLifeFcs(this.growingIO.inPlugin?t:t.methods,"page"),this.objectTraverse(this.growingIO.inPlugin?t:t.methods,((t,e)=>{this.isNormalFc(t,e[t])&&(e[t]=this.pageApplyProxy(t,e[t]))})),t),this.setAppEffectCbs=()=>{const t=this;this.appHandlers.forEach((e=>{this.defAppCbs[e]=function(...i){t.appEffects.main(e,i)}}))},this.setPageEffectCbs=()=>{const t=this;this.pageHandlers.forEach((e=>{this.defPageCbs[e]=function(...i){t.pageEffects.main(this,e,i)}}))},this.growingApp=t=>this.originalApp(this.appOverriding(t)),this.growingPage=t=>this.originalPage(this.pageOverriding(t)),this.growingComponent=t=>this.originalComponent(this.componentOverriding(t)),this.growingBehavior=t=>this.originalBehavior(this.componentOverriding(t)),this.nativeGrowing=(t=["App","Page","Component","Behavior"])=>{const e=this,{platformConfig:i}=this.growingIO,n=i.hooks;if(this.setAppEffectCbs(),this.setPageEffectCbs(),t.includes("App"))try{n.App&&!this.appHooked&&(this.originalApp=App||global.App||function(){},App=function(...t){return e.growingApp(t[0])},this.appHooked=!0)}catch(t){}if(t.includes("Page"))try{n.Page&&!this.pageHooked&&(this.originalPage=Page||global.Page||function(){},Page=function(...t){return e.growingPage(t[0])},this.pageHooked=!0)}catch(t){}if(t.includes("Component"))try{n.Component&&!this.componentHooked&&(this.originalComponent=Component||global.Component||function(){},Component=function(...t){return e.growingComponent(t[0])},this.componentHooked=!0)}catch(t){}if(t.includes("Behavior"))try{n.Behavior&&!this.behaviorHooked&&(this.originalBehavior=Behavior||global.Behavior||function(){},Behavior=function(...t){return e.growingBehavior(t[0])},this.behaviorHooked=!0)}catch(t){}},this.initEventHooks=()=>{const t=this,{platformConfig:e,gioPlatform:i}=this.growingIO;e.canHook?(this.nativeGrowing(),V().GioApp=A((()=>null!==App&&void 0!==App?App:window.GioApp)),V().GioPage=A((()=>null!==Page&&void 0!==Page?Page:window.GioPage)),V().GioComponent=A((()=>null!==Component&&void 0!==Component?Component:window.GioComponent)),V().GioBehavior=A((()=>Behavior))):"quickapp"===i&&(window.GioApp=function(...e){return t.appOverriding(e[0])},window.GioPage=function(...e){return t.pageOverriding(e[0])},window.GioComponent=function(...e){return t.pageOverriding(e[0])})};const i=null===(e=this.growingIO)||void 0===e?void 0:e.platformConfig;this.defAppCbs={},this.defPageCbs={},this.appHandlers=i.appHandlers,this.pageHandlers=i.pageHandlers,this.actionEventTypes=i.actionEventTypes,this.appEffects=new St(this.growingIO),this.pageEffects=new wt(this.growingIO),this.currentPage=new Ot(this.growingIO)}}class _t{constructor(t){var n,r;this.growingIO=t,this.ALLOW_SETTING_KEYS=y(Z),this.getStorageKey=(t,e)=>{const{inPlugin:i}=this.growingIO;return`${t===this.growingIO.trackingId?"":t}${ot[i?"plugin_"+e:e]}`},this.getGsid=t=>{let e=Number(this._gsid[t]);return Number.isNaN(e)||e>=1e9||1>e?(this.setGsid(t,1),1):e},this.setGsid=(t,e)=>{let i=Number(e);(Number.isNaN(i)||i>=1e9||1>i)&&(i=1),this._gsid[t]=i,10>this._gsid[t]-this._stid[t]||this.saveStorageInfo()},this.initStorageInfo=t=>{const{minipInstance:e}=this.growingIO,i=e.getStorageSync(this.getStorageKey(t,"gsid"));let n=Number(i);(Number.isNaN(n)||n>=1e9||1>n)&&(n=1),this._gsid[t]=n,this._stid[t]=n,n!==i&&e.setStorageSync(this.getStorageKey(t,"gsid"),n)},this.saveStorageInfo=()=>{const{minipInstance:t}=this.growingIO;this._stid=Object.assign({},this._gsid),Q(t,this.initializedTrackingIds.map((t=>({key:this.getStorageKey(t,"gsid"),value:this._gsid[t]}))))},this.setOriginalSource=(t,{path:i,query:n})=>{const{minipInstance:s}=this.growingIO;if(e(this.getOriginalSource(t))){const e={path:i,query:n,title:""};s.setStorageSync(this.getStorageKey(t,"originalSource"),JSON.stringify(e))}},this.getOriginalSource=t=>{const{minipInstance:e}=this.growingIO;return A((()=>JSON.parse(e.getStorageSync(this.getStorageKey(t,"originalSource")))))},this.getTrackerVds=t=>this.growingIO.trackingId===t?Object.assign({},this.growingIO.vdsConfig):void 0,this.initTrackerOptions=t=>{const e=this.initOptions(t);return e.trackingId=t.trackingId,this.growingIO.trackingId=t.trackingId,this.growingIO.vdsConfig=e,e},this.initTrackerHooker=t=>{var e,i;const{platformConfig:n,inPlugin:s,minipInstance:r,plugins:o}=this.growingIO,{uniVue:a,taro:g}=t;a||g||(n.canHook=!0),s&&!["tbp","jdp"].includes(r.platform)||this.eventHooks.initEventHooks(),a&&(null===(e=null==o?void 0:o.gioUniAppAdapter)||void 0===e||e.main()),g&&(null===(i=null==o?void 0:o.gioTaroAdapter)||void 0===i||i.main())},this.initOptions=t=>{var e,i,n,s,r,o;const{projectId:g,dataSourceId:l,appId:u,trackingId:c}=t,h={};return this.ALLOW_SETTING_KEYS.forEach((e=>{const i=Z[e].type;(a(i)?i.includes(P(t[e])):P(t[e])===Z[e].type)?"ignoreFields"===e?h.ignoreFields=t.ignoreFields.filter((t=>st.includes(t))):"extraParams"===e?h.extraParams=t.extraParams.filter((t=>rt.includes(t))):(h[e]=t[e],["dataCollect","autotrack"].includes(e)&&!h[e]&&E("已关闭"+it[e],"info")):h[e]=Z[e].default})),h.uploadInterval=Math.round(h.uploadInterval),(Number.isNaN(h.uploadInterval)||0>h.uploadInterval||h.uploadInterval>3e3)&&(h.uploadInterval=1e3),h.enableIdMapping&&!h.idMapping&&(h.idMapping=!0,h.idMapping||this.growingIO.userStore.setUserKey(c,"")),b(h,"enableIdMapping"),h.pluginMode&&(this.growingIO.inPlugin=!0),!isNaN(Number(h.requestTimeout))&&h.requestTimeout>0||(h.requestTimeout=5e3),Object.assign(Object.assign({},h),{projectId:g,dataSourceId:l,appId:u,trackingId:c,performance:{monitor:null===(i=null===(e=h.performance)||void 0===e?void 0:e.monitor)||void 0===i||i,exception:null===(s=null===(n=h.performance)||void 0===n?void 0:n.exception)||void 0===s||s,network:null!==(o=null===(r=h.performance)||void 0===r?void 0:r.network)&&void 0!==o&&o}})},this.setOption=(t,e,n)=>{var s;const{userStore:r,emitter:o}=this.growingIO,a=this.getTrackerVds(t),g=i(e)&&this.ALLOW_SETTING_KEYS.includes(e),l=g&&typeof n===(null===(s=Z[e])||void 0===s?void 0:s.type);if(g&&l){const i=Object.assign({},a);if(this.updateVdsConfig(t,Object.assign(Object.assign({},a),{[e]:n})),"dataCollect"===e&&i.dataCollect!==n&&n){r.setSessionId(t);const{path:e,query:i,settedTitle:n}=this.eventHooks.currentPage;this.eventHooks.currentPage.title=n[e]||this.growingIO.minipInstance.getPageTitle(this.growingIO.minipInstance.getCurrentPage()),this.sendVisit(t,{path:e,query:i}),this.eventHooks.currentPage.time=Date.now(),this.sendPage(t,{path:e,query:i})}return o.emit(vt,{optionName:e,optionValue:n}),!0}return C("setOption > "+e),!1},this.getOption=(t,e)=>{const i=this.getTrackerVds(t);return e&&f(this.growingIO.vdsConfig,e)?f(i,e)?i[e]:this.growingIO.vdsConfig[e]:k(e)?i:void C("getOption > "+e)},this.updateVdsConfig=(t,e)=>{t===this.growingIO.trackingId?(this.growingIO.vdsConfig=Object.assign(Object.assign({},this.growingIO.vdsConfig),e),V().vdsConfig=this.growingIO.vdsConfig):(this.growingIO.subInstance[t]=Object.assign(Object.assign({},this.growingIO.subInstance[t]),e),V().vdsConfig.subInstance[t]=this.growingIO.subInstance[t])},this.toggleShareOut=t=>{s(t)?this.shareOut=t:this.shareOut=!this.shareOut},this.sendVisit=(t,e)=>{this.eventHooks.appEffects.buildVisitEvent(t,null!=e?e:this.lastVisitEvent)},this.sendPage=(t,e)=>{this.eventHooks.pageEffects.buildPageEvent(t,e)},this.eventConverter=t=>{const{dataStore:e,uploader:i}=this.growingIO,{dataCollect:n}=this.getTrackerVds(t.trackingId);if(n){["LOGIN_USER_ATTRIBUTES","APP_CLOSED"].includes(t.eventType)||(t.eventSequenceId=e.getGsid(t.trackingId),e.setGsid(t.trackingId,t.eventSequenceId+1));const n={};S(t,((t,e)=>{var i;if("element"===e){const e=null!==(i=g(t))&&void 0!==i?i:{};S(e,((t,e)=>{k(t)&&0!==t||(n[e]=t)}))}else k(t)&&0!==t||(n[e]=t)})),this.growingIO.emitter.emit(lt,{composedEvent:n}),i.commitRequest(Object.assign(Object.assign({},n),{requestId:U()}))}},this.eventInterceptor=t=>{const{systemInfo:e,network:i}=this.growingIO.minipInstance;k(e)||k(i)?this.interceptEvents.push(t):k(this.interceptEvents)?this.eventConverter(t):([...this.interceptEvents,t].forEach((e=>{const i=Object.assign(Object.assign({},e),this.eventContextBuilder(t.trackingId,{path:e.path,query:e.query,timestamp:e.timestamp}));this.eventConverter(i)})),this.interceptEvents=[])},this.eventReleaseInspector=()=>{const{minipInstance:{systemInfo:t,network:e}}=this.growingIO;t&&e&&!k(this.interceptEvents)&&([...this.interceptEvents].forEach((t=>{const e=Object.assign(Object.assign({},t),this.eventContextBuilder(t.trackingId,{path:t.path,query:t.query,timestamp:t.timestamp}));this.eventConverter(e)})),this.interceptEvents=[])},this.buildAppMessageEvent=(t,e)=>{var i;const n=e[0];let s;2>e.length?1===e.length&&(s=n):s=e[1];const{dataStore:{eventContextBuilder:r,eventInterceptor:o}}=this.growingIO,a=((null==s?void 0:s.path)||"").split("?");o(Object.assign({eventType:"CUSTOM",eventName:"$mp_on_share",attributes:Object.assign({$from:n.from,$target:null===(i=null==n?void 0:n.target)||void 0===i?void 0:i.id,$share_title:null==s?void 0:s.title,$share_path:g(a),$share_query:a[1]},null==s?void 0:s.attributes)},r(t)))},this.buildTimelineEvent=(t,e)=>{var i;const n=e[0];let s;2>e.length?1===e.length&&(s=n):s=e[1];const{dataStore:{eventContextBuilder:r,eventInterceptor:o}}=this.growingIO,a=((null==s?void 0:s.path)||"").split("?");o(Object.assign({eventType:"CUSTOM",eventName:"$mp_share_timeline",attributes:Object.assign({$target:null===(i=null==n?void 0:n.target)||void 0===i?void 0:i.id,$share_title:null==s?void 0:s.title,$share_path:g(a),$share_query:a[1]},null==s?void 0:s.attributes)},r(t)))},this.buildAddFavorites=(t,e)=>{const i=e[0];let n;2>e.length?1===e.length&&(n=i):n=e[1];const{dataStore:{eventContextBuilder:s,eventInterceptor:r}}=this.growingIO,o=((null==n?void 0:n.path)||"").split("?");r(Object.assign({eventType:"CUSTOM",eventName:"$mp_add_favorites",attributes:{$share_title:null==n?void 0:n.title,$share_path:g(o),$share_query:o[1]}},s(t)))},this.trackersExecute=t=>{this.initializedTrackingIds.forEach((e=>{"function"===P(t)&&t(e)}))},this.initializedTrackingIds=[],this.eventContextBuilder=new ft(this.growingIO).main,this.eventHooks=new bt(this.growingIO),this.shareOut=!1,this._gsid={},this._stid={},this.lastVisitEvent={},this.lastPageEvent={},this.locationData={},this.generalProps={},this.trackTimers={},this.interceptEvents=[];const{emitter:l,minipInstance:u}=this.growingIO;l.on(It,(({trackingId:t})=>{this.initializedTrackingIds.push(t),this.initStorageInfo(t)})),l.on(gt,(({eventData:t,trackingId:e})=>{"VISIT"===t.eventType&&(this.lastVisitEvent=t),"PAGE"===t.eventType&&(this.lastPageEvent[e]=t)})),o(null===(n=u.minip)||void 0===n?void 0:n.onAppHide)&&u.minip.onAppHide((()=>{this.trackersExecute((t=>{const e=this.trackTimers[t];S(e,(t=>{t.start&&(t.leng=t.leng+(+Date.now()-t.start))}))}))})),o(null===(r=u.minip)||void 0===r?void 0:r.onAppShow)&&u.minip.onAppShow((()=>{this.trackersExecute((t=>{const e=this.trackTimers[t];S(e,(t=>{t.start&&(t.start=+Date.now())}))}))})),l.on(vt,(({optionName:t,optionValue:e})=>{"dataCollect"===t&&!1===e&&this.trackersExecute((t=>{this.growingIO.clearTrackTimer(t)}))}))}get scene(){return this._scene}set scene(t){const e=this._scene;this._scene=t,e!==this._scene&&this.growingIO.emitter.emit("SCENE_UPDATE",{newScene:t,oldScene:e})}}const kt={scnPrefix:"",appHandlers:["onLaunch","onShow","onHide","onError","onPageNotFound","onUnhandledRejection","onThemeChange"],pageHandlers:["onLoad","onShow","onReady","onHide","onShareAppMessage","onTabItemTap","onUnload","onPullDownRefresh","onReachBottom","onResize"],actionEventTypes:["onclick","tap","onTap","longpress","longTap","blur","change","onChange","submit","confirm","getuserinfo","getphonenumber","contact","mouseup"],canHook:!0,hooks:{App:!0,Page:!0,Component:!0,Behavior:!0},listeners:{app:{appLaunch:"onLaunch",appShow:"onShow",appClose:"onHide"},page:{pageLoad:"onLoad",pageShow:"onShow",pageReady:"onReady",pageHide:"onHide",pageUnload:"onUnload",tabTap:"onTabItemTap",shareApp:"onShareAppMessage"},actions:{click:["onclick","tap","longpress","longTap","getuserinfo","getphonenumber","contact","mouseup"],change:["blur","change","confirm"],submit:["submit"]}}},Pt=Object.assign(Object.assign({},kt),{listeners:Object.assign({},kt.listeners),name:"Weixin",platform:"MinP"});Pt.pageHandlers=[...kt.pageHandlers,"onShareTimeline","onAddToFavorites"],Pt.listeners.page=Object.assign(Object.assign({},kt.listeners.page),{shareTime:"onShareTimeline",addFavorites:"onAddToFavorites"});class Tt{constructor(t){this.growingIO=t,this.minip=R("wx"),this.hookSetTitle=()=>{var t;const e=null===(t=this.minip)||void 0===t?void 0:t.setNavigationBarTitle,i=this;e&&Object.defineProperty(this.minip,"setNavigationBarTitle",{writable:!0,enumerable:!0,configurable:!0,value:function(){if(i.growingIO.gioSDKInitialized){const t=i.getCurrentPath(),{title:e}=arguments[0]||{};i.growingIO.dataStore.eventHooks.currentPage.settedTitle[t]=e}return e.apply(this,arguments)}})},this.navigateTo=t=>{var e;return null===(e=this.minip)||void 0===e?void 0:e.navigateTo(t)},this.switchTab=t=>{var e;null===(e=this.minip)||void 0===e||e.switchTab(t)},this.navigateToMiniProgram=t=>{var e;return null===(e=this.minip)||void 0===e?void 0:e.navigateToMiniProgram(t)},this.getImageInfo=({src:t,success:e,fail:i,complete:n})=>{var s;return null===(s=this.minip)||void 0===s?void 0:s.getImageInfo({src:t,success:e,fail:i,complete:n})},this.initImpression=t=>{var e,i;null===(i=null===(e=this.growingIO.plugins)||void 0===e?void 0:e.gioImpressionTracking)||void 0===i||i.main(t,"observeAll")},this.getCurrentPage=()=>A((()=>l(getCurrentPages())))||{},this.getCurrentPath=()=>{const t=this.getCurrentPage();return(null==t?void 0:t.route)||(null==t?void 0:t.uri)||(null==t?void 0:t.__route__)||""},this.getPageTitle=t=>{var e,n;let s="";const r=F(G());try{const o=(null==t?void 0:t.data)||t.$data||{};if(s=i(null==o?void 0:o.gioPageTitle)?null==o?void 0:o.gioPageTitle:"",0===s.length){const e=r.page[t.route]||r.page[t.route+".html"];s=e?e.window.navigationBarTitleText:r.global.window.navigationBarTitleText}if(0===s.length){const i=null===(n=null===(e=null==r?void 0:r.tabBar)||void 0===e?void 0:e.list)||void 0===n?void 0:n.find((e=>e.pagePath===t.route||e.pagePath===t.route+".html"));s=(null==i?void 0:i.text)||""}}catch(t){return""}return x(s)},this.getStorageSync=t=>{var e;let i=null===(e=this.minip)||void 0===e?void 0:e.getStorageSync(t);return r(i)&&i.expiredAt?i.expiredAt<Date.now()?"":i.value:i},this.getStorage=t=>new Promise((e=>{var i;null===(i=this.minip)||void 0===i||i.getStorage({key:t,success:({data:t})=>e(t),fail:()=>e("")})})),this.setStorageSync=(t,e,i)=>{var n;i&&(e={value:e,expiredAt:i}),null===(n=this.minip)||void 0===n||n.setStorageSync(t,e)},this.setStorage=(t,e)=>{var i;null===(i=this.minip)||void 0===i||i.setStorage({key:t,data:e})},this.removeStorageSync=t=>{var e;null===(e=this.minip)||void 0===e||e.removeStorageSync(t)},this.removeStorage=t=>{var e;null===(e=this.minip)||void 0===e||e.removeStorage(t)},this.getNetworkType=()=>{const t=this;return new Promise((e=>{var i;null===(i=this.minip)||void 0===i||i.getNetworkType({success:i=>{t.network=i,e(i)},fail:()=>e(null)})}))},this.request=({url:t,data:e,header:i,timeout:n,method:s,success:r,fail:a,complete:g})=>{var l;const u=null===(l=this.minip)||void 0===l?void 0:l.request({url:t,data:e,header:i,headers:i,timeout:n,method:s,success:r,fail:a,complete:g});let c=setTimeout((()=>{(null==u?void 0:u.abort)&&o(null==u?void 0:u.abort)&&(null==u||u.abort()),clearTimeout(c),c=null}),(n||1e4)+10);return u},this.getSystemInfo=()=>{const t=this;return new Promise((e=>{var i;null===(i=this.minip)||void 0===i||i.getSystemInfo({success:i=>{t.systemInfo=i,e(i)},fail:()=>e(null)})}))},this.getSetting=()=>new Promise((t=>{var e;null===(e=this.minip)||void 0===e||e.getSetting({success:t,fail:t})}));const{platformConfig:{platform:e,scnPrefix:n}}=this.growingIO;this.platform=e,this.scnPrefix=n,this.growingIO.emitter.on(mt,(()=>{this.getNetworkType().then((()=>{var t;return null===(t=this.growingIO.dataStore)||void 0===t?void 0:t.eventReleaseInspector()})),this.getSystemInfo().then((()=>{var t;return null===(t=this.growingIO.dataStore)||void 0===t?void 0:t.eventReleaseInspector()}))}))}}class Et extends Tt{constructor(t){super(t),this.growingIO=t,this.hookSetTitle()}}const Ct=["gioPerformance"];class At{constructor(t){var e,i,n,s,r,a;this.growingIO=t,this.innerPluginInit=()=>{var t;Ct.forEach((t=>{var e;return b(null===(e=this.pluginsContext)||void 0===e?void 0:e.plugins,t)})),y(null===(t=this.pluginsContext)||void 0===t?void 0:t.plugins).forEach((t=>{var e,i;const{name:n,method:s}=null!==(i=null===(e=this.pluginsContext)||void 0===e?void 0:e.plugins[t])&&void 0!==i?i:{};h(this.pluginItems,(t=>t.name===n))||this.pluginItems.push({name:v(n||t),method:s||(t=>{})})})),k(this.pluginItems)||this.installAll()},this.install=(t,e,i)=>{var n,s;const{emitter:r}=this.growingIO,o=e||h(this.pluginItems,(e=>e.name===t));if((null===(n=this.growingIO)||void 0===n?void 0:n.plugins)[t])return E(`重复加载插件 ${t} 或插件重名,已跳过加载!`,"warn"),!1;if(!o)return E(`插件加载失败!不存在名为 ${t} 的插件!`,"error"),!1;try{return(null===(s=this.growingIO)||void 0===s?void 0:s.plugins)[t]=new o.method(this.growingIO,i),e&&(r.emit(ht,t),E("加载插件 "+t,"info")),!0}catch(i){return this.lifeError(e,i),E(`插件【${t}】加载异常 ${i}`,"error"),!1}},this.installAll=t=>{(t||this.pluginItems).forEach((e=>{this.install(e.name,t?e:void 0,t?null==e?void 0:e.options:void 0)&&!h(this.pluginItems,(t=>t.name===e.name))&&this.pluginItems.push({name:v(e.name),method:e.method?e.method:()=>{}})}))},this.uninstall=t=>{var e;b(this.pluginItems,t);const i=b(null===(e=this.growingIO)||void 0===e?void 0:e.plugins,t);return i||E(`卸载插件 ${t} 失败!`,"error"),i},this.uninstallAll=()=>{this.pluginItems.forEach((t=>this.uninstall(t.name)))},this.lifeError=(t,e)=>{this.growingIO.emitter.emit(ct,{plugin:t,error:e}),E(`插件执行错误 ${t.name} ${e}`,"error")},this.callLifeCycle=(t,e)=>{this.pluginItems.forEach((i=>{const n=this.growingIO.plugins[i.name]?this.growingIO.plugins[i.name][t]:void 0;if(n&&o(n))try{n(e)}catch(t){this.lifeError(i,t)}}))},this.pluginsContext={plugins:{}},this.pluginItems=[],null===(e=this.growingIO.emitter)||void 0===e||e.on(ht,(t=>this.callLifeCycle("onInstall",t))),null===(i=this.growingIO.emitter)||void 0===i||i.on(ct,(t=>this.callLifeCycle("onError",t))),null===(n=this.growingIO.emitter)||void 0===n||n.on(ut,(t=>this.callLifeCycle("onComposeBefore",t))),null===(s=this.growingIO.emitter)||void 0===s||s.on(lt,(t=>this.callLifeCycle("onComposeAfter",t))),null===(r=this.growingIO.emitter)||void 0===r||r.on(pt,(t=>this.callLifeCycle("onSendBefore",t))),null===(a=this.growingIO.emitter)||void 0===a||a.on(dt,(t=>this.callLifeCycle("onSendAfter",t)))}}var qt={},xt={}.hasOwnProperty;function jt(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(t){return null}}function Nt(t){try{return encodeURIComponent(t)}catch(t){return null}}qt.stringify=function(t,e){e=e||"";var i,n,s=[];for(n in"string"!=typeof e&&(e="?"),t)if(xt.call(t,n)){if((i=t[n])||null!=i&&!isNaN(i)||(i=""),n=Nt(n),i=Nt(i),null===n||null===i)continue;s.push(n+"="+i)}return s.length?e+s.join("&"):""},qt.parse=function(t){for(var e,i=/([^=?#&]+)=?([^&]*)/g,n={};e=i.exec(t);){var s=jt(e[1]),r=jt(e[2]);null===s||null===r||s in n||(n[s]=r)}return n};class Ut{constructor(t){this.growingIO=t,this.generateURL=t=>{const{serverUrl:e,projectId:i}=this.growingIO.dataStore.getTrackerVds(t);return m(e,"http")?`${e}/v3/projects/${i}/collect`:`https://${e}/v3/projects/${i}/collect`},this.getHoardingQueue=t=>{var e;return null!==(e=this.hoardingQueue[t])&&void 0!==e?e:[]},this.getRequestQueue=t=>{var e;return null!==(e=this.requestQueue[t])&&void 0!==e?e:[]},this.commitRequest=t=>{var i,n;const s=Object.assign({},t),{vdsConfig:r,emitter:o}=this.growingIO;o.emit(gt,{eventData:t,trackingId:t.trackingId}),r.forceLogin?(e(this.hoardingQueue[t.trackingId])&&(this.hoardingQueue[t.trackingId]=[]),null===(i=this.hoardingQueue[t.trackingId])||void 0===i||i.push(s)):(e(this.requestQueue[t.trackingId])&&(this.requestQueue[t.trackingId]=[]),null===(n=this.requestQueue[t.trackingId])||void 0===n||n.push(s),this.initiateRequest(t.trackingId))},this.initiateRequest=(t,e)=>{const{plugins:i,vdsConfig:n,minipInstance:s,dataStore:r}=this.growingIO,o=[...this.getHoardingQueue(t),...this.getRequestQueue(t)],a=t=>{var a,g;if(null===(a=null==n?void 0:n.tbConfig)||void 0===a?void 0:a.cloudFuncSend)null===(g=null==i?void 0:i.gioTaobaoAdapter)||void 0===g||g.singleInvoke(t);else if(e)this.batchInvoke(t);else{const{uploadInterval:e}=this.growingIO.dataStore.getTrackerVds(t);_(this.batchInvoke,e,!1,!1)(t)}o.some((t=>"VISIT"===t.eventType))&&s.removeStorageSync(r.getStorageKey(t,"originalSource"))};if(o.length>0)if(this.requestingNum<this.requestLimit)a(t);else{let e=setInterval((()=>{this.requestingNum<this.requestLimit&&(a(t),clearInterval(e),e=void 0)}),500)}},this.batchInvoke=t=>{const{vdsConfig:e,emitter:i}=this.growingIO,n=this.getHoardingQueue(t),s=this.getRequestQueue(t);let r=[...n,...s];r.length>50?(r=r.slice(0,50),n.length>50?this.hoardingQueue[t]=n.slice(50):(this.requestQueue[t]=s.slice(50-n.length),this.hoardingQueue[t]=[])):(this.hoardingQueue[t]=[],this.requestQueue[t]=[]);let o=r.filter((t=>(this.retryIds[t.requestId]||0)<=this.retryLimit));if(k(o))return;const a=o.map((t=>{const e=Object.assign({},t);return b(e,["requestId","trackingId"]),e}));e.debug&&console.log("[GrowingIO Debug]:",JSON.stringify(a,null,2)),i.emit(pt,{eventsQueue:o,requestData:a,trackingId:t})},this.sendEvent=(t,e)=>{var i;const n=g(t).trackingId,{minipInstance:s,dataStore:r,emitter:o,plugins:a}=this.growingIO,{compress:l,requestTimeout:u}=r.getTrackerVds(n);this.requestingNum+=1;const c={"content-type":"jdp"===s.platform?"application/json":"application/json;charset=UTF-8"};let h=[...e];const d=!!l&&(null===(i=null==a?void 0:a.gioCompress)||void 0===i?void 0:i.compressToUTF16);d&&(h=a.gioCompress.compressToUTF16(JSON.stringify(e)),c["X-Compress-Codec"]="1");const p=this.generateURL(n);s.request({url:`${p}?stm=${Date.now()}&compress=${d?"1":"0"}`,header:c,method:"POST",data:h,timeout:u,fail:e=>{[200,204].includes(e.code)||(t.forEach((t=>{this.requestFailFn(t)})),E("请求失败!"+JSON.stringify(e),"error"))},complete:t=>{this.requestingNum-=1,o.emit(dt,{result:t,requestData:e}),this.initiateRequest(n)}})},this.requestFailFn=t=>{if(this.retryIds[t.requestId]||(this.retryIds[t.requestId]=0),this.retryIds[t.requestId]+=1,!this.requestQueue[t.trackingId].some((e=>e.requestId===t.requestId))){let e=setTimeout((()=>{k(this.requestQueue[t.trackingId])?(this.requestQueue[t.trackingId].push(t),this.initiateRequest(t.trackingId)):this.requestQueue[t.trackingId].push(t),clearTimeout(e),e=null}),800)}},this.hoardingQueue={},this.requestQueue={},this.requestLimit=3,this.retryLimit=2,this.retryIds={},this.requestingNum=0;const{emitter:i,vdsConfig:n,plugins:s}=this.growingIO;i.on(pt,(({eventsQueue:t,requestData:e,trackingId:i})=>{var r,o;i===this.growingIO.trackingId&&((null===(r=null==n?void 0:n.tbConfig)||void 0===r?void 0:r.cloudAppId)?null===(o=null==s?void 0:s.gioTaobaoAdapter)||void 0===o||o.tbCloudAppInvoke(t,e):this.sendEvent(t,e))}))}}class Kt{constructor(t){this.growingIO=t,this._getUidKey=()=>this.growingIO.inPlugin?"_growing_plugin_uid_":"_growing_uid_",this.getUid=()=>{const{minipInstance:t}=this.growingIO;return this._uid||(this._uid=t.getStorageSync(this._getUidKey())),this._uid||(this._uid=U(),t.setStorage(this._getUidKey(),this._uid)),this._uid},this.setUid=t=>{const e=this._uid;this._uid=t,e!==this._uid&&(this.growingIO.minipInstance.setStorage(this._getUidKey(),this._uid),this.growingIO.emitter.emit("UID_UPDATE",{newUId:t,oldUId:e}))},this.getSessionId=t=>(this._sessionId[t]||this.setSessionId(t),this._sessionId[t]),this.setSessionId=(t,e)=>{const i=this._sessionId[t];e||(e=U()),this._sessionId[t]=e,i!==e&&this.growingIO.emitter.emit("SESSIONID_UPDATE",{newSessionId:e,oldSessionId:i})},this._getUserIdKey=t=>this.growingIO.dataStore.getStorageKey(t,"userId"),this.getUserId=t=>{const{minipInstance:e}=this.growingIO;return this._userId[t]||(this._userId[t]=e.getStorageSync(this._getUserIdKey(t))),this._userId[t]},this.setUserId=(t,i)=>{const n=this._userId[t];this._userId[t]=e(i)?"":i,n!==this._userId[t]&&(this.growingIO.minipInstance.setStorage(this._getUserIdKey(t),this._userId[t]),this.growingIO.emitter.emit("USERID_UPDATE",{newUserId:i,oldUserId:n})),i&&this.setGioId(t,i)},this._getUserKeyKey=t=>this.growingIO.dataStore.getStorageKey(t,"userKey"),this.getUserKey=t=>{const{minipInstance:e}=this.growingIO;return this._userKey[t]||(this._userKey[t]=e.getStorageSync(this._getUserKeyKey(t))),this._userKey[t]},this.setUserKey=(t,i)=>{const n=this._userKey[t];this._userKey[t]=e(i)?"":i,n!==this._userKey[t]&&(this.growingIO.minipInstance.setStorage(this._getUserKeyKey(t),this._userKey[t]),this.growingIO.emitter.emit("USERKEY_UPDATE",{newUserKey:i,oldUserKey:n}))},this._getGioIdKey=t=>this.growingIO.dataStore.getStorageKey(t,"gioId"),this.getGioId=t=>{const{minipInstance:e}=this.growingIO;return this._gioId[t]||(this._gioId[t]=e.getStorageSync(this._getGioIdKey(t))),this._gioId[t]},this.setGioId=(t,i)=>{const n=this._gioId[t];this._gioId[t]=e(i)?"":i,n!==this._gioId[t]&&(this.growingIO.minipInstance.setStorage(this._getGioIdKey(t),this._gioId[t]),this.growingIO.emitter.emit("GIOID_UPDATE",{newGioId:i,oldGioId:n}))},this.initUserInfo=t=>{var e;const{minipInstance:i}=this.growingIO,n=[this._getUidKey(),this._getUserIdKey(t),this._getUserKeyKey(t),this._getGioIdKey(t)],s=null!==(e=M(i,n))&&void 0!==e?e:[];["_uid","_userId","_userKey","_gioId"].forEach(((e,i)=>{"_uid"===e?this.getUid():this[e][t]=s[i]}))},this.saveUserInfo=()=>{const{minipInstance:t,dataStore:{trackersExecute:e}}=this.growingIO;e((e=>{Q(t,[{key:this._getUidKey(),value:this._uid},{key:this._getUserIdKey(e),value:this._userId[e]},{key:this._getUserKeyKey(e),value:this._userKey[e]},{key:this._getGioIdKey(e),value:this._gioId[e]}])}))},this._uid=void 0,this._sessionId={},this._userId={},this._userKey={},this._gioId={}}}const Dt=new class{constructor(){var t;this.init=t=>{var e;this.emitter.emit("ON_SDK_INITIALIZE_BEFORE",{options:t});try{if(E("Gio小程序SDK 初始化中...","info"),t.trackingId&&this.dataStore.initializedTrackingIds.includes(t.trackingId))throw Error(`已存在实例 ${t.trackingId},请勿重复初始化!`);if(this.trackingId&&!this.plugins.gioMultipleInstances)throw Error("您正在尝试初始化另一个实例,请集成多实例插件后重试!");const i=this.dataStore.initTrackerOptions(t);return null===(e=this.emitter)||void 0===e||e.emit(mt,i),this.gioSDKInitialized=!0,this.dataStore.initTrackerHooker(i),"quickapp"!==this.gioPlatform&&this.userStore.initUserInfo(t.trackingId),this.emitter.emit(It,i),this.trackingId&&this.trackingId!==t.trackingId||(V().__gio__=()=>this),E("Gio小程序SDK 初始化完成!","success"),this.inPlugin&&"tbp"!==this.minipInstance.platform&&this.dataStore.sendVisit(i.trackingId),this.vdsConfig.forceLogin&&E("forceLogin已开启,请调用 identify 方法设置 openId 以继续上报!","info"),!0}catch(t){return E(t,"error"),!1}},this.handlerDistribute=(t,e,i)=>{const{initializedTrackingIds:n,getTrackerVds:s}=this.dataStore;if(s(t)&&n.includes(t))return this[e](t,...i);E(`不存在实例:${t},请检查!`,"warn")},this.registerPlugins=t=>{this.plugins.pluginItems=[...this.plugins.pluginItems,...t],this.plugins.installAll(t)},this.getPlugins=()=>this.plugins.pluginItems,this.getDeviceId=()=>this.userStore.getUid(),this.getOption=(t,e)=>this.dataStore.getOption(t,e),this.setOption=(t,e,i)=>{var n;return y(it).includes(e)?typeof i===(null===(n=Z[e])||void 0===n?void 0:n.type)?(this.dataStore.setOption(t,e,i),E(`已修改${it[e]}: ${i}`,"info"),!0):(E(`参数格式不正确:${i},请检查后重试!`,"error"),!1):(E(`不存在可修改的配置项:${e},请检查后重试!`,"error"),!1)},this.setPageAttributes=(t,e)=>{const{currentPage:i}=this.dataStore.eventHooks;k(i.pageProps[t])&&(i.pageProps[t]={}),k(e)||(i.pageProps[t]=Object.assign(Object.assign({},i.pageProps[t]),B(e)))},this.sendPage=(t,e)=>{const{trackPage:i}=this.dataStore.getTrackerVds(t);i?E("仅在关闭trackPage时允许调用sendPage,请确认后修改初始化配置项!","error"):this.dataStore.sendPage(t,e)},this.identify=(t,e)=>{if(t===this.trackingId)if(this.vdsConfig.forceLogin){if(!J(e))return void C("identify");const t=d(e).slice(0,1e3);this.userStore.setUid(t),this.dataStore.setOption(this.trackingId,"forceLogin",!1),this.dataStore.trackersExecute((e=>{const i=this.uploader.getHoardingQueue(e);i.forEach(((e,n)=>i[n].deviceId=t)),this.uploader.initiateRequest(e,!0)}))}else C("identify",!1,"forceLogin未开启");else C("identify",!1,"子实例不允许调用identify")},this.setUserAttributes=(t,e)=>{if(!k(e)&&r(e)){const{eventContextBuilder:i,eventInterceptor:n,lastVisitEvent:s}=this.dataStore,r=Object.assign({eventType:"LOGIN_USER_ATTRIBUTES",attributes:B(e)},i(t));r.path||(r.path=s.path,r.query=s.query,r.title=s.title),n(r)}else C("setUserAttributes")},this.setUserId=(t,i,n)=>{if(J(i)){const s=this.userStore.getGioId(t);i=d(i).slice(0,1e3),n=d(n).slice(0,1e3),this.userStore.setUserId(t,i);const{idMapping:r}=this.dataStore.getTrackerVds(t);if(r&&this.userStore.setUserKey(t,e(n)?"":n),s&&s!==i){this.userStore.setSessionId(t);const{path:e,query:i,settedTitle:n}=this.dataStore.eventHooks.currentPage;this.dataStore.eventHooks.currentPage.title=n[e]||this.minipInstance.getPageTitle(this.minipInstance.getCurrentPage()),this.dataStore.sendVisit(t,{path:e,query:i})}}else C("setUserId")},this.clearUserId=t=>{this.userStore.setUserId(t,void 0),this.userStore.setUserKey(t,void 0)},this.setGeneralProps=(t,e)=>{var i;return k(e)?(C("setGeneralProps"),!1):(this.dataStore.generalProps[t]=Object.assign(Object.assign({},null!==(i=this.dataStore.generalProps[t])&&void 0!==i?i:{}),e),!0)},this.clearGeneralProps=(t,e)=>{try{k(this.dataStore.generalProps[t])||(a(e)&&!k(e)?e.forEach((e=>{b(this.dataStore.generalProps[t],e)})):this.dataStore.generalProps[t]={})}catch(t){return C("setGeneralProps"),!1}},this.track=(t,e,i)=>{j(e,(()=>{var n;const{eventContextBuilder:s,eventInterceptor:o,generalProps:a}=this.dataStore,g=Object.assign(Object.assign({},null!==(n=a[t])&&void 0!==n?n:{}),r(i)&&!k(i)?i:{}),l=Object.assign({eventType:"CUSTOM",eventName:e,attributes:B(N(g))},s(t));this.plugins.gioMultipleInstances&&i&&i["&&sendTo"]&&(l["&&sendTo"]=i["&&sendTo"]),o(l)}))},this.trackTimerStart=(t,e)=>{const{dataCollect:i}=this.dataStore.getTrackerVds(t);return i?j(e,(()=>{const i=U();return this.dataStore.trackTimers[t]||(this.dataStore.trackTimers[t]={}),this.dataStore.trackTimers[t][i]={eventName:e,leng:0,start:+Date.now()},i})):(E("指定实例未开启数据采集,请检查!","error"),!1)},this.trackTimerPause=(t,e)=>{const i=this.dataStore.trackTimers[t];if(e&&i&&i[e]){const t=i[e];return t.start&&(t.leng=t.leng+(+Date.now()-t.start)),t.start=0,!0}return!1},this.trackTimerResume=(t,e)=>{const i=this.dataStore.trackTimers[t];if(e&&i&&i[e]){const t=i[e];return 0===t.start&&(t.start=+Date.now()),!0}return!1},this.trackTimerEnd=(t,e,i)=>{const{dataCollect:n}=this.dataStore.getTrackerVds(t),s=this.dataStore.trackTimers[t];if(e&&s&&s[e]){if(n){const n=864e5,r=s[e];if(0!==r.start){const t=+Date.now()-r.start;r.leng=t>0?r.leng+t:0}const{eventContextBuilder:o,eventInterceptor:a}=this.dataStore,g=Object.assign({eventType:"CUSTOM",eventName:r.eventName,attributes:B(Object.assign(Object.assign({},i),{event_duration:r.leng>n?0:r.leng/1e3}))},o(t));return this.plugins.gioMultipleInstances&&i&&i["&&sendTo"]&&(g["&&sendTo"]=i["&&sendTo"]),a(g),!0}return E("指定实例未开启数据采集,计时器已移除,请检查!","error"),!1}return E("未查询到指定计时器,请检查!","error"),!1},this.removeTimer=(t,e)=>{const i=this.dataStore.trackTimers[t];return e&&i&&i[e]?(delete i[e],!0):(E("未查询到指定计时器,请检查!","error"),!1)},this.clearTrackTimer=t=>{this.dataStore.trackTimers[t]={}},this.setLocation=(t,e,i)=>{k(this.dataStore.locationData[t])&&(this.dataStore.locationData[t]={});const n=this.dataStore.locationData[t],s=t=>t>=-180&&180>=t;s(e)&&s(i)&&(n.latitude!==e||n.longitude!==i)&&(this.dataStore.locationData[t]={latitude:e,longitude:i})},this.updateImpression=()=>{E("updateImpression 错误! 请集成半自动埋点浏览插件后重试!","error")},this.getABTest=(t,e,i)=>{E("获取ABTest数据错误! 请集成ABTest插件后重试!","error"),q(i,{})},this.getGioInfo=t=>{const{getUid:e,getUserId:i,getUserKey:n,getSessionId:s}=this.userStore,{projectId:r,appId:o,dataSourceId:a,dataCollect:g,idMapping:l,extraParams:u,ignoreFields:c}=this.dataStore.getTrackerVds(t),h={gioappid:o,giocs1:i(t)||"",gioplatform:this.platformConfig.platform,gioprojectid:r,gios:s(t),giou:e()};return h.giodatacollect=g,h.giodatasourceid=a,l&&(h.giouserkey=n(t)),k(u)||u.forEach((t=>{c.includes(t)||(h["gio"+t]=this.dataStore.lastVisitEvent[t])})),qt.stringify(h)},this.utils=Object.assign(Object.assign(Object.assign({},T),Y),{qs:qt}),this.emitter={all:t=t||new Map,on:function(e,i){var n=t.get(e);n?n.push(i):t.set(e,[i])},off:function(e,i){var n=t.get(e);n&&(i?n.splice(n.indexOf(i)>>>0,1):t.set(e,[]))},emit:function(e,i){var n=t.get(e);n&&n.slice().map((function(t){t(i)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,i)}))}},this.gioPlatform="wx",this.gioFramework="native",this.sdkVersion="4.1.0";try{"quickapp"===this.gioPlatform||o(getApp)&&o(App)?this.inPlugin=!1:this.inPlugin=!0}catch(t){this.inPlugin=!0}this.inPlugin&&E("未检测到小程序实例,自动切换为插件模式!","info"),this.platformConfig=Pt,this.minipInstance=new Et(this),this.dataStore=new _t(this),this.userStore=new Kt(this),this.uploader=new Ut(this),this.plugins=new At(this),this.plugins.innerPluginInit()}},Ht=function(){var t;const e=arguments[0];let n="g0",s=e;if(e.indexOf(".")>-1&&(n=null!==(t=e.split(".")[0])&&void 0!==t?t:"g0",s=e.split(".")[1]),i(s)&&et.includes(s)&&Dt[s]){const t=u(Array.from(arguments));if("init"===s){const e=((t,e)=>{const i=d(e[0]),n=d(e[1]),s=(4===e.length?e[3]:e[2])||{};return i&&n?t.dataStore.initializedTrackingIds.some(((e,s)=>{const r=0===s?t.vdsConfig:t.subInstance[e];return r.projectId===i&&r.dataSourceId===n}))?(E("SDK初始化失败,重复初始化,请检查初始化参数!","error"),!1):{projectId:i,dataSourceId:n,appId:d(4===e.length?e[2]:""),userOptions:s}:(E('SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "您的小程序 AppId(可选)", options: { host: "您的数据上报地址host" }); 进行初始化!',"error"),!1)})(Dt,t);if(e){const{projectId:t,dataSourceId:i,appId:s,userOptions:r}=e;return Dt.init(Object.assign(Object.assign({},r),{projectId:t,dataSourceId:i,appId:s,trackingId:n}))}return!1}if("registerPlugins"===s)Dt.registerPlugins(t[0]);else{if(Dt.gioSDKInitialized&&Dt.vdsConfig)return X.includes(s)?A((()=>Dt.handlerDistribute(n,s,t))):A((()=>Dt[s](...t)));E("SDK未初始化!","error")}}else if(nt.includes(s))E(`方法 ${d(s)} 已被弃用,请移除!`,"warn");else{if("canIUse"===s)return et.includes(arguments[1])&&!!Dt[arguments[1]];E(`不存在名为 ${d(s)} 的方法调用!`,"error")}};V().gdp=Ht,V().gioSDKVersion=Dt.sdkVersion;const $t=A((()=>{var t;return null!==(t=Dt.dataStore.eventHooks.growingApp)&&void 0!==t?t:App})),Lt=A((()=>{var t;return null!==(t=Dt.dataStore.eventHooks.growingPage)&&void 0!==t?t:Page})),Rt=A((()=>{var t;return null!==(t=Dt.dataStore.eventHooks.growingComponent)&&void 0!==t?t:Component})),Ft=A((()=>{var t;return null!==(t=Dt.dataStore.eventHooks.growingBehavior)&&void 0!==t?t:Behavior}));export{$t as GioApp,Ft as GioBehavior,Rt as GioComponent,Lt as GioPage,Ht as default};
package/package.json CHANGED
@@ -1,46 +1,31 @@
1
1
  {
2
2
  "name": "gio-miniprogram-sdk",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "GrowngIO官方小程序 SDK,具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持微信小程序、支付宝小程序、百度小程序、字节(抖音头条)小程序、QQ小程序、淘宝小程序、京东小程序、快手小程序、快应用。",
5
- "main": "./dist/wechat.js",
6
5
  "author": "anyi@startdt.com",
7
6
  "license": "GNU General Public License v3.0",
8
7
  "scripts": {
9
- "build:full": "./bin/build/full.sh",
10
- "build:jd": "./bin/build/jd.sh",
11
- "build:ks": "./bin/build/ks.sh",
12
- "build:my": "./bin/build/my.sh",
13
- "build:plugins": "bin/build/plugins.sh",
14
- "build:qq": "./bin/build/qq.sh",
15
- "build:quickapp": "./bin/build/quickapp.sh",
16
- "build:swan": "./bin/build/swan.sh",
17
- "build:taro": "./bin/build/taro.sh",
18
- "build:tb": "./bin/build/tb.sh",
19
- "build:tt": "./bin/build/tt.sh",
20
- "build:uniapp": "./bin/build/uniapp.sh",
21
- "build:wx": "./bin/build/wx.sh",
22
- "build": "./bin/build/all.sh",
23
- "dev:full": "./bin/dev/full.sh",
24
- "dev:jd": "./bin/dev/jd.sh",
25
- "dev:ks": "./bin/dev/ks.sh",
26
- "dev:my": "./bin/dev/my.sh",
27
- "dev:plugins": "./bin/dev/plugins.sh",
28
- "dev:qq": "./bin/dev/qq.sh",
29
- "dev:quickapp": "./bin/dev/quickapp.sh",
30
- "dev:swan": "./bin/dev/swan.sh",
31
- "dev:taro": "./bin/dev/taro.sh",
32
- "dev:tb": "./bin/dev/tb.sh",
33
- "dev:tt": "./bin/dev/tt.sh",
34
- "dev:uniapp": "./bin/dev/uniapp.sh",
35
- "dev:wx": "./bin/dev/wx.sh",
36
- "lint": "eslint --fix 'src/**/*.{js,ts}'"
8
+ "build:jd": "rollup -c rollup.config.js --jd",
9
+ "build:ks": "rollup -c rollup.config.js --ks",
10
+ "build:my": "rollup -c rollup.config.js --my",
11
+ "build:plugins": "rollup -c rollup.plugins.config.js --plugins",
12
+ "build:qq": "rollup -c rollup.config.js --qq",
13
+ "build:quickapp": "rollup -c rollup.config.js --quickapp",
14
+ "build:swan": "rollup -c rollup.config.js --swan",
15
+ "build:taro": "rollup -c rollup.config.js --framework-taro",
16
+ "build:tb": "rollup -c rollup.config.js --tb",
17
+ "build:tt": "rollup -c rollup.config.js --tt",
18
+ "build:uniapp": "rollup -c rollup.config.js --framework-uniapp",
19
+ "build:wx": "rollup -c rollup.config.js --wx",
20
+ "build": "./bin/build.sh",
21
+ "lint": "eslint --fix 'src/**/*.{js,ts}'",
22
+ "test": "./bin/test/autoTest-wechat.sh",
23
+ "test:taro3-react": "./bin/test/autoTest-taro3-react.sh",
24
+ "test:taro3-vue3": "./bin/test/autoTest-taro3-vue3.sh"
37
25
  },
38
- "engines": {
39
- "node": "16.x"
40
- },
41
- "dependencies": {
42
- "mitt": "^3.0.0",
43
- "querystringify": "^2.2.0"
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://git.growingio.cn/growing/sdk/gio-miniprogram-autotracker.git"
44
29
  },
45
30
  "devDependencies": {
46
31
  "@babel/core": "^7.16.0",
@@ -51,35 +36,43 @@
51
36
  "@rollup/plugin-commonjs": "^21.0.1",
52
37
  "@rollup/plugin-node-resolve": "^13.0.2",
53
38
  "@rollup/plugin-replace": "^3.0.0",
54
- "@rollup/plugin-terser": "^0.4.3",
55
39
  "@rollup/plugin-typescript": "^8.2.3",
40
+ "@types/jest": "^27.0.3",
56
41
  "@types/webpack-env": "^1.16.2",
57
42
  "@typescript-eslint/eslint-plugin": "^5.7.0",
58
43
  "@typescript-eslint/parser": "^5.7.0",
59
44
  "babel-core": "^6.26.3",
60
- "babel-plugin-bulk-import": "^2.0.0",
61
45
  "eslint": "^8.4.1",
62
46
  "eslint-config-prettier": "^8.3.0",
63
47
  "eslint-plugin-prettier": "^4.0.0",
64
- "generate-source-map": "^0.0.5",
48
+ "jest": "^27.4.3",
49
+ "jest-serial-runner": "^1.2.1",
50
+ "miniprogram-automator": "^0.11.0",
65
51
  "prettier": "^2.3.2",
66
52
  "rollup": "^2.53.2",
67
53
  "rollup-plugin-copy": "^3.4.0",
68
54
  "rollup-plugin-filesize": "^9.1.1",
69
55
  "rollup-plugin-minip-components-transfer": "^1.0.0",
56
+ "rollup-plugin-terser": "^7.0.2",
70
57
  "shelljs": "^0.8.5",
71
58
  "tslib": "^2.3.1",
72
59
  "typescript": "^4.3.5"
73
60
  },
74
- "repository": {
75
- "type": "git",
76
- "url": "https://github.com/growingio/growingio-sdk-miniprogram-autotracker.git"
61
+ "dependencies": {
62
+ "@jest/test-sequencer": "^29.7.0",
63
+ "@types/shelljs": "^0.8.15",
64
+ "mitt": "^3.0.0",
65
+ "querystringify": "^2.2.0"
77
66
  },
78
67
  "bugs": {
79
68
  "url": "https://github.com/growingio/growingio-sdk-miniprogram-autotracker/issues"
80
69
  },
81
70
  "homepage": "https://github.com/growingio/growingio-sdk-miniprogram-autotracker#readme",
82
71
  "exports": {
72
+ ".": {
73
+ "import": "./dist/wechat.js",
74
+ "require": "./dist/wechat.js"
75
+ },
83
76
  "./wechat": {
84
77
  "import": "./dist/wechat.js",
85
78
  "require": "./dist/wechat.js"
@@ -139,6 +132,10 @@
139
132
  "./plugins/gioImpressionTracking": {
140
133
  "import": "./dist/plugins/gioImpressionTracking.js",
141
134
  "require": "./dist/plugins/gioImpressionTracking.js"
135
+ },
136
+ "./plugins/gioMultipleInstances": {
137
+ "import": "./dist/plugins/gioMultipleInstances.js",
138
+ "require": "./dist/plugins/gioMultipleInstances.js"
142
139
  }
143
140
  }
144
141
  }
package/rollup.config.js CHANGED
@@ -1,21 +1,26 @@
1
1
  // @ts-nocheck
2
2
  import { babel } from '@rollup/plugin-babel';
3
3
  import { version } from './package.json';
4
+ import { terser } from 'rollup-plugin-terser';
4
5
  import alias from '@rollup/plugin-alias';
5
6
  import commonjs from '@rollup/plugin-commonjs';
6
7
  import filesize from 'rollup-plugin-filesize';
7
8
  import path from 'path';
8
9
  import replace from '@rollup/plugin-replace';
9
10
  import resolve from '@rollup/plugin-node-resolve';
10
- import terser from '@rollup/plugin-terser';
11
11
  import typescript from '@rollup/plugin-typescript';
12
12
 
13
13
  const processENV = process.argv[process.argv.length - 1]
14
14
  .split('-')
15
15
  .filter((o) => o);
16
16
 
17
+ // 小程序平台
17
18
  const platform = processENV[0];
19
+ // 框架平台
18
20
  const frameName = processENV[1];
21
+ // 插件实例的入口名
22
+ const pluginInstanceName = frameName || platform === 'tb' ? frameName || platform : 'base';
23
+ // 小程序平台文件名枚举
19
24
  const PLATFORMS = {
20
25
  wx: 'wechat',
21
26
  my: 'alipay',
@@ -30,10 +35,9 @@ const PLATFORMS = {
30
35
 
31
36
  // 控制台打印当前打包的环境和小程序平台
32
37
  console.log(
33
- `Packaging ${
34
- PLATFORMS[platform]
35
- ? 'platform:' + PLATFORMS[platform]
36
- : 'framework:' + frameName
38
+ `Packaging ${PLATFORMS[platform]
39
+ ? 'platform:' + PLATFORMS[platform]
40
+ : 'framework:' + frameName
37
41
  }`
38
42
  );
39
43
 
@@ -56,7 +60,8 @@ const config = {
56
60
  __GIO_PLATFORM__: PLATFORMS[platform] ? platform : 'framework',
57
61
  __GIO_FRAMEWORK__: PLATFORMS[platform] ? 'native' : frameName,
58
62
  __GIO_PLATFORM_CONFIG__: `@@/platformConfig/${platform}.ts`,
59
- __GIO_PLATFORM_INSTANCE__: `@@/minipInstance/${platform}.ts`
63
+ __GIO_PLATFORM_INSTANCE__: `@@/minipInstance/${platform}.ts`,
64
+ __GIO_PLUGIN_INSTANCE__: `@@/core/pluginsInstance/${pluginInstanceName}.ts`
60
65
  }),
61
66
  alias({
62
67
  entries: {
@@ -1,11 +1,11 @@
1
1
  // @ts-nocheck
2
2
  import { babel } from '@rollup/plugin-babel';
3
+ import { terser } from 'rollup-plugin-terser';
3
4
  import alias from '@rollup/plugin-alias';
4
5
  import commonjs from '@rollup/plugin-commonjs';
5
6
  import filesize from 'rollup-plugin-filesize';
6
7
  import path from 'path';
7
8
  import resolve from '@rollup/plugin-node-resolve';
8
- import terser from '@rollup/plugin-terser';
9
9
  import typescript from '@rollup/plugin-typescript';
10
10
 
11
11
  const fs = require('fs');
@@ -14,17 +14,20 @@ const processENV = process.argv[process.argv.length - 1]
14
14
  .split('-')
15
15
  .filter((o) => o);
16
16
  // 获取是否打包全量插件
17
- const folder = processENV[0] ?? 'all';
17
+ const folder = processENV[0] ?? 'plugins';
18
+
19
+ // 获取外置插件的目录
20
+ const plugInFolder = fs
21
+ .readdirSync(`./src/${folder}`)
22
+ .filter((o) => !['.DS_Store'].includes(o));
18
23
 
19
24
  const expls = [];
20
- const plgs = fs.readdirSync(`./src/pluginsOut/${folder}`);
21
- plgs.forEach((plg) => {
22
- if (plg && plg.endsWith('.ts') && plg !== 'gioCustomTracking.ts') {
23
- const outName = plg.split('.')[0];
25
+ plugInFolder.forEach((plugin) => {
26
+ if (plugin && plugin.endsWith('.ts')) {
27
+ const outName = plugin.split('.')[0];
24
28
  expls.push({
25
- input: `${folder}/${plg}`,
26
- output: `${folder === 'ordinary' ? 'plugins/' : folder + '/'
27
- }${outName}.js`,
29
+ input: `src/${folder}/${plugin}`,
30
+ output: `${folder}/${outName}.js`,
28
31
  name: `${outName}.js`
29
32
  });
30
33
  }
@@ -32,7 +35,7 @@ plgs.forEach((plg) => {
32
35
 
33
36
  const configs = [];
34
37
  const configGenerat = ({ input, output, name }) => ({
35
- input: `src/pluginsOut/${input}`,
38
+ input,
36
39
  output: {
37
40
  file: `dist/${output}`,
38
41
  format: 'es',