@gctrack/vue 0.1.1 → 0.1.2

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/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import "node:module";
2
1
  //#region src/index.ts
3
2
  /**
4
3
  * GCTrack Vue 插件对象
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Tracker } from '@gctrack/core'\n\n/**\n * Vue 插件选项\n */\nexport interface VuePluginOptions {\n tracker: Tracker\n router?: any\n trackPageView?: boolean\n trackErrors?: boolean\n}\n\n/**\n * GCTrack Vue 插件对象\n */\nexport const GCTrackPlugin = {\n install(Vue: any, options: VuePluginOptions): void {\n const { tracker, router, trackPageView = true, trackErrors = true } = options\n\n // 将 tracker 挂载到 Vue 原型\n Vue.prototype.$tracker = tracker\n\n // 路由变化时追踪页面浏览\n if (router && trackPageView) {\n router.afterEach((to: any, from: any) => {\n tracker.track('page_view', {\n from: from.path,\n to: to.path,\n title: (to.meta && to.meta.title) || document.title,\n query: to.query,\n params: to.params,\n })\n })\n }\n\n // 全局错误处理\n if (trackErrors) {\n Vue.config.errorHandler = (err: Error, vm: any, info: string) => {\n console.error('Vue Error:', err)\n\n tracker.track('vue_error', {\n message: err.message,\n stack: err.stack,\n componentName: (vm && vm.$options && vm.$options.name) || 'Anonymous',\n info,\n timestamp: Date.now(),\n })\n }\n }\n\n // 注册全局指令\n registerDirectives(Vue, tracker)\n },\n}\n\n/**\n * 注册全局指令\n */\nfunction registerDirectives(Vue: any, tracker: Tracker) {\n // 点击埋点指令\n Vue.directive('track', {\n bind(el: HTMLElement, binding: any) {\n el.addEventListener('click', () => {\n const eventName = binding.value\n const eventData = binding.arg ? { [binding.arg]: binding.modifiers } : {}\n\n tracker.track(eventName, eventData)\n })\n },\n })\n\n // 曝光埋点指令\n Vue.directive('track-view', {\n bind(el: HTMLElement, binding: any) {\n if (typeof IntersectionObserver === 'undefined') {\n return\n }\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n const eventName = binding.value\n tracker.track(`${eventName}_view`, {\n element: el.tagName,\n })\n\n // 只上报一次\n observer.unobserve(el)\n }\n })\n })\n\n observer.observe(el)\n },\n })\n\n // 停留时长埋点指令\n Vue.directive('track-stay', {\n bind(el: HTMLElement, binding: any) {\n if (typeof IntersectionObserver === 'undefined') {\n return\n }\n\n const startTime = Date.now()\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n if (!entry.isIntersecting) {\n const stayTime = Date.now() - startTime\n const eventName = binding.value\n\n tracker.track(`${eventName}_stay`, {\n stayTime,\n })\n }\n })\n })\n\n observer.observe(el)\n },\n })\n}\n\n/**\n * Vue Mixin\n */\nexport const GCTrackMixin = {\n methods: {\n /**\n * 追踪事件\n */\n $track(eventType: string, data?: Record<string, any>): void {\n if (this.$tracker) {\n this.$tracker.track(eventType, data)\n }\n },\n\n /**\n * 追踪页面浏览\n */\n $trackPageView(data?: Record<string, any>): void {\n if (this.$tracker) {\n this.$tracker.track('page_view', data)\n }\n },\n },\n}\n\n/**\n * 类型声明\n */\ndeclare module 'vue/types/vue' {\n interface Vue {\n $tracker: Tracker\n $track: (eventType: string, data?: Record<string, any>) => void\n $trackPageView: (data?: Record<string, any>) => void\n }\n}\n"],"mappings":";;;;;AAeA,MAAa,gBAAgB,EAC3B,QAAQ,KAAU,SAAiC;CACjD,MAAM,EAAE,SAAS,QAAQ,gBAAgB,MAAM,cAAc,SAAS;CAGtE,IAAI,UAAU,WAAW;CAGzB,IAAI,UAAU,eACZ,OAAO,WAAW,IAAS,SAAc;EACvC,QAAQ,MAAM,aAAa;GACzB,MAAM,KAAK;GACX,IAAI,GAAG;GACP,OAAQ,GAAG,QAAQ,GAAG,KAAK,SAAU,SAAS;GAC9C,OAAO,GAAG;GACV,QAAQ,GAAG;GACZ,CAAC;GACF;CAIJ,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IAEvB,CAAC;;;;;AAMJ,MAAa,eAAe,EAC1B,SAAS;;;;CAIP,OAAO,WAAmB,MAAkC;EAC1D,IAAI,KAAK,UACP,KAAK,SAAS,MAAM,WAAW,KAAK;;;;;CAOxC,eAAe,MAAkC;EAC/C,IAAI,KAAK,UACP,KAAK,SAAS,MAAM,aAAa,KAAK;;CAG3C,EACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Tracker } from '@gctrack/core'\n\n/**\n * Vue 插件选项\n */\nexport interface VuePluginOptions {\n tracker: Tracker\n router?: any\n trackPageView?: boolean\n trackErrors?: boolean\n}\n\n/**\n * GCTrack Vue 插件对象\n */\nexport const GCTrackPlugin = {\n install(Vue: any, options: VuePluginOptions): void {\n const { tracker, router, trackPageView = true, trackErrors = true } = options\n\n // 将 tracker 挂载到 Vue 原型\n Vue.prototype.$tracker = tracker\n\n // 路由变化时追踪页面浏览\n if (router && trackPageView) {\n router.afterEach((to: any, from: any) => {\n tracker.track('page_view', {\n from: from.path,\n to: to.path,\n title: (to.meta && to.meta.title) || document.title,\n query: to.query,\n params: to.params,\n })\n })\n }\n\n // 全局错误处理\n if (trackErrors) {\n Vue.config.errorHandler = (err: Error, vm: any, info: string) => {\n console.error('Vue Error:', err)\n\n tracker.track('vue_error', {\n message: err.message,\n stack: err.stack,\n componentName: (vm && vm.$options && vm.$options.name) || 'Anonymous',\n info,\n timestamp: Date.now(),\n })\n }\n }\n\n // 注册全局指令\n registerDirectives(Vue, tracker)\n },\n}\n\n/**\n * 注册全局指令\n */\nfunction registerDirectives(Vue: any, tracker: Tracker) {\n // 点击埋点指令\n Vue.directive('track', {\n bind(el: HTMLElement, binding: any) {\n el.addEventListener('click', () => {\n const eventName = binding.value\n const eventData = binding.arg ? { [binding.arg]: binding.modifiers } : {}\n\n tracker.track(eventName, eventData)\n })\n },\n })\n\n // 曝光埋点指令\n Vue.directive('track-view', {\n bind(el: HTMLElement, binding: any) {\n if (typeof IntersectionObserver === 'undefined') {\n return\n }\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n const eventName = binding.value\n tracker.track(`${eventName}_view`, {\n element: el.tagName,\n })\n\n // 只上报一次\n observer.unobserve(el)\n }\n })\n })\n\n observer.observe(el)\n },\n })\n\n // 停留时长埋点指令\n Vue.directive('track-stay', {\n bind(el: HTMLElement, binding: any) {\n if (typeof IntersectionObserver === 'undefined') {\n return\n }\n\n const startTime = Date.now()\n\n const observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n if (!entry.isIntersecting) {\n const stayTime = Date.now() - startTime\n const eventName = binding.value\n\n tracker.track(`${eventName}_stay`, {\n stayTime,\n })\n }\n })\n })\n\n observer.observe(el)\n },\n })\n}\n\n/**\n * Vue Mixin\n */\nexport const GCTrackMixin = {\n methods: {\n /**\n * 追踪事件\n */\n $track(eventType: string, data?: Record<string, any>): void {\n if (this.$tracker) {\n this.$tracker.track(eventType, data)\n }\n },\n\n /**\n * 追踪页面浏览\n */\n $trackPageView(data?: Record<string, any>): void {\n if (this.$tracker) {\n this.$tracker.track('page_view', data)\n }\n },\n },\n}\n\n/**\n * 类型声明\n */\ndeclare module 'vue/types/vue' {\n interface Vue {\n $tracker: Tracker\n $track: (eventType: string, data?: Record<string, any>) => void\n $trackPageView: (data?: Record<string, any>) => void\n }\n}\n"],"mappings":";;;;AAeA,MAAa,gBAAgB,EAC3B,QAAQ,KAAU,SAAiC;CACjD,MAAM,EAAE,SAAS,QAAQ,gBAAgB,MAAM,cAAc,SAAS;CAGtE,IAAI,UAAU,WAAW;CAGzB,IAAI,UAAU,eACZ,OAAO,WAAW,IAAS,SAAc;EACvC,QAAQ,MAAM,aAAa;GACzB,MAAM,KAAK;GACX,IAAI,GAAG;GACP,OAAQ,GAAG,QAAQ,GAAG,KAAK,SAAU,SAAS;GAC9C,OAAO,GAAG;GACV,QAAQ,GAAG;GACZ,CAAC;GACF;CAIJ,IAAI,aACF,IAA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;;;AAMJ,MAAa,eAAe,EAC1B,SAAS;;;;CAIP,OAAO,WAAmB,MAAkC;EAC1D,IAAI,KAAK,UACP,KAAK,SAAS,MAAM,WAAW,KAAK;;;;;CAOxC,eAAe,MAAkC;EAC/C,IAAI,KAAK,UACP,KAAK,SAAS,MAAM,aAAa,KAAK;;CAG3C,EACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gctrack/vue",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Vue plugin for GCTrack",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "vue": "^2.6.0",
32
- "@gctrack/core": "0.1.1"
32
+ "@gctrack/core": "0.1.2"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsdown",