mta_analysis.js 6.01 KB
/* eslint-disable */
const MTA_CONFIG={ app_id:"", event_id:"", api_base:"https://pingtas.qq.com/pingd", prefix:"_mta_", version:"1.3.10", stat_share_app:!1, stat_pull_down_fresh:!1, stat_reach_bottom:!1, stat_param:!0 };function getNetworkType(a){wx.getNetworkType({ success(b){a(b.networkType);} });}
function getSystemInfo(){const a=wx.getSystemInfoSync();return { adt:encodeURIComponent(a.model), scl:a.pixelRatio, scr:`${a.windowWidth}x${a.windowHeight}`, lg:a.language, fl:a.version, jv:encodeURIComponent(a.system), tz:encodeURIComponent(a.platform) };} function getUID(){try {return wx.getStorageSync(`${MTA_CONFIG.prefix}auid`);} catch {}} function setUID(){try {const a=getRandom();wx.setStorageSync(`${MTA_CONFIG.prefix}auid`, a);return a;} catch {}}
function getSID(){try {return wx.getStorageSync(`${MTA_CONFIG.prefix}ssid`);} catch {}} function setSID(){try {const a=`s${getRandom()}`;wx.setStorageSync(`${MTA_CONFIG.prefix}ssid`, a);return a;} catch {}} function getRandom(a){for (var b=[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], c=10;c>1;c--){var d=Math.floor(10*Math.random()); const f=b[d];b[d]=b[c-1];b[c-1]=f;} for (c=d=0;c<5;c++)d=10*d+b[c];return `${a||""}${d}${ Date.now()}`;}
function getPagePath(){try {const a=getCurrentPages(); let b="/";a.length>0&&(b=a.pop().__route__);return b;} catch (error){console.log(`get current page path error:${error}`);}} function getMainInfo(){const a={ dm:"wechat.apps.xx", url:encodeURIComponent(getPagePath()+getQuery(MTA.Data.pageQuery)), pvi:"", si:"", ty:0 };a.pvi=function(){let b=getUID();b||(b=setUID(), a.ty=1);return b;}();a.si=function(){let a=getSID();a||(a=setSID());return a;}();return a;}
function getBasicInfo(){const a=getSystemInfo();getNetworkType((a) =>{try {wx.setStorageSync(`${MTA_CONFIG.prefix}ntdata`, a);} catch {}});a.ct=wx.getStorageSync(`${MTA_CONFIG.prefix}ntdata`)||"4g";return a;} function getExtentInfo(){let a=MTA.Data.userInfo;const b=[]; let c;for (c in a)a.hasOwnProperty(c)&&b.push(`${c}=${a[c]}`);a=b.join(";");return { r2:MTA_CONFIG.app_id, r4:"wx", ext:`v=${MTA_CONFIG.version}${a!==null&&a!==""?`;ui=${encodeURIComponent(a)}`:""}` };}
function getQuery(a){if (!MTA_CONFIG.stat_param||!a) return "";a=ignoreParams(a);const b=[]; let c;for (c in a)b.push(`${c}=${a[c]}`);return b.length>0?`?${b.join("&")}`:"";} function ignoreParams(a){if (MTA_CONFIG.ignore_params.length === 0) return a;const b={}; let c;for (c in a)MTA_CONFIG.ignore_params.includes(c)||(b[c]=a[c]);return b;}
function initOnload(){const a=Page;Page=function(b){const c=b.onLoad;b.onLoad=function(a){c&&c.call(this, a);MTA.Data.lastPageQuery=MTA.Data.pageQuery;MTA.Data.pageQuery=a;MTA.Data.lastPageUrl=MTA.Data.pageUrl;MTA.Data.pageUrl=getPagePath();MTA.Data.show=!1;MTA.Page.init();};a(b);};}
var MTA={ App:{ init(a){"appID"in a&&(MTA_CONFIG.app_id=a.appID);"eventID"in a&&(MTA_CONFIG.event_id=a.eventID);"statShareApp"in a&&(MTA_CONFIG.stat_share_app=a.statShareApp);"statPullDownFresh"in a&&(MTA_CONFIG.stat_pull_down_fresh=a.statPullDownFresh);"statReachBottom"in a&&(MTA_CONFIG.stat_reach_bottom=a.statReachBottom);"ignoreParams"in a&&(MTA_CONFIG.ignore_params=a.ignoreParams);"statParam"in a&&(MTA_CONFIG.stat_param=a.statParam);setSID();try {"lauchOpts"in a&&(MTA.Data.lanchInfo=a.lauchOpts,
MTA.Data.lanchInfo.landing=1);} catch {}"autoReport"in a&&a.autoReport&&initOnload();} }, Page:{ init(){const a=getCurrentPages()[getCurrentPages().length-1];a.onShow&&!function(){const b=a.onShow;a.onShow=function(){if (!0===MTA.Data.show){const a=MTA.Data.lastPageQuery;MTA.Data.lastPageQuery=MTA.Data.pageQuery;MTA.Data.pageQuery=a;MTA.Data.lastPageUrl=MTA.Data.pageUrl;MTA.Data.pageUrl=getPagePath();}MTA.Data.show=!0;MTA.Page.stat();Reflect.apply(b, this, arguments);};}();MTA_CONFIG.stat_pull_down_fresh&&a.onPullDownRefresh&&
!function(){const b=a.onPullDownRefresh;a.onPullDownRefresh=function(){MTA.Event.stat(`${MTA_CONFIG.prefix}pulldownfresh`, { url:a.__route__ });Reflect.apply(b, this, arguments);};}();MTA_CONFIG.stat_reach_bottom&&a.onReachBottom&&!function(){const b=a.onReachBottom;a.onReachBottom=function(){MTA.Event.stat(`${MTA_CONFIG.prefix}reachbottom`, { url:a.__route__ });Reflect.apply(b, this, arguments);};}();MTA_CONFIG.stat_share_app&&a.onShareAppMessage&&!function(){const b=a.onShareAppMessage;a.onShareAppMessage=function(){MTA.Event.stat(`${MTA_CONFIG.prefix
}shareapp`, { url:a.__route__ });return Reflect.apply(b, this, arguments);};}();}, multiStat(a, b){if (b===1)MTA.Page.stat(a), !0;else {const c=getCurrentPages()[getCurrentPages().length-1];c.onShow&&!function(){const b=c.onShow;c.onShow=function(){MTA.Page.stat(a);b.call(this, arguments);};}();}}, stat(a){if (MTA_CONFIG.app_id!==""){const b=[]; let c=getExtentInfo();a&&(c.r2=a);a=[ getMainInfo(), c, getBasicInfo() ];if (MTA.Data.lanchInfo){a.push({ ht:MTA.Data.lanchInfo.scene });MTA.Data.pageQuery&&MTA.Data.pageQuery._mta_ref_id&&
a.push({ rarg:MTA.Data.pageQuery._mta_ref_id });try {MTA.Data.lanchInfo.landing===1&&(c.ext+=";lp=1", MTA.Data.lanchInfo.landing=0);} catch {}}a.push({ rdm:"/", rurl:MTA.Data.lastPageUrl.length<=0?MTA.Data.pageUrl+getQuery(MTA.Data.lastPageQuery):encodeURIComponent(MTA.Data.lastPageUrl+getQuery(MTA.Data.lastPageQuery)) });a.push({ rand:Date.now() });c=0;for (let d=a.length;c<d;c++) for (const f in a[c])a[c].hasOwnProperty(f)&&b.push(`${f}=${a[c][f]===undefined?"":a[c][f]}`);wx.request({ url:`${MTA_CONFIG.api_base
}?${b.join("&").toLowerCase()}` });}} }, Event:{ stat(a, b){if (MTA_CONFIG.event_id!==""){const c=[]; let d=getMainInfo(); let f=getExtentInfo();d.dm="wxapps.click";d.url=a;f.r2=MTA_CONFIG.event_id;let e=b===undefined?{}:b;let g; const k=[];for (g in e)e.hasOwnProperty(g)&&k.push(`${encodeURIComponent(g)}=${encodeURIComponent(e[g])}`);e=k.join(";");f.r5=e;e=0;d=[ d, f, getBasicInfo(), { rand:Date.now() } ];for (f=d.length;e<f;e++) for (const h in d[e])d[e].hasOwnProperty(h)&&c.push(`${h}=${d[e][h]===undefined?"":d[e][h]}`);
    wx.request({ url:`${MTA_CONFIG.api_base}?${c.join("&").toLowerCase()}` });}} }, Data:{ userInfo:null, lanchInfo:null, pageQuery:null, lastPageQuery:null, pageUrl:"", lastPageUrl:"", show:!1 } };module.exports=MTA;