@kbapp/data-analysis 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +454 -0
- package/dist/data-analysis.d.ts +86 -0
- package/dist/helpers/filter-undefined-properties.d.ts +8 -0
- package/dist/helpers/load-script.d.ts +10 -0
- package/dist/helpers/object-to-map.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +863 -0
- package/dist/index.umd.js +1 -0
- package/dist/lib/gsido-proxy.d.ts +24 -0
- package/dist/models/DocActionEvent.d.ts +85 -0
- package/dist/models/DocVisitEvent.d.ts +85 -0
- package/examples/index.html +209 -0
- package/package.json +30 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(O,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(O=typeof globalThis<"u"?globalThis:O||self,_(O.kbDataAnalysis={}))})(this,(function(O){"use strict";const _=class{constructor(n){this.errorCode=n.errorCode,this.errorMsg=n.errorMsg}};_.UNKNOWN=new _({errorCode:1e3,errorMsg:"未知错误"}),_.UNSUPPORTED_VERSION=new _({errorCode:1001,errorMsg:"当前开吧版本不支持"}),_.TIMEOUT=new _({errorCode:1002,errorMsg:"执行超时"}),_.UNSUPPORTED_BRIDGE_ENV=new _({errorCode:1003,errorMsg:"请在开吧app内执行"});let S=_;const ne=()=>{const o=(i,a,f)=>{var d="";typeof a=="function"&&(f=a,a={});var g={data:a===void 0?null:a};if(typeof f=="function"){var m="dscb"+window.dscb++;window[m]=f,g._dscbstub=m}if(g=JSON.stringify(g),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(d=window.flutter_inappwebview.callHandler(""+i,g)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(d=prompt("_flutterDsbridge="+i,g)),d instanceof Promise)return d;try{return JSON.parse(d||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},n=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,c=(()=>{const i=[],a=setInterval(()=>{n()&&(clearInterval(a),i.forEach(f=>{o.apply(window,f)}),i.length=0)},500);return(...f)=>{i.push(f)}})();var u={default:void 0,callHandler:function(i,a,f){return n()?o(i,a,f):c(i,a,f)},register:function(i,a,f){var d=f?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){u.callHandler("_dsb.dsinit")},0)),typeof a=="object"?d._obs[i]=a:d[i]=a},registerHandler:function(i,a){this.register(i,a,!0)}};return(function(){if(!window._dsf){var i={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:u,_handleMessageFromNative:function(f){var d=JSON.parse(f.data),g={id:f.callbackId,complete:!0},m=this._dsf[f.method],D=this._dsaf[f.method],W=function(B,P){g.data=B.apply(P,d),u.callHandler("_dsb.returnValue",g)},C=function(B,P){d.push(function(Y,U){g.data=Y,g.complete=U!==!1,u.callHandler("_dsb.returnValue",g)}),B.apply(P,d)};if(m)W(m,this._dsf);else if(D)C(D,this._dsaf);else{var R=f.method.split(".");if(R.length<2)return;var G=R.pop(),F=R.join("."),N=this._dsf._obs,y=N[F]||{},w=y[G];if(w&&typeof w=="function"){W(w,y);return}if(N=this._dsaf._obs,y=N[F]||{},w=y[G],w&&typeof w=="function"){C(w,y);return}}}};for(var a in i)window[a]=i[a]}})(),u},oe=(o=>/(kb)/i.test(o)?ne():{registerHandler(n,c){throw S.UNSUPPORTED_BRIDGE_ENV},callHandler(n,c,u){throw S.UNSUPPORTED_BRIDGE_ENV}})(window?.navigator?.userAgent);function yt(o){const n=c=>{let u;const i=f=>{(!u||u==="success")&&(u="success",c.success?.(f))},a=f=>{(!u||u==="error")&&(u="error",c.fail?.(f))};c.timeout&&setTimeout(()=>{a(S.TIMEOUT)},c.timeout);try{oe.callHandler(c.name,c.params,f=>{let d;try{d=typeof f=="string"?JSON.parse(f.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):f}catch{d=null}i(d)})}catch(f){a(f)}};return new Promise((c,u)=>{n({name:o.name,params:o.params,timeout:o.timeout,success:i=>{o.success?.(i),o.complete?.(),c(i)},fail:i=>{o.fail?.(i),o.complete?.(),u(i)}})})}const ot=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent);function wt(o,n){return new Promise(async(c,u)=>{try{const i=await n();o.success?.(i),c(i)}catch(i){const a=i?.errorCode?i:new S({errorCode:S.UNKNOWN.errorCode,errorMsg:String(i)});o.fail?.(a),u(a)}finally{o.complete?.()}})}function ie(o){let n;return function(...c){return n||(n=o(...c),Promise.resolve(n).catch(()=>{n=void 0}),n)}}const se=ie(()=>yt({name:"OpenActRequest",params:{type:35,data:{}}}));function ae(o){return wt(o,async()=>(await se()).vcode>=o.minVersion)}function ce(o,n){return(...c)=>ae({minVersion:o.minVersion}).then(u=>u?n(...c):Promise.reject(new S({errorCode:S.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${o.minVersion}`})))}function ue(o){if(typeof o!="object"||o===null||Array.isArray(o))return{};const n={};return Object.keys(o).forEach(c=>{const u=o[c];u!==void 0&&(n[c]=u)}),n}function it(o){return wt(o,ce({minVersion:80801},async()=>yt({name:"OpenActRequest",params:{type:60400,data:ue({eventId:o.eventName,trackParams:o.eventParams,ExtEventType:o.eventType})}})))}function st(o){const n=[];return Object.keys(o).forEach(c=>{n.push([c,o[c]])}),new Map(n)}const fe=o=>window[o.key]?window[o.key]:new Promise((n,c)=>{const u=window.document.createElement("script");u.setAttribute("src",o.src),u.async=!0,u.onload=()=>{n(window[o.key])},u.onerror=i=>{c(i)},window.document.head.appendChild(u)}),vt=(()=>{let o,n="";function c(i){n=i.sdkURL}async function u(){return n?o||(o=new Promise(async(i,a)=>{try{await fe({src:n,key:"GsIdo"}),i(window.GsIdo)}catch(f){o=void 0,a(f)}}),o):Promise.reject(new Error("GsIdo SDK 地址未配置,请先调用 GsidoProxy.configureSdk"))}return{configure:c,load:u}})(),j=new Proxy({},{get(n,c){return c==="configureSdk"?vt.configure:c==="getGsido"?window.GsIdo:function(...u){return vt.load().then(i=>{const a=i[c];if(typeof a!="function")throw new Error(`${c} 不是 GsIdo 的有效方法`);return a(...u)})}}});var z=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function le(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var L={exports:{}};L.exports;var At;function de(){return At||(At=1,(function(o,n){var c=200,u="__lodash_hash_undefined__",i=9007199254740991,a="[object Arguments]",f="[object Array]",d="[object Boolean]",g="[object Date]",m="[object Error]",D="[object Function]",W="[object GeneratorFunction]",C="[object Map]",R="[object Number]",G="[object Object]",F="[object Promise]",N="[object RegExp]",y="[object Set]",w="[object String]",B="[object Symbol]",P="[object WeakMap]",Y="[object ArrayBuffer]",U="[object DataView]",Ot="[object Float32Array]",Et="[object Float64Array]",St="[object Int8Array]",jt="[object Int16Array]",mt="[object Int32Array]",Ct="[object Uint8Array]",Pt="[object Uint8ClampedArray]",It="[object Uint16Array]",xt="[object Uint32Array]",be=/[\\^$.*+?()[\]{}|]/g,_e=/\w*$/,ye=/^\[object .+?Constructor\]$/,we=/^(?:0|[1-9]\d*)$/,l={};l[a]=l[f]=l[Y]=l[U]=l[d]=l[g]=l[Ot]=l[Et]=l[St]=l[jt]=l[mt]=l[C]=l[R]=l[G]=l[N]=l[y]=l[w]=l[B]=l[Ct]=l[Pt]=l[It]=l[xt]=!0,l[m]=l[D]=l[P]=!1;var ve=typeof z=="object"&&z&&z.Object===Object&&z,Ae=typeof self=="object"&&self&&self.Object===Object&&self,v=ve||Ae||Function("return this")(),Mt=n&&!n.nodeType&&n,Dt=Mt&&!0&&o&&!o.nodeType&&o,Te=Dt&&Dt.exports===Mt;function Oe(t,e){return t.set(e[0],e[1]),t}function Ee(t,e){return t.add(e),t}function Se(t,e){for(var r=-1,s=t?t.length:0;++r<s&&e(t[r],r,t)!==!1;);return t}function je(t,e){for(var r=-1,s=e.length,h=t.length;++r<s;)t[h+r]=e[r];return t}function Rt(t,e,r,s){for(var h=-1,p=t?t.length:0;++h<p;)r=e(r,t[h],h,t);return r}function me(t,e){for(var r=-1,s=Array(t);++r<t;)s[r]=e(r);return s}function Ce(t,e){return t?.[e]}function Gt(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function Nt(t){var e=-1,r=Array(t.size);return t.forEach(function(s,h){r[++e]=[h,s]}),r}function at(t,e){return function(r){return t(e(r))}}function Bt(t){var e=-1,r=Array(t.size);return t.forEach(function(s){r[++e]=s}),r}var Pe=Array.prototype,Ie=Function.prototype,Z=Object.prototype,ct=v["__core-js_shared__"],Ut=(function(){var t=/[^.]+$/.exec(ct&&ct.keys&&ct.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""})(),Ht=Ie.toString,E=Z.hasOwnProperty,Q=Z.toString,xe=RegExp("^"+Ht.call(E).replace(be,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),kt=Te?v.Buffer:void 0,Kt=v.Symbol,Vt=v.Uint8Array,Me=at(Object.getPrototypeOf,Object),De=Object.create,Re=Z.propertyIsEnumerable,Ge=Pe.splice,Lt=Object.getOwnPropertySymbols,Ne=kt?kt.isBuffer:void 0,Be=at(Object.keys,Object),ut=K(v,"DataView"),$=K(v,"Map"),ft=K(v,"Promise"),lt=K(v,"Set"),dt=K(v,"WeakMap"),J=K(Object,"create"),Ue=M(ut),He=M($),ke=M(ft),Ke=M(lt),Ve=M(dt),Wt=Kt?Kt.prototype:void 0,Ft=Wt?Wt.valueOf:void 0;function I(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var s=t[e];this.set(s[0],s[1])}}function Le(){this.__data__=J?J(null):{}}function We(t){return this.has(t)&&delete this.__data__[t]}function Fe(t){var e=this.__data__;if(J){var r=e[t];return r===u?void 0:r}return E.call(e,t)?e[t]:void 0}function $e(t){var e=this.__data__;return J?e[t]!==void 0:E.call(e,t)}function Je(t,e){var r=this.__data__;return r[t]=J&&e===void 0?u:e,this}I.prototype.clear=Le,I.prototype.delete=We,I.prototype.get=Fe,I.prototype.has=$e,I.prototype.set=Je;function A(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var s=t[e];this.set(s[0],s[1])}}function ze(){this.__data__=[]}function qe(t){var e=this.__data__,r=tt(e,t);if(r<0)return!1;var s=e.length-1;return r==s?e.pop():Ge.call(e,r,1),!0}function Xe(t){var e=this.__data__,r=tt(e,t);return r<0?void 0:e[r][1]}function Ye(t){return tt(this.__data__,t)>-1}function Ze(t,e){var r=this.__data__,s=tt(r,t);return s<0?r.push([t,e]):r[s][1]=e,this}A.prototype.clear=ze,A.prototype.delete=qe,A.prototype.get=Xe,A.prototype.has=Ye,A.prototype.set=Ze;function H(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var s=t[e];this.set(s[0],s[1])}}function Qe(){this.__data__={hash:new I,map:new($||A),string:new I}}function tr(t){return et(this,t).delete(t)}function er(t){return et(this,t).get(t)}function rr(t){return et(this,t).has(t)}function nr(t,e){return et(this,t).set(t,e),this}H.prototype.clear=Qe,H.prototype.delete=tr,H.prototype.get=er,H.prototype.has=rr,H.prototype.set=nr;function k(t){this.__data__=new A(t)}function or(){this.__data__=new A}function ir(t){return this.__data__.delete(t)}function sr(t){return this.__data__.get(t)}function ar(t){return this.__data__.has(t)}function cr(t,e){var r=this.__data__;if(r instanceof A){var s=r.__data__;if(!$||s.length<c-1)return s.push([t,e]),this;r=this.__data__=new H(s)}return r.set(t,e),this}k.prototype.clear=or,k.prototype.delete=ir,k.prototype.get=sr,k.prototype.has=ar,k.prototype.set=cr;function ur(t,e){var r=pt(t)||Dr(t)?me(t.length,String):[],s=r.length,h=!!s;for(var p in t)E.call(t,p)&&!(h&&(p=="length"||Pr(p,s)))&&r.push(p);return r}function $t(t,e,r){var s=t[e];(!(E.call(t,e)&&Xt(s,r))||r===void 0&&!(e in t))&&(t[e]=r)}function tt(t,e){for(var r=t.length;r--;)if(Xt(t[r][0],e))return r;return-1}function fr(t,e){return t&&Jt(e,bt(e),t)}function ht(t,e,r,s,h,p,T){var b;if(s&&(b=p?s(t,h,p,T):s(t)),b!==void 0)return b;if(!rt(t))return t;var Qt=pt(t);if(Qt){if(b=jr(t),!e)return Or(t,b)}else{var V=x(t),te=V==D||V==W;if(Gr(t))return br(t,e);if(V==G||V==a||te&&!p){if(Gt(t))return p?t:{};if(b=mr(te?{}:t),!e)return Er(t,fr(b,t))}else{if(!l[V])return p?t:{};b=Cr(t,V,ht,e)}}T||(T=new k);var ee=T.get(t);if(ee)return ee;if(T.set(t,b),!Qt)var re=r?Sr(t):bt(t);return Se(re||t,function(_t,nt){re&&(nt=_t,_t=t[nt]),$t(b,nt,ht(_t,e,r,s,nt,t,T))}),b}function lr(t){return rt(t)?De(t):{}}function dr(t,e,r){var s=e(t);return pt(t)?s:je(s,r(t))}function hr(t){return Q.call(t)}function gr(t){if(!rt(t)||xr(t))return!1;var e=Zt(t)||Gt(t)?xe:ye;return e.test(M(t))}function pr(t){if(!qt(t))return Be(t);var e=[];for(var r in Object(t))E.call(t,r)&&r!="constructor"&&e.push(r);return e}function br(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}function gt(t){var e=new t.constructor(t.byteLength);return new Vt(e).set(new Vt(t)),e}function _r(t,e){var r=e?gt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}function yr(t,e,r){var s=e?r(Nt(t),!0):Nt(t);return Rt(s,Oe,new t.constructor)}function wr(t){var e=new t.constructor(t.source,_e.exec(t));return e.lastIndex=t.lastIndex,e}function vr(t,e,r){var s=e?r(Bt(t),!0):Bt(t);return Rt(s,Ee,new t.constructor)}function Ar(t){return Ft?Object(Ft.call(t)):{}}function Tr(t,e){var r=e?gt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function Or(t,e){var r=-1,s=t.length;for(e||(e=Array(s));++r<s;)e[r]=t[r];return e}function Jt(t,e,r,s){r||(r={});for(var h=-1,p=e.length;++h<p;){var T=e[h],b=void 0;$t(r,T,b===void 0?t[T]:b)}return r}function Er(t,e){return Jt(t,zt(t),e)}function Sr(t){return dr(t,bt,zt)}function et(t,e){var r=t.__data__;return Ir(e)?r[typeof e=="string"?"string":"hash"]:r.map}function K(t,e){var r=Ce(t,e);return gr(r)?r:void 0}var zt=Lt?at(Lt,Object):Ur,x=hr;(ut&&x(new ut(new ArrayBuffer(1)))!=U||$&&x(new $)!=C||ft&&x(ft.resolve())!=F||lt&&x(new lt)!=y||dt&&x(new dt)!=P)&&(x=function(t){var e=Q.call(t),r=e==G?t.constructor:void 0,s=r?M(r):void 0;if(s)switch(s){case Ue:return U;case He:return C;case ke:return F;case Ke:return y;case Ve:return P}return e});function jr(t){var e=t.length,r=t.constructor(e);return e&&typeof t[0]=="string"&&E.call(t,"index")&&(r.index=t.index,r.input=t.input),r}function mr(t){return typeof t.constructor=="function"&&!qt(t)?lr(Me(t)):{}}function Cr(t,e,r,s){var h=t.constructor;switch(e){case Y:return gt(t);case d:case g:return new h(+t);case U:return _r(t,s);case Ot:case Et:case St:case jt:case mt:case Ct:case Pt:case It:case xt:return Tr(t,s);case C:return yr(t,s,r);case R:case w:return new h(t);case N:return wr(t);case y:return vr(t,s,r);case B:return Ar(t)}}function Pr(t,e){return e=e??i,!!e&&(typeof t=="number"||we.test(t))&&t>-1&&t%1==0&&t<e}function Ir(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function xr(t){return!!Ut&&Ut in t}function qt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Z;return t===r}function M(t){if(t!=null){try{return Ht.call(t)}catch{}try{return t+""}catch{}}return""}function Mr(t){return ht(t,!0,!0)}function Xt(t,e){return t===e||t!==t&&e!==e}function Dr(t){return Rr(t)&&E.call(t,"callee")&&(!Re.call(t,"callee")||Q.call(t)==a)}var pt=Array.isArray;function Yt(t){return t!=null&&Nr(t.length)&&!Zt(t)}function Rr(t){return Br(t)&&Yt(t)}var Gr=Ne||Hr;function Zt(t){var e=rt(t)?Q.call(t):"";return e==D||e==W}function Nr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=i}function rt(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Br(t){return!!t&&typeof t=="object"}function bt(t){return Yt(t)?ur(t):pr(t)}function Ur(){return[]}function Hr(){return!1}o.exports=Mr})(L,L.exports)),L.exports}var he=de();const ge=le(he);class pe{constructor(n){this.globalAttrs=[],this.debugger=n.debugger||!1,j.configureSdk({sdkURL:n.sdkUrl}),j.init({gsAppid:n.appid}),j.setDebugEnable(this.debugger)}log(...n){this.debugger&&console.log(...n)}getReportDataMergeGlobalAttrs(n){const c={},u=ge(Object.assign.apply(null,[{},...this.globalAttrs,n]));return Object.keys(u).forEach(i=>{if(typeof u[i]=="number")return c[i]=u[i];u[i]&&(c[i]=String(u[i]))}),c}getGsido(){return j.getGsido()}setReportGlobalAttrs(n={}){this.globalAttrs.push(n)}report(n){return ot?((i,a)=>{this.log("[个推] 桥接埋点",{name:i,params:a}),it({eventName:i,eventParams:a})})(n.name,this.getReportDataMergeGlobalAttrs(n.params)):((i,a)=>{this.log("[个推] web埋点",{name:i,params:a}),j.onEvent({id:i,attrs:st(a)})})(n.name,this.getReportDataMergeGlobalAttrs(n.params))}reportBeginEvent(n){return ot?((i,a)=>{this.log("[个推] 桥接.begin埋点",{name:i,params:a}),it({eventName:i,eventParams:a,eventType:"Begin"})})(n.name,this.getReportDataMergeGlobalAttrs(n.params)):((i,a)=>{this.log("[个推] web.begin埋点",{name:i,params:a}),j.onBeginEvent({id:i,attrs:st(a)})})(n.name,this.getReportDataMergeGlobalAttrs(n.params))}reportEndEvent(n){return ot?((i,a)=>{this.log("[个推] 桥接.end埋点",{name:i,params:a}),it({eventName:i,eventParams:a,eventType:"End"})})(n.name,this.getReportDataMergeGlobalAttrs(n.params)):((i,a)=>{this.log("[个推] web.end埋点",{name:i,params:a}),j.onEndEvent({id:i,attrs:st(a)})})(n.name,this.getReportDataMergeGlobalAttrs(n.params))}}function Tt(o){if(typeof o!="object"||o===null||Array.isArray(o))return{};const n={};return Object.keys(o).forEach(c=>{const u=o[c];u!==void 0&&(n[c]=u)}),n}class q{constructor(n){this.act=n.act,this.biz=n.biz,this.unit=n.unit,this.ref1=n.ref1,this.ref2=n.ref2,this.ref3=n.ref3,this.sid=n.sid,this.title=n.title,this.channel=n.channel,this.depart=n.depart,this.suid=n.suid,Object.defineProperty(this,"docId",{enumerable:!0,configurable:!1,get:()=>q.generateDocId(this)})}static generateDocId(n){return[n.biz,n.unit,n.ref1,n.ref2,n.ref3,n.sid].filter(c=>!!c).join("-")}static createDocTrackEvent(n){return Tt(new q(n))}}class X{constructor(n){this.biz=n.biz,this.unit=n.unit,this.ref1=n.ref1,this.ref2=n.ref2,this.ref3=n.ref3,this.sid=n.sid,this.title=n.title,this.channel=n.channel,this.depart=n.depart,this.referer=n.referer,this.suid=n.suid,Object.defineProperty(this,"docId",{enumerable:!0,configurable:!1,get:()=>X.generateDocId(this)})}static generateDocId(n){return[n.biz,n.unit,n.ref1,n.ref2,n.ref3,n.sid].filter(c=>!!c).join("-")}static createDocTrackEvent(n){return Tt(new X(n))}}O.DataAnalysis=pe,O.DocActionEvent=q,O.DocVisitEvent=X,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定义 Gsido 代理对象的类型
|
|
3
|
+
* 1. 继承 GsIdo 命名空间的所有方法,且所有方法返回值转为 Promise 类型
|
|
4
|
+
* 2. 新增 SDK 配置方法
|
|
5
|
+
*/
|
|
6
|
+
type GsidoProxyType = {
|
|
7
|
+
[K in keyof typeof GsIdo]: (typeof GsIdo)[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : never;
|
|
8
|
+
} & {
|
|
9
|
+
/** 配置 GsIdo SDK 地址(需在调用其他方法前执行) */
|
|
10
|
+
configureSdk: (config: {
|
|
11
|
+
sdkURL: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
getGsido: () => typeof GsIdo | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* GsIdo 代理对象:自动加载 SDK + 所有方法 Promise 化
|
|
17
|
+
* 特性:
|
|
18
|
+
* 1. 先通过 configureSdk 配置 SDK 地址,再调用其他方法
|
|
19
|
+
* 2. 所有方法返回 Promise,自动等待 SDK 加载完成后执行
|
|
20
|
+
* 3. SDK 单例加载,重复调用不重复请求
|
|
21
|
+
* 4. ES6 模块导出,无全局挂载
|
|
22
|
+
*/
|
|
23
|
+
export declare const GsidoProxy: GsidoProxyType;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @description 稿件动作 开吧意义上的第二类埋点
|
|
4
|
+
* @example
|
|
5
|
+
* **示例代码**
|
|
6
|
+
```js
|
|
7
|
+
import { DocActionEvent } from '@kbapp/data-analysis';
|
|
8
|
+
|
|
9
|
+
kbTracker.report({
|
|
10
|
+
name: 'DocActionEvent', // 事件名称
|
|
11
|
+
params: DocActionEvent.createDocTrackEvent({
|
|
12
|
+
act: '动作标识',
|
|
13
|
+
biz: '业务类型',
|
|
14
|
+
unit: '业务单元',
|
|
15
|
+
ref1: '对象标识1 可为空',
|
|
16
|
+
ref2: '对象标识2 可为空',
|
|
17
|
+
ref3: '对象标识3 可为空',
|
|
18
|
+
sid: '站点 ID 可为空',
|
|
19
|
+
title: '稿件标题',
|
|
20
|
+
channel: '所属单位 可为空',
|
|
21
|
+
depart: '所属部门 可为空',
|
|
22
|
+
suid: '分享人的用用户id 可为空'
|
|
23
|
+
}),
|
|
24
|
+
})
|
|
25
|
+
```
|
|
26
|
+
*/
|
|
27
|
+
export declare class DocActionEvent {
|
|
28
|
+
/**
|
|
29
|
+
* 动作标识. 以下为保留关键字, 语义相同的动作请复用如下定义:
|
|
30
|
+
* 点赞: like
|
|
31
|
+
* 分享: share
|
|
32
|
+
* 评论: reply
|
|
33
|
+
* 评论的评论: reply_r
|
|
34
|
+
* 评论的点赞: reply_l
|
|
35
|
+
* 投票: vote
|
|
36
|
+
* 签到: sign
|
|
37
|
+
* 购买: buy
|
|
38
|
+
* 打赏: reward
|
|
39
|
+
*
|
|
40
|
+
* 动作语义不符合如上定义时, 请自行定义动作标识.
|
|
41
|
+
*/
|
|
42
|
+
act: string;
|
|
43
|
+
/** 业务类型. {@link KbModule}. 非空. */
|
|
44
|
+
biz: string;
|
|
45
|
+
/** 业务单元. 用以保持稿件定义的同构性: 同一个业务单元下的 ref 含义和层级结构总是一致的. 可为空. */
|
|
46
|
+
unit?: string;
|
|
47
|
+
/** 对象标识1. 非空. */
|
|
48
|
+
ref1: string;
|
|
49
|
+
/** 对象标识2. 可为空. */
|
|
50
|
+
ref2?: string;
|
|
51
|
+
/** 对象标识3. 可为空. */
|
|
52
|
+
ref3?: string;
|
|
53
|
+
/** 站点 ID. 可为空. */
|
|
54
|
+
sid?: number;
|
|
55
|
+
/**
|
|
56
|
+
* 稿件标题. 非空.
|
|
57
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
58
|
+
*/
|
|
59
|
+
title: string;
|
|
60
|
+
/**
|
|
61
|
+
* 所属单位. 可为空.
|
|
62
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
63
|
+
*/
|
|
64
|
+
channel?: string;
|
|
65
|
+
/**
|
|
66
|
+
* 所属部门. 部门是单位的下属组织. 可为空.
|
|
67
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
68
|
+
*/
|
|
69
|
+
depart?: string;
|
|
70
|
+
/** 分享人的用用户id, 分享出去的链接自动追加 suid=xxx */
|
|
71
|
+
suid?: string;
|
|
72
|
+
/** 稿件标识, 拼接非空字段得到: biz-unit-ref1-ref2-ref3-siteId */
|
|
73
|
+
docId: string;
|
|
74
|
+
constructor(params: Omit<DocActionEvent, 'docId'>);
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @description 生成稿件标识
|
|
78
|
+
*/
|
|
79
|
+
static generateDocId(params: DocActionEvent): string;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @description 生成稿件数据(自动生成docId)
|
|
83
|
+
*/
|
|
84
|
+
static createDocTrackEvent(params: Omit<DocActionEvent, 'docId'>): Pick<DocActionEvent, "unit" | "channel" | "title" | "docId" | "act" | "biz" | "ref1" | "ref2" | "ref3" | "sid" | "depart" | "suid" | undefined>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @description 稿件浏览 开吧意义上的第一类埋点
|
|
4
|
+
* @example
|
|
5
|
+
* **示例代码**
|
|
6
|
+
```js
|
|
7
|
+
import { DocVisitEvent } from '@kbapp/data-analysis';
|
|
8
|
+
|
|
9
|
+
kbTracker.report({
|
|
10
|
+
name: 'DocVisitEvent', // 事件名称
|
|
11
|
+
params: DocVisitEvent.createDocTrackEvent({
|
|
12
|
+
biz: '业务类型',
|
|
13
|
+
unit: '业务单元',
|
|
14
|
+
ref1: '对象标识1 可为空',
|
|
15
|
+
ref2: '对象标识2 可为空',
|
|
16
|
+
ref3: '对象标识3 可为空',
|
|
17
|
+
sid: '站点 ID 可为空',
|
|
18
|
+
title: '稿件标题',
|
|
19
|
+
channel: '所属单位 可为空',
|
|
20
|
+
depart: '所属部门 可为空',
|
|
21
|
+
suid: '分享人的用用户id 可为空'
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
*/
|
|
26
|
+
export declare class DocVisitEvent {
|
|
27
|
+
/**
|
|
28
|
+
* 访问来源, {@link Doc#getDocId()} 上级页面的稿件标识. 可为空.
|
|
29
|
+
*/
|
|
30
|
+
referer?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 业务类型. {@link KbModule}. 非空.
|
|
33
|
+
*/
|
|
34
|
+
biz: string;
|
|
35
|
+
/**
|
|
36
|
+
* 业务单元. 用以保持稿件定义的同构性: 同一个业务单元下的 ref 含义和层级结构总是一致的. 可为空.
|
|
37
|
+
*/
|
|
38
|
+
unit?: string;
|
|
39
|
+
/**
|
|
40
|
+
* 对象标识1. 非空.
|
|
41
|
+
*/
|
|
42
|
+
ref1: string;
|
|
43
|
+
/**
|
|
44
|
+
* 对象标识2. 可为空.
|
|
45
|
+
*/
|
|
46
|
+
ref2?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 对象标识3. 可为空.
|
|
49
|
+
*/
|
|
50
|
+
ref3?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 站点 ID. 可为空.
|
|
53
|
+
*/
|
|
54
|
+
sid?: number;
|
|
55
|
+
/**
|
|
56
|
+
* 稿件标题. 非空.
|
|
57
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
58
|
+
*/
|
|
59
|
+
title: string;
|
|
60
|
+
/**
|
|
61
|
+
* 所属单位. 可为空.
|
|
62
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
63
|
+
*/
|
|
64
|
+
channel?: string;
|
|
65
|
+
/**
|
|
66
|
+
* 所属部门. 部门是单位的下属组织. 可为空.
|
|
67
|
+
* 此为冗余字段, 以便在分析平台查询. 考核统计场景下应使用维表.
|
|
68
|
+
*/
|
|
69
|
+
depart?: string;
|
|
70
|
+
/** 分享人的用用户id, 分享出去的链接自动追加 suid=xxx */
|
|
71
|
+
suid?: string;
|
|
72
|
+
/** 稿件标识, 拼接非空字段得到: biz-unit-ref1-ref2-ref3-siteId, 可通过 createDocTrackEvent 自动生成 */
|
|
73
|
+
docId: string;
|
|
74
|
+
constructor(params: Omit<DocVisitEvent, 'docId'>);
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @description 生成稿件标识
|
|
78
|
+
*/
|
|
79
|
+
static generateDocId(params: DocVisitEvent): string;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @description 生成稿件数据(自动生成docId)
|
|
83
|
+
*/
|
|
84
|
+
static createDocTrackEvent(params: Omit<DocVisitEvent, 'docId'>): Pick<DocVisitEvent, "unit" | "channel" | "title" | "docId" | "biz" | "ref1" | "ref2" | "ref3" | "sid" | "depart" | "suid" | "referer" | undefined>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>测试demo</title>
|
|
7
|
+
<link
|
|
8
|
+
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
|
|
9
|
+
rel="stylesheet"
|
|
10
|
+
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
|
|
11
|
+
crossorigin="anonymous"
|
|
12
|
+
/>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div id="app">
|
|
16
|
+
<div class="card m-2" v-for="(item, index) in list" :key="index">
|
|
17
|
+
<h5 class="card-header">
|
|
18
|
+
<div class="d-flex justify-content-between align-items-center">
|
|
19
|
+
<span class="flex-grow-1">{{item.title}}</span>
|
|
20
|
+
|
|
21
|
+
<template v-if="item.done.status.loading">
|
|
22
|
+
<button type="button" class="btn btn-primary" disabled>
|
|
23
|
+
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
|
|
24
|
+
</button>
|
|
25
|
+
</template>
|
|
26
|
+
<template v-else>
|
|
27
|
+
<button type="button" class="btn btn-primary" @click="item.done">{{item.buttonText}}</button>
|
|
28
|
+
</template>
|
|
29
|
+
</div>
|
|
30
|
+
</h5>
|
|
31
|
+
|
|
32
|
+
<div class="card-body">
|
|
33
|
+
<template v-if="item.subtitle">
|
|
34
|
+
<div class="card-title fw-bold">{{item.subtitle}}</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<template v-if="item.desc">
|
|
38
|
+
<div class="card-text">{{item.desc}}</div>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<template v-if="item.done.status.data">
|
|
42
|
+
<div class="alert alert-success mt-2" role="alert">{{item.done.status.data}}</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<template v-if="item.done.status.error">
|
|
46
|
+
<div class="alert alert-danger mt-2" role="alert">{{item.done.status.error}}</div>
|
|
47
|
+
</template>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</body>
|
|
52
|
+
<script type="module">
|
|
53
|
+
import { createApp, ref, reactive } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
|
|
54
|
+
import { DataAnalysis, DocActionEvent, DocVisitEvent } from '../dist/index.es.js'
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 装饰器,用于处理done函数的调用
|
|
58
|
+
* @param {Function} callback - 实际执行的函数
|
|
59
|
+
* @returns {Function} - 装饰后的函数
|
|
60
|
+
*/
|
|
61
|
+
const decorateDone = (callback) => {
|
|
62
|
+
/** 状态 */
|
|
63
|
+
const status = reactive({
|
|
64
|
+
/** 请求中 */
|
|
65
|
+
loading: false,
|
|
66
|
+
|
|
67
|
+
/** 请求完成 */
|
|
68
|
+
data: null,
|
|
69
|
+
|
|
70
|
+
/** 异常值 */
|
|
71
|
+
error: null,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
async function done() {
|
|
75
|
+
status.data = null
|
|
76
|
+
status.error = null
|
|
77
|
+
status.loading = true
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const data = await Promise.resolve(callback())
|
|
81
|
+
status.data = data
|
|
82
|
+
} catch (error) {
|
|
83
|
+
status.error = error
|
|
84
|
+
throw error
|
|
85
|
+
} finally {
|
|
86
|
+
status.loading = false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
done['status'] = status
|
|
91
|
+
|
|
92
|
+
return done
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const kbTracker = new DataAnalysis({
|
|
96
|
+
sdkUrl: 'https://page.kaiba315.com.cn/js/gsido-h5-min-1.0.7.1_final.js', // 个推SDK地址
|
|
97
|
+
appid: 'xzc9chqi1s5bPYs3SWtPm2', // 埋点应用ID,由开吧分配
|
|
98
|
+
debugger: true, // 开发环境可设为true,开启埋点日志输出
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const list = reactive([
|
|
102
|
+
{
|
|
103
|
+
title: 'report',
|
|
104
|
+
subtitle: '普通事件上报',
|
|
105
|
+
buttonText: '执行',
|
|
106
|
+
desc: `执行结果 上报事件`,
|
|
107
|
+
done: decorateDone(async () => {
|
|
108
|
+
kbTracker.report({
|
|
109
|
+
name: 'test_event_name',
|
|
110
|
+
params: {
|
|
111
|
+
test_event_params: '1',
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
return '上报成功'
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
title: 'report.DocVisitEvent',
|
|
119
|
+
subtitle: 'DocVisitEvent上报',
|
|
120
|
+
buttonText: '执行',
|
|
121
|
+
desc: `执行结果 上报事件`,
|
|
122
|
+
done: decorateDone(async () => {
|
|
123
|
+
kbTracker.report({
|
|
124
|
+
name: 'DocVisitEvent',
|
|
125
|
+
params: DocVisitEvent.createDocTrackEvent({
|
|
126
|
+
biz: 'MISC_PAGE',
|
|
127
|
+
ref1: 'about',
|
|
128
|
+
ref2: 'index',
|
|
129
|
+
title: '关于',
|
|
130
|
+
suid: '1234',
|
|
131
|
+
}),
|
|
132
|
+
})
|
|
133
|
+
return '上报成功'
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
title: 'report.DocActionEvent',
|
|
138
|
+
subtitle: 'DocActionEvent上报',
|
|
139
|
+
buttonText: '执行',
|
|
140
|
+
desc: `执行结果 上报事件`,
|
|
141
|
+
done: decorateDone(async () => {
|
|
142
|
+
kbTracker.report({
|
|
143
|
+
name: 'DocActionEvent',
|
|
144
|
+
params: DocActionEvent.createDocTrackEvent({
|
|
145
|
+
act: 'click',
|
|
146
|
+
biz: 'MISC_PAGE',
|
|
147
|
+
ref1: 'about',
|
|
148
|
+
ref2: 'index',
|
|
149
|
+
title: '关于',
|
|
150
|
+
suid: '1234',
|
|
151
|
+
}),
|
|
152
|
+
})
|
|
153
|
+
return '上报成功'
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
title: 'setReportGlobalAttrs',
|
|
158
|
+
subtitle: '设置全局公共上报属性',
|
|
159
|
+
buttonText: '执行',
|
|
160
|
+
desc: `执行结果 上报事件`,
|
|
161
|
+
done: decorateDone(async () => {
|
|
162
|
+
kbTracker.setReportGlobalAttrs({
|
|
163
|
+
userId: '123456', // 用户唯一标识
|
|
164
|
+
appVersion: '1.0.0', // APP版本号
|
|
165
|
+
})
|
|
166
|
+
return '设置成功'
|
|
167
|
+
}),
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
title: 'reportBeginEvent',
|
|
171
|
+
subtitle: '上报事件开始',
|
|
172
|
+
buttonText: '执行',
|
|
173
|
+
desc: `执行结果 上报事件`,
|
|
174
|
+
done: decorateDone(async () => {
|
|
175
|
+
kbTracker.reportBeginEvent({
|
|
176
|
+
name: 'test_event_name',
|
|
177
|
+
params: {
|
|
178
|
+
test_event_params: '1',
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
return '上报成功'
|
|
182
|
+
}),
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
title: 'reportEndEvent',
|
|
186
|
+
subtitle: '上报事件结束',
|
|
187
|
+
buttonText: '执行',
|
|
188
|
+
desc: `执行结果 上报事件`,
|
|
189
|
+
done: decorateDone(async () => {
|
|
190
|
+
kbTracker.reportEndEvent({
|
|
191
|
+
name: 'test_event_name',
|
|
192
|
+
params: {
|
|
193
|
+
test_event_params: '1',
|
|
194
|
+
},
|
|
195
|
+
})
|
|
196
|
+
return '上报成功'
|
|
197
|
+
}),
|
|
198
|
+
},
|
|
199
|
+
])
|
|
200
|
+
|
|
201
|
+
createApp({
|
|
202
|
+
setup() {
|
|
203
|
+
return {
|
|
204
|
+
list,
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
}).mount('#app')
|
|
208
|
+
</script>
|
|
209
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kbapp/data-analysis",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"description": "开吧app埋点平台",
|
|
8
|
+
"main": "./dist/index.umd.js",
|
|
9
|
+
"module": "./dist/index.es.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"unpkg": "./dist/index.umd.js",
|
|
12
|
+
"browser": "./dist/index.umd.js",
|
|
13
|
+
"author": "along",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "npm run build && web-dev-server --root-dir ./ --port 3000 --open /examples/index.html --node-resolve --no-cache",
|
|
16
|
+
"build": "rm -rf ./dist && vite build && npx tsc --emitDeclarationOnly",
|
|
17
|
+
"publish": "npm run build && npm publish"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@kbapp/market-partner-sdk": "^0.0.4",
|
|
21
|
+
"@types/lodash.clonedeep": "^4.5.9",
|
|
22
|
+
"lodash.clonedeep": "^4.5.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
26
|
+
"@web/dev-server": "^0.4.6",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"vite": "^7.3.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"baseUrl": "./",
|
|
9
|
+
"rootDir": "./src",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationDir": "./dist",
|
|
12
|
+
"lib": ["esnext", "dom"],
|
|
13
|
+
"sourceMap": false,
|
|
14
|
+
"moduleResolution": "Node",
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"resolveJsonModule": true
|
|
17
|
+
},
|
|
18
|
+
"include": ["src"]
|
|
19
|
+
}
|