跟踪按钮单击作为Google Analytics中的目标

时间:2022-01-13 15:21:36

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

目标设置:自定义目标类型:目的地目的地;等于:/ 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.

我的猜测是

1 个解决方案

#1


32  

I would use a Google Analytics event for 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>

#1


32  

I would use a Google Analytics event for 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>