I have 10 link buttons on my web page. Each button pertains to a unique city. Each link button has an id attribute containing the name of the city. Each link button contains an onclick event which is recorded/tracked in Google Analytics Event Tracking. However, I haven't figured out how to capture the location from the unique id attribute. See example code below.
In short, I want to dynamically capture the value of the id attribute of the tag as the Event Label in Google Analytics? FYI: In the code below, the Event Label is sending event.target.href
to GA. This is where I want to capture the id value.
Here's the code:
<a id=“location-city-example” onclick=“ga(‘send’, ‘event’, ‘button’, ‘click’, event.target.href);” href="/apply" class="btn btn-rj">apply now</a>
的ID
答案 0 :(得分:0)
onclick="ga('send', 'event', 'button', 'click', this.id);"
请注意,我会坚持使用“直接”引号而不是原始代码中的“智能”引号。后者有时会做有趣的事情。