使用JavaScript的PDF文件的Google Analytics(分析)GTAG事件跟踪
我正在尝试添加一个简单的解决方案,以将PDF文件的事件跟踪添加到Google Analytics(分析)。
我不知道,为什么没有跟踪这些事件。如果我手动添加:
<a href="/my-file.pdf" target="_blank" onclick="gtag('event', 'click', {'event_category' : 'PDF download','event_label' : 'label123'});">Download the PDF</a>
在链接中,它可以正常工作。
似乎
var path = $(this).attr('href');
引起了问题。
我在做什么错?
<script>
(function($){
$('a[href$=\'.pdf\']').click(function() {
var path = $(this).attr('href');
gtag('event', 'click', {'event_category' : 'PDF download','event_label' : path});
});
});
</script>
谢谢!
I'm trying to add a simple solution to add event tracking for PDF files to google analytics.
I can't figure out, why the events are not tracked. If I manual add:
<a href="/my-file.pdf" target="_blank" onclick="gtag('event', 'click', {'event_category' : 'PDF download','event_label' : 'label123'});">Download the PDF</a>
to a link, it works fine.
It seems
var path = $(this).attr('href');
causes the issue.
What am I doing wrong?
<script>
(function($){
$('a[href$=\'.pdf\']').click(function() {
var path = $(this).attr('href');
gtag('event', 'click', {'event_category' : 'PDF download','event_label' : path});
});
});
</script>
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论