使用JavaScript的PDF文件的Google Analytics(分析)GTAG事件跟踪

发布于 2025-02-08 10:00:06 字数 699 浏览 3 评论 0原文

我正在尝试添加一个简单的解决方案,以将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文