user-interaction-tracker
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UserInteractionTracker={})}(this,(function(t){"use strict";var e=Object.defineProperty,o=(t,o,n)=>((t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n)(t,"symbol"!=typeof o?o+"":o,n);class n{constructor(t){o(this,"actions"),o(this,"uploadLog"),o(this,"enabled"),this.actions=new Map,this.uploadLog=t.uploadLog,this.enabled=void 0!==t.enabled&&t.enabled}startAction(t,e){if(!this.enabled)return;const o=Date.now();this.actions.has(t)||this.actions.set(t,{start:null,end:null,startOptions:null,endOptions:null});const n=this.actions.get(t);n.start=o,n.startOptions=e||null,this.actions.set(t,n),this.uploadStartAction(t)}endAction(t,e){if(!this.enabled)return;const o=Date.now(),n=this.actions.get(t);n?(n.end=o,n.endOptions=e||null,this.actions.set(t,n),null!==n.start?this.calculateAndUploadIfNeeded(t):this.uploadEndAction(t,n,e),this.actions.delete(t)):this.uploadEndAction(t,{start:null,end:o,startOptions:null,endOptions:null},e)}getPendingActions(t){if(!this.enabled)return;if(t){const e=this.actions.get(t);return e?{action:t,...e}:{}}const e=[];return this.actions.forEach((t,o)=>{e.push({action:o,...t})}),e}clearActions(t){this.enabled&&(t?t.forEach(t=>{this.actions.delete(t)}):this.actions.clear())}calculateAndUploadIfNeeded(t){const e=this.actions.get(t),{start:o,end:n}=e;if(o&&n){const s=n-o;this.safeUploadLog(t,"duration",{duration:s,...e})}}uploadStartAction(t){const e=this.actions.get(t);e&&this.safeUploadLog(t,"startAction",{duration:0,...e})}uploadEndAction(t,e={},o){let n={};o&&(n=s(o)?o:{data:o}),this.safeUploadLog(t,"endAction",{duration:0,...e,...n})}safeUploadLog(t,e,o){try{this.uploadLog(t,e,o)}catch(n){console.error(`Error UserInteractionTracker,action ${t}:`,n)}}}const s=t=>"[object Object]"===Object.prototype.toString.call(t),i={install(t,e){const o=new n(e),s=e.globalName||"$userTracker";t.config&&t.config.globalProperties?t.config.globalProperties[s]=o:t.prototype?t.prototype[s]=o:console.error("当前 Vue 版本不支持!")}};t.UserInteractionTracker=n,t.default=i,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UserInteractionTracker={})}(this,(function(t){"use strict";var e=Object.defineProperty,o=(t,o,n)=>((t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n)(t,"symbol"!=typeof o?o+"":o,n);class n{constructor(t){o(this,"actions"),o(this,"uploadLog"),o(this,"enabled"),this.actions=new Map,this.uploadLog=t.uploadLog,this.enabled=void 0!==t.enabled&&t.enabled}track(t,e){if(!this.enabled)return;const o={timestamp:Date.now(),action:t,options:e};this.safeUploadLog(t,"track",o)}startAction(t,e){if(!this.enabled)return;const o=Date.now();this.actions.has(t)||this.actions.set(t,{start:null,end:null,startOptions:null,endOptions:null});const n=this.actions.get(t);n.start=o,n.startOptions=e||null,this.actions.set(t,n),this.uploadStartAction(t)}endAction(t,e){if(!this.enabled)return;const o=Date.now(),n=this.actions.get(t);n?(n.end=o,n.endOptions=e||null,this.actions.set(t,n),null!==n.start?this.calculateAndUploadIfNeeded(t):this.uploadEndAction(t,n,e),this.actions.delete(t)):this.uploadEndAction(t,{start:null,end:o,startOptions:null,endOptions:null},e)}getPendingActions(t){if(!this.enabled)return;if(t){const e=this.actions.get(t);return e?{action:t,...e}:{}}const e=[];return this.actions.forEach((t,o)=>{e.push({action:o,...t})}),e}clearActions(t){this.enabled&&(t?t.forEach(t=>{this.actions.delete(t)}):this.actions.clear())}calculateAndUploadIfNeeded(t){const e=this.actions.get(t),{start:o,end:n}=e;if(o&&n){const s=n-o;this.safeUploadLog(t,"duration",{duration:s,...e})}}uploadStartAction(t){const e=this.actions.get(t);e&&this.safeUploadLog(t,"startAction",{duration:0,...e})}uploadEndAction(t,e={},o){let n={};o&&(n=s(o)?o:{data:o}),this.safeUploadLog(t,"endAction",{duration:0,...e,...n})}safeUploadLog(t,e,o){try{this.uploadLog(t,e,o)}catch(n){console.error(`Error UserInteractionTracker,action ${t}:`,n)}}}const s=t=>"[object Object]"===Object.prototype.toString.call(t),i={install(t,e){const o=new n(e),s=e.globalName||"$userTracker";t.config&&t.config.globalProperties?t.config.globalProperties[s]=o:t.prototype?t.prototype[s]=o:console.error("当前 Vue 版本不支持!")}};t.UserInteractionTracker=n,t.default=i,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); |
@@ -1,2 +0,2 @@ | ||
type UploadLogFunction = (action: string, type: 'duration' | 'endAction' | 'startAction', data?: { | ||
type UploadLogFunction = (action: string, type: 'duration' | 'endAction' | 'startAction' | 'track', data?: { | ||
duration: number; | ||
@@ -17,2 +17,3 @@ start: number | null; | ||
constructor(options: TrackerOptions); | ||
track(action: string, options?: any): void; | ||
startAction(action: string, options?: any): void; | ||
@@ -19,0 +20,0 @@ endAction(action: string, options?: any): void; |
{ | ||
"name": "user-interaction-tracker", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "用户交互跟踪器 duration", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.umd.js", |
@@ -111,2 +111,3 @@ # User Interaction Tracker | ||
| `clearActions(actions?: string[]): void` | 清除指定的操作记录。如果不传递参数,清除所有操作记录。 | `actions` (可选, 数组): 要清除的操作名称数组 | 无 | | ||
| `track(action: string, options?: any) ` | 交互埋点 | `action` (字符串): 操作名称<br>`options` (可选, any): 额外信息 | 无 | | ||
@@ -119,3 +120,3 @@ | ||
action: string, | ||
type: 'duration' | 'endAction' | 'startAction', | ||
type: 'duration' | 'endAction' | 'startAction' | 'track', | ||
data?: { | ||
@@ -122,0 +123,0 @@ duration: number, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14762
204
138