@slan-health/tracker 1.0.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.
- package/.eslintrc.json +15 -0
- package/dist/es/createTracker.33fca2a1.js +643 -0
- package/dist/es/index.js +8 -0
- package/dist/es/react.js +21 -0
- package/dist/es/trackerStore.2d9f9635.js +8 -0
- package/dist/es/vue.js +91 -0
- package/dist/lib/createTracker.8d58679e.cjs +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/react.js +1 -0
- package/dist/lib/trackerStore.32eb3aae.cjs +1 -0
- package/dist/lib/vue.js +1 -0
- package/package.json +58 -0
- package/src/adapters/react/index.js +25 -0
- package/src/adapters/vue/createVueTracker.js +13 -0
- package/src/adapters/vue/hooks/usePageStay.js +23 -0
- package/src/adapters/vue/hooks/usePageTracker.js +67 -0
- package/src/adapters/vue/hooks/useTracker.js +44 -0
- package/src/adapters/vue/index.js +5 -0
- package/src/adapters/vue/rootStore.js +8 -0
- package/src/core/EventTimer.js +43 -0
- package/src/core/EventType.js +8 -0
- package/src/core/Queue.js +59 -0
- package/src/core/TrackerMode.js +8 -0
- package/src/core/createTracker.js +194 -0
- package/src/core/trackerStore.js +7 -0
- package/src/core/utils/DbHelper.js +32 -0
- package/src/core/utils/SlLog.js +9 -0
- package/src/core/utils/devices.js +437 -0
- package/src/core/utils/lib.js +8 -0
- package/src/core/utils/request.js +85 -0
- package/src/core/utils/uuid.js +6 -0
- package/src/index.js +4 -0
- package/src/react.js +5 -0
- package/src/vue.js +8 -0
- package/vite.config.js +38 -0
package/dist/es/vue.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { c as l } from "./createTracker.33fca2a1.js";
|
|
2
|
+
import { getCurrentInstance as U, inject as v, onBeforeMount as B, onMounted as k, onBeforeUpdate as _, onUpdated as A, onBeforeUnmount as M, onUnmounted as m, onActivated as f, onDeactivated as d } from "vue";
|
|
3
|
+
import { g as E } from "./trackerStore.2d9f9635.js";
|
|
4
|
+
import { useRoute as b } from "vue-router";
|
|
5
|
+
const p = Symbol("sl-tracker");
|
|
6
|
+
function y() {
|
|
7
|
+
return U() && v(p) || E();
|
|
8
|
+
}
|
|
9
|
+
function h(e) {
|
|
10
|
+
const o = l(e);
|
|
11
|
+
return o.install = (a) => {
|
|
12
|
+
a.provide(p, o), a.config.globalProperties.$tracker = o;
|
|
13
|
+
}, o;
|
|
14
|
+
}
|
|
15
|
+
function g() {
|
|
16
|
+
const e = y();
|
|
17
|
+
if (!e)
|
|
18
|
+
throw new Error("Tracker instance not found, please install tracker plugin first");
|
|
19
|
+
return {
|
|
20
|
+
trackEvent: (t, r) => {
|
|
21
|
+
e.trackEvent(t, r);
|
|
22
|
+
},
|
|
23
|
+
startTrackTime: (t) => {
|
|
24
|
+
e.startTrackTime(t);
|
|
25
|
+
},
|
|
26
|
+
pauseTrackTime: (t) => {
|
|
27
|
+
e.pauseTrackTime(t);
|
|
28
|
+
},
|
|
29
|
+
resumeTrackTime: (t) => {
|
|
30
|
+
e.resumeTrackTime(t);
|
|
31
|
+
},
|
|
32
|
+
endTrackTime: (t, r) => {
|
|
33
|
+
e.endTrackTime(t, r);
|
|
34
|
+
},
|
|
35
|
+
login: (t) => {
|
|
36
|
+
e.login(t);
|
|
37
|
+
},
|
|
38
|
+
logOut: () => {
|
|
39
|
+
e.logOut();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function w({
|
|
44
|
+
onBeforeMount: e,
|
|
45
|
+
onMounted: o,
|
|
46
|
+
onBeforeUpdate: a,
|
|
47
|
+
onUpdated: c,
|
|
48
|
+
onBeforeUnmount: i,
|
|
49
|
+
onUnmounted: u,
|
|
50
|
+
onActivated: s,
|
|
51
|
+
onDeactivated: T
|
|
52
|
+
}) {
|
|
53
|
+
const r = b().path, { trackEvent: n } = g();
|
|
54
|
+
e && B(() => {
|
|
55
|
+
n(r + "_onBeforeMount");
|
|
56
|
+
}), o && k(() => {
|
|
57
|
+
n(r + "_onMounted");
|
|
58
|
+
}), a && _(() => {
|
|
59
|
+
n(r + "_onBeforeUpdate");
|
|
60
|
+
}), c && A(() => {
|
|
61
|
+
n(r + "_onUpdated");
|
|
62
|
+
}), i && M(() => {
|
|
63
|
+
n(r + "_onBeforeUnmount");
|
|
64
|
+
}), u && m(() => {
|
|
65
|
+
n(r + "_onUnmounted");
|
|
66
|
+
}), s && f(() => {
|
|
67
|
+
n(r + "_onActivated");
|
|
68
|
+
}), T && d(() => {
|
|
69
|
+
n(r + "_onDeactivated");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function V(e, o) {
|
|
73
|
+
const { startTrackTime: a, endTrackTime: c, pauseTrackTime: i, resumeTrackTime: u } = g();
|
|
74
|
+
k(() => {
|
|
75
|
+
a(e);
|
|
76
|
+
}), f(() => {
|
|
77
|
+
u(e);
|
|
78
|
+
}), d(() => {
|
|
79
|
+
i(e);
|
|
80
|
+
}), m(() => {
|
|
81
|
+
c(e, o);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
h as createVueTracker,
|
|
86
|
+
y as getVueActiveTracker,
|
|
87
|
+
p as trackerSymbol,
|
|
88
|
+
V as usePageStay,
|
|
89
|
+
w as usePageTracker,
|
|
90
|
+
g as useTracker
|
|
91
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var W=Object.defineProperty;var N=(e,n,r)=>n in e?W(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var h=(e,n,r)=>(N(e,typeof n!="symbol"?n+"":n,r),r);const y=require("./trackerStore.32eb3aae.cjs"),S={DEBUG_ONLY:"DEBUG_ONLY",RELEASE:"RELEASE",DISABLE:"DISABLE",CONSOLE_LOG:"CONSOLE_LOG"},p={APP_START:"APP_START",APP_END:"APP_END",TRACK:"TRACK",TRACK_TIME:"TRACK_TIME"},$={RUN:"RUN",PAUSED:"PAUSED"};class U{constructor(n){h(this,"startTime");h(this,"endTime");h(this,"status");h(this,"pauseTime");h(this,"pauseDuration",0);this.startTime=n,this.status=$.RUN}pause(n){this.status===$.RUN&&(this.pauseTime=n,this.status=$.PAUSED)}resume(n){this.status===$.PAUSED&&(this.pauseDuration=this.pauseDuration+(this.pauseTime?n-this.pauseTime:0),this.status=$.RUN,this.pauseTime=void 0)}setEndTime(n){this.resume(n),this.endTime=n}duration(){return this.endTime?this.endTime-this.startTime-this.pauseDuration:-1}}const V=e=>({lib:"web-app",lib_version:"0.0.2",app_version:e}),F=async({url:e="",data:n={},header:r={},method:t="GET"})=>{if(t=t.toUpperCase(),t=="GET"){let i="";Object.keys(n).forEach(a=>{i+=a+"="+n[a]+"&"}),i!==""&&(i=i.slice(0,i.lastIndexOf("&")),e=e+"?"+i)}if(typeof window<"u"&&window.fetch){let i={method:t,headers:{Accept:"application/json","content-type":"application/json",...r},mode:"cors",cache:"force-cache"};t=="POST"&&Object.defineProperty(i,"body",{value:JSON.stringify(n)});try{return await(await fetch(e,i)).json()}catch(a){throw new Error(a)}}else{if(typeof window<"u")return new Promise((i,a)=>{let c;window.XMLHttpRequest?c=new XMLHttpRequest:c=new window.ActiveXObject,Object.keys(r||{}).forEach(u=>{c.setRequestHeader(u,r[u])}),t=="GET"?(c.open(t,e,!0),c.setRequestHeader("content-type","application/x-www-form-urlencoded"),c.send()):t=="POST"?(c.open(t,e,!0),c.setRequestHeader("content-type","application/json"),c.send(JSON.stringify(n))):a("error type"),c.onreadystatechange=()=>{if(c.readyState==4)if(c.status==200){let u=c.response;typeof u!="object"&&(u=JSON.parse(u)),i(u)}else a(c)}});throw new Error("Request client is not available in the current environment")}};var b;typeof window>"u"?b={navigator:{userAgent:""}}:b=window;const w=b.navigator,T=w.userAgent,v={browser:["Safari","Chrome","Edge","IE","Firefox","Firefox Focus","Chromium","Opera","Vivaldi","Yandex","Arora","Lunascape","QupZilla","Coc Coc","Kindle","Iceweasel","Konqueror","Iceape","SeaMonkey","Epiphany","360","360SE","360EE","UC","QQBrowser","QQ","Baidu","Maxthon","Sogou","LBBROWSER","2345Explorer","TheWorld","XiaoMi","Quark","Qiyu","Wechat","Taobao","Alipay","Weibo","Douban","Suning","iQiYi"],os:["Windows","Linux","Mac OS","Android","Ubuntu","FreeBSD","Debian","iOS","Windows Phone","BlackBerry","MeeGo","Symbian","Chrome OS","WebOS"],device:["Mobile","Tablet","iPad"]},d={getMatchMap:function(e){return{Safari:e.indexOf("Safari")>-1,Chrome:e.indexOf("Chrome")>-1||e.indexOf("CriOS")>-1,IE:e.indexOf("MSIE")>-1||e.indexOf("Trident")>-1,Edge:e.indexOf("Edge")>-1,Firefox:e.indexOf("Firefox")>-1||e.indexOf("FxiOS")>-1,"Firefox Focus":e.indexOf("Focus")>-1,Chromium:e.indexOf("Chromium")>-1,Opera:e.indexOf("Opera")>-1||e.indexOf("OPR")>-1,Vivaldi:e.indexOf("Vivaldi")>-1,Yandex:e.indexOf("YaBrowser")>-1,Arora:e.indexOf("Arora")>-1,Lunascape:e.indexOf("Lunascape")>-1,QupZilla:e.indexOf("QupZilla")>-1,"Coc Coc":e.indexOf("coc_coc_browser")>-1,Kindle:e.indexOf("Kindle")>-1||e.indexOf("Silk/")>-1,Iceweasel:e.indexOf("Iceweasel")>-1,Konqueror:e.indexOf("Konqueror")>-1,Iceape:e.indexOf("Iceape")>-1,SeaMonkey:e.indexOf("SeaMonkey")>-1,Epiphany:e.indexOf("Epiphany")>-1,360:e.indexOf("QihooBrowser")>-1||e.indexOf("QHBrowser")>-1,"360EE":e.indexOf("360EE")>-1,"360SE":e.indexOf("360SE")>-1,UC:e.indexOf("UC")>-1||e.indexOf(" UBrowser")>-1,QQBrowser:e.indexOf("QQBrowser")>-1,QQ:e.indexOf("QQ/")>-1,Baidu:e.indexOf("Baidu")>-1||e.indexOf("BIDUBrowser")>-1,Maxthon:e.indexOf("Maxthon")>-1,Sogou:e.indexOf("MetaSr")>-1||e.indexOf("Sogou")>-1,LBBROWSER:e.indexOf("LBBROWSER")>-1,"2345Explorer":e.indexOf("2345Explorer")>-1,TheWorld:e.indexOf("TheWorld")>-1,XiaoMi:e.indexOf("MiuiBrowser")>-1,Quark:e.indexOf("Quark")>-1,Qiyu:e.indexOf("Qiyu")>-1,Wechat:e.indexOf("MicroMessenger")>-1,Taobao:e.indexOf("AliApp(TB")>-1,Alipay:e.indexOf("AliApp(AP")>-1,Weibo:e.indexOf("Weibo")>-1,Douban:e.indexOf("com.douban.frodo")>-1,Suning:e.indexOf("SNEBUY-APP")>-1,iQiYi:e.indexOf("IqiyiApp")>-1,Windows:e.indexOf("Windows")>-1,Linux:e.indexOf("Linux")>-1||e.indexOf("X11")>-1,"Mac OS":e.indexOf("Macintosh")>-1,Android:e.indexOf("Android")>-1||e.indexOf("Adr")>-1,Ubuntu:e.indexOf("Ubuntu")>-1,FreeBSD:e.indexOf("FreeBSD")>-1,Debian:e.indexOf("Debian")>-1,"Windows Phone":e.indexOf("IEMobile")>-1||e.indexOf("Windows Phone")>-1,BlackBerry:e.indexOf("BlackBerry")>-1||e.indexOf("RIM")>-1,MeeGo:e.indexOf("MeeGo")>-1,Symbian:e.indexOf("Symbian")>-1,iOS:e.indexOf("like Mac OS X")>-1,"Chrome OS":e.indexOf("CrOS")>-1,WebOS:e.indexOf("hpwOS")>-1,Mobile:e.indexOf("Mobi")>-1||e.indexOf("iPh")>-1||e.indexOf("480")>-1,Tablet:e.indexOf("Tablet")>-1||e.indexOf("Nexus 7")>-1,iPad:e.indexOf("iPad")>-1}},matchInfoMap:function(e){var n=d.getMatchMap(T);for(var r in v)for(var t=0;t<v[r].length;t++){var i=v[r][t];n[i]&&(e[r]=i)}},getOS:function(){var e=this;return d.matchInfoMap(e),e.os},getOSVersion:function(){var e=this,n=T;e.osVersion="";var r={Windows:function(){var t=n.replace(/^.*Windows NT ([\d.]+);.*$/,"$1"),i={6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000"};return i[t]||t},Android:function(){return n.replace(/^.*Android ([\d.]+);.*$/,"$1")},iOS:function(){return n.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,".")},Debian:function(){return n.replace(/^.*Debian\/([\d.]+).*$/,"$1")},"Windows Phone":function(){return n.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2")},"Mac OS":function(){return n.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,".")},WebOS:function(){return n.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")}};return r[e.os]&&(e.osVersion=r[e.os](),e.osVersion==n&&(e.osVersion="")),e.osVersion},getDeviceType:function(){var e=this;return e.device="PC",d.matchInfoMap(e),e.device},getNetwork:function(){var e=w&&w.connection&&w.connection.effectiveType;return e||"\u672A\u77E5"},getBrowserInfo:function(){var e=this;d.matchInfoMap(e);var n=T,r=d.getMatchMap(n);r.Baidu&&r.Opera&&(r.Baidu=!1),r.Mobile&&(r.Mobile=!(n.indexOf("iPad")>-1));var t={Safari:function(){return n.replace(/^.*Version\/([\d.]+).*$/,"$1")},Chrome:function(){return n.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1")},IE:function(){return n.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1")},Edge:function(){return n.replace(/^.*Edge\/([\d.]+).*$/,"$1")},Firefox:function(){return n.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1")},"Firefox Focus":function(){return n.replace(/^.*Focus\/([\d.]+).*$/,"$1")},Chromium:function(){return n.replace(/^.*Chromium\/([\d.]+).*$/,"$1")},Opera:function(){return n.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1")},Vivaldi:function(){return n.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1")},Yandex:function(){return n.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1")},Arora:function(){return n.replace(/^.*Arora\/([\d.]+).*$/,"$1")},Lunascape:function(){return n.replace(/^.*Lunascape[/\s]([\d.]+).*$/,"$1")},QupZilla:function(){return n.replace(/^.*QupZilla[/\s]([\d.]+).*$/,"$1")},"Coc Coc":function(){return n.replace(/^.*coc_coc_browser\/([\d.]+).*$/,"$1")},Kindle:function(){return n.replace(/^.*Version\/([\d.]+).*$/,"$1")},Iceweasel:function(){return n.replace(/^.*Iceweasel\/([\d.]+).*$/,"$1")},Konqueror:function(){return n.replace(/^.*Konqueror\/([\d.]+).*$/,"$1")},Iceape:function(){return n.replace(/^.*Iceape\/([\d.]+).*$/,"$1")},SeaMonkey:function(){return n.replace(/^.*SeaMonkey\/([\d.]+).*$/,"$1")},Epiphany:function(){return n.replace(/^.*Epiphany\/([\d.]+).*$/,"$1")},360:function(){return n.replace(/^.*QihooBrowser\/([\d.]+).*$/,"$1")},"360SE":function(){var i={63:"10.0",55:"9.1",45:"8.1",42:"8.0",31:"7.0",21:"6.3"},a=n.replace(/^.*Chrome\/([\d]+).*$/,"$1");return i[a]||""},"360EE":function(){var i={69:"11.0",63:"9.5",55:"9.0",50:"8.7",30:"7.5"},a=n.replace(/^.*Chrome\/([\d]+).*$/,"$1");return i[a]||""},Maxthon:function(){return n.replace(/^.*Maxthon\/([\d.]+).*$/,"$1")},QQBrowser:function(){return n.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1")},QQ:function(){return n.replace(/^.*QQ\/([\d.]+).*$/,"$1")},Baidu:function(){return n.replace(/^.*BIDUBrowser[\s/]([\d.]+).*$/,"$1")},UC:function(){return n.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1")},Sogou:function(){return n.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1")},LBBROWSER:function(){var i={57:"6.5",49:"6.0",46:"5.9",42:"5.3",39:"5.2",34:"5.0",29:"4.5",21:"4.0"},a=n.replace(/^.*Chrome\/([\d]+).*$/,"$1");return i[a]||""},"2345Explorer":function(){return n.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1")},TheWorld:function(){return n.replace(/^.*TheWorld ([\d.]+).*$/,"$1")},XiaoMi:function(){return n.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1")},Quark:function(){return n.replace(/^.*Quark\/([\d.]+).*$/,"$1")},Qiyu:function(){return n.replace(/^.*Qiyu\/([\d.]+).*$/,"$1")},Wechat:function(){return n.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1")},Taobao:function(){return n.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1")},Alipay:function(){return n.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1")},Weibo:function(){return n.replace(/^.*weibo__([\d.]+).*$/,"$1")},Douban:function(){return n.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1")},Suning:function(){return n.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1")},iQiYi:function(){return n.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")}};return e.browserVersion="",t[e.browser]&&(e.browserVersion=t[e.browser](),e.browserVersion==n&&(e.browserVersion="")),e.browser+" "+e.browserVersion}};class K{constructor(n){this.device_id=n}valueOf(){return{device_id:this.device_id,os_version:d.getBrowserInfo(),model:d.getOS()+" "+d.getOSVersion()+" "+d.getDeviceType(),network_type:d.getNetwork()}}}const j=(e,...n)=>{var r;(r=y.getActiveTracker())!=null&&r.isDebug()&&console.log(e,...n)};function Y(e=16){if(e>21)return null;var n=new RegExp("(\\d{"+e+"})(\\.|$)"),r=(Array(e-1).join("0")+Math.pow(10,e)*Math.random()).match(n)[1];return r}const B="sl-tracker-point-data";function G(){let e=localStorage.getItem("sl-tracker-uuid");return e||(e=Y(),localStorage.setItem("sl-tracker-uuid",e)),e}function X(e){localStorage.setItem("sl-tracker-loginId",e)}function J(){return localStorage.getItem("sl-tracker-loginId")}function H(){localStorage.setItem("sl-tracker-loginId","")}function m(e){localStorage.setItem(B,JSON.stringify(e))}function Z(){var e;return(e=JSON.parse(localStorage.getItem(B)))!=null?e:[]}class z{constructor(n=[]){this._queue=[...n]}sort(){this._queue.sort((n,r)=>n.event.time-r.event.time)}push(n){this._queue.push(n),m(this._queue)}unshift(n){this._queue.unshift(...n),this.sort(),m(this._queue)}size(){return this._queue.length}empty(){return this.size()===0}tail(){if(!this.empty())return this._queue[this.size()-1]}head(){if(!this.empty())return this._queue[0]}all(){return[...this._queue]}clear(){this._queue.length=0}flush(){const n=this.all();return this.clear(),m(this._queue),n}stringify(){return JSON.stringify(this._queue)}}function ee(e){const n=V(e.appVersion),r=u(),t=new Map;let i=J();const a=new z(Z()),c=typeof window<"u"?window:{addEventListener:()=>{}};c.addEventListener("load",()=>{x(p.APP_START,p.APP_START,void 0,i)}),c.addEventListener("beforeunload",()=>{x(p.APP_END,p.APP_END,void 0,i)});function u(){return new K(G()).valueOf()}function M(){return e.trackerMode==S.DEBUG_ONLY}function I(o,s){x(o,p.TRACK,s,i)}function P(o){t.set(o,new U(Date.now()))}function D(o){const s=t.get(o);s&&s.pause(Date.now())}function k(o){const s=t.get(o);s&&s.resume(Date.now())}function C(o,s){const f=t.get(o);f&&(f.setEndTime(Date.now()),x(o,p.TRACK_TIME,s,i))}function Q(o){X(o),i=o}function L(){H(),i=void 0}function R(){g(!0)}function x(o,s,f,l){if(e.trackerMode==S.DISABLE)return;j({eventName:o,type:s,property:f,loginId:l});let O={name:o,type:s,time:Date.now()};if(s==p.TRACK_TIME&&t.get(o)){const _=t.get(o).duration();_!=-1&&(O.duration=_),t.delete(o)}let E={event:O,devices:r,lib:n};l&&l!=""&&(E.distinct_id=l),f&&(E.properties=f),a.push(E),g(!1)}function g(o=!1){if(a.empty()||a.size()<(e.reportThreshold||10)&&!M()&&!o)return;const s=a.flush();if(e.trackerMode==S.CONSOLE_LOG){console.log(s);return}q(JSON.stringify(s))}function q(o){var f;let s={url:e.serverUrl,method:"POST",header:{"content-type":"application/json",...e.headers||{}},data:{app_id:e.appId,data_list:o}};((f=e.requestInterceptors)==null?void 0:f.length)>0&&(s=e.requestInterceptors.reduce((l,O)=>O(l),s)),F(s).then(l=>{const{code:O}=l;O!==0&&a.unshift(JSON.parse(o))}).catch(()=>{a.unshift(JSON.parse(o))})}const A={trackEvent:I,startTrackTime:P,pauseTrackTime:D,resumeTrackTime:k,endTrackTime:C,login:Q,logOut:L,flush:R,isDebug:M};return y.setActiveTracker(A),A}exports.EventType=p;exports.TrackerMode=S;exports.createTracker=ee;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./createTracker.8d58679e.cjs"),r=require("./trackerStore.32eb3aae.cjs");exports.EventType=e.EventType;exports.TrackerMode=e.TrackerMode;exports.createTracker=e.createTracker;exports.getActiveTracker=r.getActiveTracker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("react"),o=require("./trackerStore.32eb3aae.cjs"),u=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},i=u(r),a=r.createContext(null);function s({tracker:e,children:t}){return i.default.createElement(a.Provider,{value:e},t)}function n(){const e=r.useContext(a)||o.getActiveTracker();if(!e)throw new Error("Tracker instance not found in context");return e}function f(e,t){const c=n();r.useEffect(()=>(c.startTrackTime(e),()=>c.endTrackTime(e,t)),[e,t,c])}exports.TrackerProvider=s;exports.useReactPageStay=f;exports.useReactTracker=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";let e;const c=t=>{e=t},r=()=>e;exports.getActiveTracker=r;exports.setActiveTracker=c;
|
package/dist/lib/vue.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./createTracker.8d58679e.cjs"),r=require("vue"),g=require("./trackerStore.32eb3aae.cjs"),v=require("vue-router"),T=Symbol("sl-tracker");function f(){return r.getCurrentInstance()&&r.inject(T)||g.getActiveTracker()}function p(e){const o=l.createTracker(e);return o.install=a=>{a.provide(T,o),a.config.globalProperties.$tracker=o},o}function k(){const e=f();if(!e)throw new Error("Tracker instance not found, please install tracker plugin first");return{trackEvent:(t,n)=>{e.trackEvent(t,n)},startTrackTime:t=>{e.startTrackTime(t)},pauseTrackTime:t=>{e.pauseTrackTime(t)},resumeTrackTime:t=>{e.resumeTrackTime(t)},endTrackTime:(t,n)=>{e.endTrackTime(t,n)},login:t=>{e.login(t)},logOut:()=>{e.logOut()}}}function _({onBeforeMount:e,onMounted:o,onBeforeUpdate:a,onUpdated:u,onBeforeUnmount:i,onUnmounted:s,onActivated:d,onDeactivated:m}){const n=v.useRoute().path,{trackEvent:c}=k();e&&r.onBeforeMount(()=>{c(n+"_onBeforeMount")}),o&&r.onMounted(()=>{c(n+"_onMounted")}),a&&r.onBeforeUpdate(()=>{c(n+"_onBeforeUpdate")}),u&&r.onUpdated(()=>{c(n+"_onUpdated")}),i&&r.onBeforeUnmount(()=>{c(n+"_onBeforeUnmount")}),s&&r.onUnmounted(()=>{c(n+"_onUnmounted")}),d&&r.onActivated(()=>{c(n+"_onActivated")}),m&&r.onDeactivated(()=>{c(n+"_onDeactivated")})}function S(e,o){const{startTrackTime:a,endTrackTime:u,pauseTrackTime:i,resumeTrackTime:s}=k();r.onMounted(()=>{a(e)}),r.onActivated(()=>{s(e)}),r.onDeactivated(()=>{i(e)}),r.onUnmounted(()=>{u(e,o)})}exports.createVueTracker=p;exports.getVueActiveTracker=f;exports.trackerSymbol=T;exports.usePageStay=S;exports.usePageTracker=_;exports.useTracker=k;
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@slan-health/tracker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/umd/index.js",
|
|
6
|
+
"module": "./dist/es/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/es/index.js",
|
|
10
|
+
"require": "./dist/lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./vue": {
|
|
13
|
+
"import": "./dist/es/vue.js",
|
|
14
|
+
"require": "./dist/lib/vue.js"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"import": "./dist/es/react.js",
|
|
18
|
+
"require": "./dist/lib/react.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
24
|
+
"build": "vite build"
|
|
25
|
+
},
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"dependencies": {},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^8.27.0",
|
|
31
|
+
"vite": "^3.2.0",
|
|
32
|
+
"@vitejs/plugin-vue": "^3.2.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"vue": "^3.2.41",
|
|
36
|
+
"vue-router": "^4.1.6",
|
|
37
|
+
"react": "^18.0.0",
|
|
38
|
+
"react-dom": "^18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"vue": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"vue-router": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"react": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"react-dom": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect } from "react";
|
|
2
|
+
import { getActiveTracker } from "../../core/trackerStore";
|
|
3
|
+
|
|
4
|
+
const TrackerContext = createContext(null);
|
|
5
|
+
|
|
6
|
+
export function TrackerProvider({ tracker, children }) {
|
|
7
|
+
return React.createElement(TrackerContext.Provider, { value: tracker }, children);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useTracker() {
|
|
11
|
+
const tracker = useContext(TrackerContext) || getActiveTracker();
|
|
12
|
+
if (!tracker) {
|
|
13
|
+
throw new Error("Tracker instance not found in context");
|
|
14
|
+
}
|
|
15
|
+
return tracker;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function usePageStay(eventName, property) {
|
|
19
|
+
const tracker = useTracker();
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
tracker.startTrackTime(eventName);
|
|
23
|
+
return () => tracker.endTrackTime(eventName, property);
|
|
24
|
+
}, [eventName, property, tracker]);
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createTracker as createCoreTracker } from "../../core/createTracker";
|
|
2
|
+
import { trackerSymbol } from "./rootStore";
|
|
3
|
+
|
|
4
|
+
export function createVueTracker(config) {
|
|
5
|
+
const tracker = createCoreTracker(config);
|
|
6
|
+
|
|
7
|
+
tracker.install = (app) => {
|
|
8
|
+
app.provide(trackerSymbol, tracker);
|
|
9
|
+
app.config.globalProperties.$tracker = tracker;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return tracker;
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { onMounted, onUnmounted, onActivated, onDeactivated } from "vue";
|
|
2
|
+
import useTracker from "./useTracker";
|
|
3
|
+
|
|
4
|
+
export default function usePageStay(eventName, property) {
|
|
5
|
+
const { startTrackTime, endTrackTime, pauseTrackTime, resumeTrackTime } =
|
|
6
|
+
useTracker();
|
|
7
|
+
|
|
8
|
+
onMounted(() => {
|
|
9
|
+
startTrackTime(eventName);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
onActivated(() => {
|
|
13
|
+
resumeTrackTime(eventName);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
onDeactivated(() => {
|
|
17
|
+
pauseTrackTime(eventName);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
onUnmounted(() => {
|
|
21
|
+
endTrackTime(eventName, property);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
onBeforeMount as _onBeforeMount,
|
|
3
|
+
onMounted as _onMounted,
|
|
4
|
+
onBeforeUpdate as _onBeforeUpdate,
|
|
5
|
+
onUpdated as _onUpdated,
|
|
6
|
+
onBeforeUnmount as _onBeforeUnmount,
|
|
7
|
+
onUnmounted as _onUnmounted,
|
|
8
|
+
onActivated as _onActivated,
|
|
9
|
+
onDeactivated as _onDeactivated,
|
|
10
|
+
} from "vue";
|
|
11
|
+
import { useRoute } from "vue-router";
|
|
12
|
+
import useTracker from "./useTracker";
|
|
13
|
+
export default function usePageTracker({
|
|
14
|
+
onBeforeMount,
|
|
15
|
+
onMounted,
|
|
16
|
+
onBeforeUpdate,
|
|
17
|
+
onUpdated,
|
|
18
|
+
onBeforeUnmount,
|
|
19
|
+
onUnmounted,
|
|
20
|
+
onActivated,
|
|
21
|
+
onDeactivated,
|
|
22
|
+
}) {
|
|
23
|
+
// const instance = Taro.getCurrentInstance();
|
|
24
|
+
const route = useRoute();
|
|
25
|
+
const page = route.path;
|
|
26
|
+
const { trackEvent } = useTracker();
|
|
27
|
+
if (onBeforeMount) {
|
|
28
|
+
_onBeforeMount(() => {
|
|
29
|
+
trackEvent(page + "_onBeforeMount");
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (onMounted) {
|
|
33
|
+
_onMounted(() => {
|
|
34
|
+
trackEvent(page + "_onMounted");
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (onBeforeUpdate) {
|
|
38
|
+
_onBeforeUpdate(() => {
|
|
39
|
+
trackEvent(page + "_onBeforeUpdate");
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (onUpdated) {
|
|
43
|
+
_onUpdated(() => {
|
|
44
|
+
trackEvent(page + "_onUpdated");
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (onBeforeUnmount) {
|
|
48
|
+
_onBeforeUnmount(() => {
|
|
49
|
+
trackEvent(page + "_onBeforeUnmount");
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (onUnmounted) {
|
|
53
|
+
_onUnmounted(() => {
|
|
54
|
+
trackEvent(page + "_onUnmounted");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (onActivated) {
|
|
58
|
+
_onActivated(() => {
|
|
59
|
+
trackEvent(page + "_onActivated");
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (onDeactivated) {
|
|
63
|
+
_onDeactivated(() => {
|
|
64
|
+
trackEvent(page + "_onDeactivated");
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getActiveTracker } from "../rootStore";
|
|
2
|
+
|
|
3
|
+
export default function useTracker() {
|
|
4
|
+
const tracker = getActiveTracker();
|
|
5
|
+
if (!tracker) {
|
|
6
|
+
throw new Error("Tracker instance not found, please install tracker plugin first");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const trackEvent = (eventName, property) => {
|
|
10
|
+
tracker.trackEvent(eventName, property);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const startTrackTime = (eventName) => {
|
|
14
|
+
tracker.startTrackTime(eventName);
|
|
15
|
+
};
|
|
16
|
+
const pauseTrackTime = (eventName) => {
|
|
17
|
+
tracker.pauseTrackTime(eventName);
|
|
18
|
+
};
|
|
19
|
+
const resumeTrackTime = (eventName) => {
|
|
20
|
+
tracker.resumeTrackTime(eventName);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const endTrackTime = (eventName, property) => {
|
|
24
|
+
tracker.endTrackTime(eventName, property);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const login = (loginId) => {
|
|
28
|
+
tracker.login(loginId);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const logOut = () => {
|
|
32
|
+
tracker.logOut();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
trackEvent,
|
|
37
|
+
startTrackTime,
|
|
38
|
+
pauseTrackTime,
|
|
39
|
+
resumeTrackTime,
|
|
40
|
+
endTrackTime,
|
|
41
|
+
login,
|
|
42
|
+
logOut,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createVueTracker } from "./createVueTracker";
|
|
2
|
+
export { trackerSymbol, getActiveTracker } from "./rootStore";
|
|
3
|
+
export { default as useTracker } from "./hooks/useTracker";
|
|
4
|
+
export { default as usePageTracker } from "./hooks/usePageTracker";
|
|
5
|
+
export { default as usePageStay } from "./hooks/usePageStay";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getCurrentInstance, inject } from "vue";
|
|
2
|
+
import { getActiveTracker as getCoreTracker } from "../../core/trackerStore";
|
|
3
|
+
|
|
4
|
+
export const trackerSymbol = Symbol("sl-tracker");
|
|
5
|
+
|
|
6
|
+
export function getActiveTracker() {
|
|
7
|
+
return (getCurrentInstance() && inject(trackerSymbol)) || getCoreTracker();
|
|
8
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const StatusName = {
|
|
2
|
+
RUN: "RUN",
|
|
3
|
+
PAUSED: "PAUSED",
|
|
4
|
+
};
|
|
5
|
+
class EventTimer {
|
|
6
|
+
startTime;
|
|
7
|
+
endTime;
|
|
8
|
+
status;
|
|
9
|
+
pauseTime;
|
|
10
|
+
pauseDuration = 0;
|
|
11
|
+
constructor(startTime) {
|
|
12
|
+
this.startTime = startTime;
|
|
13
|
+
this.status = StatusName.RUN;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
pause(time) {
|
|
17
|
+
if (this.status === StatusName.RUN) {
|
|
18
|
+
this.pauseTime = time;
|
|
19
|
+
this.status = StatusName.PAUSED;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
resume(time) {
|
|
24
|
+
if (this.status === StatusName.PAUSED) {
|
|
25
|
+
this.pauseDuration =
|
|
26
|
+
this.pauseDuration + (this.pauseTime ? time - this.pauseTime : 0);
|
|
27
|
+
this.status = StatusName.RUN;
|
|
28
|
+
this.pauseTime = undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setEndTime(endTime) {
|
|
32
|
+
this.resume(endTime);
|
|
33
|
+
this.endTime = endTime;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
duration() {
|
|
37
|
+
return this.endTime
|
|
38
|
+
? this.endTime - this.startTime - this.pauseDuration
|
|
39
|
+
: -1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default EventTimer;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { setPointDataList } from "./utils/DbHelper";
|
|
2
|
+
|
|
3
|
+
export class Queue {
|
|
4
|
+
constructor(init = []) {
|
|
5
|
+
this._queue = [...init];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
sort() {
|
|
9
|
+
this._queue.sort((a, b) => a.event.time - b.event.time);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
push(data) {
|
|
13
|
+
this._queue.push(data);
|
|
14
|
+
setPointDataList(this._queue);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
unshift(items) {
|
|
18
|
+
this._queue.unshift(...items);
|
|
19
|
+
this.sort();
|
|
20
|
+
setPointDataList(this._queue);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
size() {
|
|
24
|
+
return this._queue.length;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
empty() {
|
|
28
|
+
return this.size() === 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
tail() {
|
|
32
|
+
if (this.empty()) return undefined;
|
|
33
|
+
return this._queue[this.size() - 1];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
head() {
|
|
37
|
+
if (this.empty()) return undefined;
|
|
38
|
+
return this._queue[0];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
all() {
|
|
42
|
+
return [...this._queue];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clear() {
|
|
46
|
+
this._queue.length = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
flush() {
|
|
50
|
+
const all = this.all();
|
|
51
|
+
this.clear();
|
|
52
|
+
setPointDataList(this._queue);
|
|
53
|
+
return all;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
stringify() {
|
|
57
|
+
return JSON.stringify(this._queue);
|
|
58
|
+
}
|
|
59
|
+
}
|