按钮上的Google Analytics事件跟踪

时间:2021-10-31 14:08:14

In my Django app, I have a button in a template for every doctor profile that shows the phone number when the button is clicked. I'd like to add Google Analytics event tracking to track how many times people click on the show phone number button for a particular doctor.

在我的Django应用程序中,我在每个医生配置文件的模板中都有一个按钮,用于显示单击按钮时的电话号码。我想添加Google Analytics事件跟踪,以跟踪用户点击特定医生的显示电话号码按钮的次数。

<input onclick="change()"  class="btn btn-primary phone" type="button" value="Show Phone Number" id="myButton1" />

      <script type="text/javascript">
      function change() 
{
    var elem = document.getElementById("myButton1");

    elem.value = "" + {{doctor.clinic.contact_no}};
}
      </script>

I found some documentation that talks about how to track links, but am not sure how to do it for a button.

我找到了一些文档,讨论如何跟踪链接,但我不知道如何为按钮执行此操作。

<a href=”/downloads/whitepapers/seo-is-great.pdf” onClick=”_gaq.push([‘_trackEvent’, ‘whitepaper’, ‘download’, ‘SEO is great’, 5, true]);” target=”_blank”>SEO Is Great Whitepaper</a>

1 个解决方案

#1


1  

Add the ga event tracking code to the change() function. You can include the doctor.clinic.contact_no as one of the parameters to the _trackEvent function, here it would show under "label".

将ga事件跟踪代码添加到change()函数。您可以将doctor.clinic.contact_no包含为_trackEvent函数的参数之一,此处它将显示在“label”下。

If you are using classic ga (i.e. have ga.js)

如果你使用经典ga(即有ga.js)

function change() 
{
var elem = document.getElementById("myButton1");
elem.value = "" + {{doctor.clinic.contact_no}};
_gaq.push(['_trackEvent', 'phone', 'show','{{doctor.clinic.contact_no}}',, false]);
}

With Universal analytics (analytics.js) it would be:

使用通用分析(analytics.js),它将是:

function change() 
{
var elem = document.getElementById("myButton1");
elem.value = "" + {{doctor.clinic.contact_no}};
ga('send', 'event', 'phone', 'show','{{doctor.clinic.contact_no}}');
}

Make sure you have the basic tracking code in place as well.

确保您也有基本的跟踪代码。

#1


1  

Add the ga event tracking code to the change() function. You can include the doctor.clinic.contact_no as one of the parameters to the _trackEvent function, here it would show under "label".

将ga事件跟踪代码添加到change()函数。您可以将doctor.clinic.contact_no包含为_trackEvent函数的参数之一,此处它将显示在“label”下。

If you are using classic ga (i.e. have ga.js)

如果你使用经典ga(即有ga.js)

function change() 
{
var elem = document.getElementById("myButton1");
elem.value = "" + {{doctor.clinic.contact_no}};
_gaq.push(['_trackEvent', 'phone', 'show','{{doctor.clinic.contact_no}}',, false]);
}

With Universal analytics (analytics.js) it would be:

使用通用分析(analytics.js),它将是:

function change() 
{
var elem = document.getElementById("myButton1");
elem.value = "" + {{doctor.clinic.contact_no}};
ga('send', 'event', 'phone', 'show','{{doctor.clinic.contact_no}}');
}

Make sure you have the basic tracking code in place as well.

确保您也有基本的跟踪代码。