Track button click as goal in Google Analytics

51,759

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

<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>
Share:
51,759

Related videos on Youtube

Liu Kang
Author by

Liu Kang

Choose Your Destiny

Updated on July 24, 2020

Comments

  • Liu Kang
    Liu Kang almost 4 years

    I have a button on my website, clicking on this button reveals a phonenumber.

    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

    (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.

    So I added href="/show/phonenumber-middle" onclick="javascript:pageTracker._trackPageview (‘Phonenumber Middle’);" target="blank" to the button:

    <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:.

    Goal setup: Custom
    Goal type: Destination
    Destination; Equals to: /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.

    My guess is that something is wrong with the <button> but I have no clue.

    • nyuen
      nyuen almost 9 years
      Are you seeing anything in the real time reports when you click the button?
    • Liu Kang
      Liu Kang almost 9 years
      Yes, I am seeing myself, 1 active user.
    • nyuen
      nyuen almost 9 years
      If you can see events come through in RT, then you may just need to wait for the data to be processed, and this takes up to 24 hours.
    • Liu Kang
      Liu Kang almost 9 years
      There no events triggering in the Real Time report.
    • nyuen
      nyuen almost 9 years
      I'm assuming you clicked the button and checked, and that you are not filtering your own visits as well?
  • Akin Hwan
    Akin Hwan almost 5 years
    is it onclick="__gaTracker(... or onclick="ga(... like it says in the docs?
  • Mike
    Mike almost 5 years
    @AkinHwan for this specific case, it was __gaTracker(... because that's how it was loaded onto this specific site. For you, I would guess it is ga(...