mirror of
https://github.com/1621740748/vue-ba.git
synced 2025-04-05 03:05:08 +08:00
可以统计自定义事件
This commit is contained in:
parent
2c5e0d6a43
commit
89793e3550
@ -83,6 +83,8 @@ vue-ba 提供 track-event,track-pageview 两个指令,开发者可以直接
|
|||||||
|
|
||||||
可通过逗号分隔的字符串或对象字面量传递参数,以字符串传递时请注意参数顺序,可参考trackEvent API。
|
可通过逗号分隔的字符串或对象字面量传递参数,以字符串传递时请注意参数顺序,可参考trackEvent API。
|
||||||
|
|
||||||
|
统计自定义事件使用 v-track-event.someEvent.custom
|
||||||
|
|
||||||
#### 用法
|
#### 用法
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -92,6 +94,8 @@ vue-ba 提供 track-event,track-pageview 两个指令,开发者可以直接
|
|||||||
|
|
||||||
<input v-track-event.keypress="'category, action'"> // 统计keypress事件
|
<input v-track-event.keypress="'category, action'"> // 统计keypress事件
|
||||||
|
|
||||||
|
<input v-track-event.someEvent.custom="'category, action'"> // 统计someEvent事件,someEvent是自定义事件
|
||||||
|
|
||||||
<button v-track-event="'category, action, opt_label, opt_value'"><button> // 以字符串传递参数
|
<button v-track-event="'category, action, opt_label, opt_value'"><button> // 以字符串传递参数
|
||||||
|
|
||||||
<button v-track-event="{category:'event', action:'click'}"></button> // 以对象字面量传递参数
|
<button v-track-event="{category:'event', action:'click'}"></button> // 以对象字面量传递参数
|
||||||
@ -112,4 +116,4 @@ vue-ba 提供 track-event,track-pageview 两个指令,开发者可以直接
|
|||||||
<div v-track-pageview="'/tar'"></div> // 以字符串指定受访页面和来源
|
<div v-track-pageview="'/tar'"></div> // 以字符串指定受访页面和来源
|
||||||
|
|
||||||
<div v-track-pageview="{pageURL:'/zoo''}"></div> // 以对象字面量指定受访页面和来源
|
<div v-track-pageview="{pageURL:'/zoo''}"></div> // 以对象字面量指定受访页面和来源
|
||||||
```
|
```
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import ba from '../index'
|
import ba from '../index'
|
||||||
import { notChanged, isEmpty } from './utils'
|
import { notChanged, isEmpty } from './utils'
|
||||||
|
|
||||||
export default function (el, binding) {
|
export default function (el, binding, vnode) {
|
||||||
if (notChanged(binding) || isEmpty(binding)) {
|
if (notChanged(binding) || isEmpty(binding)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -26,7 +26,13 @@ export default function (el, binding) {
|
|||||||
|
|
||||||
if (!events.length) events.push('click') // default listen click
|
if (!events.length) events.push('click') // default listen click
|
||||||
|
|
||||||
events.forEach((event) => {
|
events.forEach((eventValue) => {
|
||||||
el.addEventListener(event, () => ba.trackEvent(...args), false)
|
const customTag = 'custom'
|
||||||
|
let [event, custom] = eventValue.split(':')
|
||||||
|
if (custom === customTag) {
|
||||||
|
vnode.componentInstance.$on(event, () => ba.trackEvent(...args), false)
|
||||||
|
} else {
|
||||||
|
el.addEventListener(event, () => ba.trackEvent(...args), false)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user