Javascript 在 Google Analytics 中将按钮点击作为目标进行跟踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31673991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Track button click as goal in Google Analytics
提问by Liu Kang
I have a button on my website, clicking on this button reveals a phonenumber.
我的网站上有一个按钮,点击这个按钮会显示一个电话号码。
HTML
HTML
<div class="call-wrapper-middle">
<button id="call-phone-middle"><i class="fa fa-phone"></i>Call us</button>
<div class="call-number-middle" style="display: block;"> <a href="tel:555" class="number">555</a></div>
</div>
Using the following jQuery
使用以下 jQuery
(function($) {
$("button#call-phone-middle").click(function() {
$(this).hide();
$("div.call-number-middle").show();
});
})(jQuery);
This works great. But I also wish to track the clicks on the button as a goal in Google Analytics.
这很好用。但我也希望在 Google Analytics 中跟踪按钮的点击次数作为目标。
So I added href="/show/phonenumber-middle" onclick="javascript:pageTracker._trackPageview (‘Phonenumber Middle');" target="blank"
to the button:
所以我添加href="/show/phonenumber-middle" onclick="javascript:pageTracker._trackPageview (‘Phonenumber Middle');" target="blank"
到按钮:
<div class="call-wrapper-middle">
<button href="/show/phonenumber-middle" onclick="javascript:pageTracker._trackPageview (‘Phonenumber Middle');" target="blank" id="call-phone-middle"><i class="fa fa-phone"></i>Call us</button>
<div class="call-number-middle" style="display: block;"> <a href="tel:555" class="number">555</a></div>
</div>
And added a goal in Google Analytics with the following settings:.
并使用以下设置在 Google Analytics 中添加了一个目标:
Goal setup: Custom
Goal type: Destination
Destination; Equals to: /show/phonenumber-middle
目标设置:Custom
目标类型:Destination
目的地;等于:/show/phonenumber-middle
Getting "This Goal would have a 0% conversion rate based on your data" and in the Real Time report there is no conversations.
获得“根据您的数据,此目标的转化率为 0%”,并且在实时报告中没有对话。
My guess is that something is wrong with the <button>
but I have no clue.
我的猜测是有些问题,<button>
但我不知道。
回答by Mike
I would use a Google Analytics eventfor this. Here is the documentation for a GA click event. Then in goals, you would set your goal type to event, and you can track it via the Category, Action, or Label attributes
我会为此使用 Google Analytics事件。这是 GA 单击事件的文档。然后在目标中,您将目标类型设置为事件,您可以通过类别、操作或标签属性对其进行跟踪
<div class="call-wrapper-middle">
<button href="/show/phonenumber-middle" onclick="__gaTracker('send', 'event', 'buttons', 'click', 'phone-number-middle');" target="blank" id="call-phone-middle" style="display: none;"><i class="fa fa-phone"></i>Call us</button>
<div class="call-number-middle" style="display: block;"> <a href="tel:555" class="number">555</a></div>
</div>