Vuejs使用Google Analytics进行事件跟踪 [英] Vuejs Event tracking using Google analytics

查看:2994
本文介绍了Vuejs使用Google Analytics进行事件跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找按钮和链接上的谷歌分析事件。通常在jquery中,我会传递数据属性中的值并获取它们并调用所需的函数。我知道我不应该使用数据属性,所以我正在寻找这样做的最佳方式,可以有多个按钮执行不同的跟踪与不同的数据目的(属性)所以我需要通过数据的目的和数据用户添加到vue组件/函数中

 < button id =openmodaldata-purpose =contact form class =btn__primaryaria-label =帮助@ click =contactForm>联系表单< / button> 

在分析中

  ga('send',{
hitType:'event',
eventCategory:'button',
eventAction:'data-purpose',
eventLabel: '价值的按钮'
});


解决方案

我最终使用 vue-analytics 。从作者
很容易遵循文档

I am looking to track google analytics events on buttons and links. In jquery typically, I would pass values in data-attributes and fetch them and call required function. I understand I shouldn't be using data-attributes so I am looking out for the best way of doing this , there can be multiple buttons that performs different tracking with different data-purpose (attribute) So I will need to pass data-purpose and data-user to the vue component/function

<button id="openmodal"  data-purpose="contact form" class="btn__primary" aria-label="Help" @click="contactForm">Contact Form</button>
  <button id="openmodal"  data-purpose="Opt In" class="btn__primary" aria-label="Help" @click="optIn">Opt In</button>

In analytics

ga('send', {
  hitType: 'event',
  eventCategory: 'button',
  eventAction: 'data-purpose',
  eventLabel: 'VALUE OF BUTTON'
});

解决方案

I ended up using vue-analytics . There is Easy to follow documentation from the author

这篇关于Vuejs使用Google Analytics进行事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆