0.0.31 • Published 3 years ago

@mayupai/ga-tracker v0.0.31

Weekly downloads
-
License
ISC
Repository
github
Last release
3 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

3 years ago

0.0.30

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago