@cherish8change/naviot-fillingpoint_sdk
Version:
naviot埋点SDK
2 lines • 2.92 kB
JavaScript
;var R=Object.create;var m=Object.defineProperty,O=Object.defineProperties,y=Object.getOwnPropertyDescriptor,A=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,w=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var b=(r,t,e)=>t in r?m(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,s=(r,t)=>{for(var e in t||(t={}))T.call(t,e)&&b(r,e,t[e]);if(I)for(var e of I(t))C.call(t,e)&&b(r,e,t[e]);return r},g=(r,t)=>O(r,A(t));var D=(r,t)=>{for(var e in t)m(r,e,{get:t[e],enumerable:!0})},E=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!T.call(r,i)&&i!==e&&m(r,i,{get:()=>t[i],enumerable:!(o=y(t,i))||o.enumerable});return r};var G=(r,t,e)=>(e=r!=null?R(w(r)):{},E(t||!r||!r.__esModule?m(e,"default",{value:r,enumerable:!0}):e,r)),K=r=>E(m({},"__esModule",{value:!0}),r);var Y={};D(Y,{default:()=>N});module.exports=K(Y);var h=require("uuid"),p=G(require("@turf/turf"));var c=class{constructor(t){this.STORAGE_KEY="FillingPoint_KEY";this.timeout=1e3*60*60;this.url="";var e,o;this.enable=!0,this.url=t.url,this.headers=(e=t.headers)!=null?e:{},this.data={reportId:(0,h.v4)(),userId:t.userId,latitude:-1,longitude:-1,mobile:(o=t.mobile)!=null?o:!1,userAgent:navigator.userAgent,platform:t.platform},this.listenerGeoChange(),typeof window<"u"&&!window.FillingPointSDK&&(window.FillingPointSDK=this)}listenerGeoChange(){navigator.geolocation.watchPosition(t=>{var l,u,d;console.log("\u5730\u7406\u4F4D\u7F6E\u53D8\u5316:",t);let e=t.coords.latitude,o=t.coords.longitude,i=JSON.parse((l=localStorage.getItem(this.STORAGE_KEY))!=null?l:"{}"),a=p.point([(u=i.latitude)!=null?u:e,(d=i.longitude)!=null?d:o]),n=p.point([e,o]),S=p.distance(a,n);if(this.setData("latitude",e),this.setData("longitude",o),S>3){let f=(0,h.v4)();this.setData("reportId",f),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(g(s({},i),{reportId:f,latitude:e,longitude:o})))}else!i.latitude&&!i.longitude&&localStorage.setItem(this.STORAGE_KEY,JSON.stringify(g(s({},i),{latitude:e,longitude:o})))},()=>{},{})}getData(t){return this.data[t]}setData(t,e){this.data[t]=e}setTime(t){this.timeout=t}disable(){this.enable=!1}repor(t,e,o,i=""){if(!this.enable)return;let a=new Date().getTime();window.requestAnimationFrame(()=>{var l,u;let n=JSON.parse((l=localStorage.getItem(this.STORAGE_KEY))!=null?l:"{}");if(a-((u=n.timestamp)!=null?u:0)>this.timeout){let d=(0,h.v4)();this.setData("reportId",d),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(g(s({},n),{reportId:d,timestamp:a})))}else localStorage.setItem(this.STORAGE_KEY,JSON.stringify(g(s({},n),{timestamp:a})));let S=s({tag:t,moduleName:e,action:o,params:i,timestamp:a},this.data);this.url&&fetch(this.url,{method:"post",headers:s({"Content-Type":"application/json"},this.headers),body:JSON.stringify(S)})})}},N=c;
//# sourceMappingURL=index.js.map