简体   繁体   English

我在哪里可以在按钮上包含Google Analytics(分析)事件跟踪代码?

[英]Where can I include the Google Analytics event tracking code on a button?

The button code on the website goes like this: 网站上的按钮代码如下:

    <button class="book-button" id="callButton">PHONE NUMBER</button>

This button is available on many pages, with the same class and id. 具有相同类别和ID的许多页面上都可以使用此按钮。

I want to track the number of clicks on this button (irrespective of which page it is on), and I have set up an event in Google Analytics with the following parameters: 我想跟踪此按钮的点击次数(无论它在哪个页面上),并且我已经在Google Analytics(分析)中使用以下参数设置了一个事件:

Category= button;
Action= call;
Label= right-top;

I am new to this, and wanted to know where to put the event tracking code from Google in the button code. 我对此并不陌生,想知道将Google的事件跟踪代码放在按钮代码中的位置。

Thank you! 谢谢!

You could try something like this, as pointed to in the comments: 您可以尝试这样的方法,如注释中所指出:

<button class="book-button" id="callButton" onclick="ga('send', 'event', 'button', 'call', 'right-top');">PHONE NUMBER</button>

but this would be specific to the "top right" button only. 但这仅适用于“右上”按钮。 I think that if your site isn't terribly complex at the moment (and assuming you aren't using GTM), you could migrate to GTM and track that button and other user engagement points, which would free you from using inline code. 我认为,如果您的网站目前还不是很复杂(并假设您未使用GTM),则可以迁移到GTM并跟踪该按钮和其他用户参与点,这将使您不必使用内联代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM