在Google Analytics分析事件标签中捕获已点击的链接网址

时间:2023-02-07 19:17:14

Does anybody know why the value for event label is not getting passed through? I am trying to capture the click url in the event label.

有人知道为什么事件标签的价值没有通过吗?我正在尝试捕获事件标签中的单击URL。

Here is my code.

这是我的代码。

var url = $(this).attr('href');
$('.s-button').click(function() {
    ga('send', 'event', 'myevent', 'PDF', url);
});

});

1 个解决方案

#1


0  

You should do it like this :

你应该这样做:

$('.s-button').click(function() {
    var url = $(this).attr('href');
    ga('send', 'event', 'myevent', 'PDF', url);
});

The way you do it, the $(this) is not referring to the button, but to something bigger, with no href attributes.

你这样做的方式,$(this)不是指按钮,而是指更大的东西,没有href属性。

#1


0  

You should do it like this :

你应该这样做:

$('.s-button').click(function() {
    var url = $(this).attr('href');
    ga('send', 'event', 'myevent', 'PDF', url);
});

The way you do it, the $(this) is not referring to the button, but to something bigger, with no href attributes.

你这样做的方式,$(this)不是指按钮,而是指更大的东西,没有href属性。