0.0.31 • Published 3 years ago
@mayupai/ga-tracker v0.0.31
在小程序中使用谷歌统计4
1.安装
npm i @mayupai/ga-tracker 2.设置全局实例
const gaTracker = {
instance: null,
getInstance() {
if (!this.instance) {
this.instance = new ga.GoogleAnalytics().getTracker('G-XXXXXXXXXX') // 设置measurement id
this.instance.setTrackerServer(
'https://ga-proxy.example.com' // 设置转发服务器
)
}
return this.instance
}
}
Vue.prototype.$gaTracker = gaTracker3.发送页面事件
const tracker = this.$gaTracker.getInstance()
const event = new ga.PageViewEvent()
event.setParams({ page_title: '页面标题' })
tracker.send(event)4.发送自定义事件
const tracker = this.$gaTracker.getInstance()
const event = new ga.Event()
event.setName('信息提交')
event.setParams({ action: 'click', 'label': '用户' })
tracker.send(event)0.0.31
3 years ago
0.0.30
3 years ago
0.0.26
4 years ago
0.0.25
4 years ago
0.0.24
4 years ago
0.0.23
4 years ago
0.0.22
4 years ago
0.0.21
4 years ago
0.0.20
4 years ago
0.0.19
4 years ago
0.0.18
4 years ago
0.0.17
4 years ago
0.0.16
4 years ago
0.0.15
4 years ago
0.0.14
4 years ago
0.0.13
4 years ago
0.0.12
4 years ago
0.0.11
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago