0.0.31 • Published 2 years ago

@mayupai/ga-tracker v0.0.31

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

在小程序中使用谷歌统计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 = gaTracker

3.发送页面事件

 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

2 years ago

0.0.30

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago