谷歌分析出站链接事件跟踪 [英] Google Analytics Outbound Link Event Tracking

查看:19
本文介绍了谷歌分析出站链接事件跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置事件跟踪,以便在有人访问我的关于"页面并点击指向我的 LinkedIn 个人资料的链接时进行跟踪.下面是我想要跟踪的链接.如您所见,我尝试添加一些代码来使跟踪正常工作……我使用了几种不同的技术,但到目前为止没有任何效果.

I'm trying to set up event tracking so that I can track when someone goes to my 'about' page and clicks on a link to my LinkedIn profile. Below is the link that I want tracked. As you can see, i tried to add some code to get tracking working...i went through a few different techniques, but nothing works so far.

这就是我现在所拥有的:

This is what I have now:

<a ga('send', 'event', 'outbound', 'click', 'linkedin'); href="http://www.linkedin.com/profile/view?id=110370894&amp;trk=nav_responsive_tab_profile_pic" target="_blank">LinkedIn Page</a>

我将继续阅读和插入,但感谢任何帮助.

I'm going to keep reading and plugging away, but any help is appreciated.

我有analytics.js.我还在标题部分实施了代码以提供延迟,以便跟踪有时间加载,正如此支持帖子所推荐的:
https://support.google.com/analytics/answer/1136920?hl=en

I have analytics.js in place. I also implemented code in the header section to give a delay so that the tracking will have time to load, as recommended by this support post:
https://support.google.com/analytics/answer/1136920?hl=en

另外,想知道这是如何工作的.一旦我得到正确的代码,它会自动显示在我的分析中吗?在事件下?或者还有什么我需要做的吗?

Also, wondering how this works. Once I get the code right, it will automatically show up in my analytics? under events? or is there something else I have to do?

抱歉,如果有人在其他地方回答了这个问题,我阅读了很多以前的帖子,但我觉得总是缺少一些信息,这让我无法做到这一点.

Sorry ahead of time if this is answered somewhere else, I read a bunch of previous posts but I feel like theres always some bit of info missing that's just keeping me from getting this right.

推荐答案

问题是浏览器在事件被正确记录之前重定向到新的 URL.

The problem is that the browser redirects to the new URL before the event has been properly recorded.

常用的方法有3种:

  1. :在重定向前插入一小段延迟.这是一种不可靠的方法,因为所需的延迟取决于网络的性能.在网速较慢的情况下,可能会因为浏览器过早切换到新网址而无法记录该事件.

  1. Bad: Insert a small delay before redirecting. This is an unreliable method because the delay required depends on the performance of the network. In a slow network, the event may not be recorded because the browser will switch to the new URL too soon.

更好:将 target="_blank" 添加到您的 元素.这将在新窗口中打开链接,并允许记录事件,因为旧窗口将保持打开状态.

Better: Add target="_blank" to your <a> element. This will open the link in a new window, and will allow the event to be logged because the old window will stay open.

最佳:ga() 方法允许在成功记录事件后立即运行回调函数.

Best: The ga() method allows a callback function to be run immediately after the event has been successfully recorded.

<script>
/**
* Function that tracks a click on an outbound link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that
* URL string as the event label.
*/
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
     function () {
     document.location = url;
     }
   });
}
</script>

用法:

<a href="http://www.example.com"
   onclick="trackOutboundLink('http://www.example.com'); return false;">
Check out example.com
</a>

以上代码复制自本页.

这篇关于谷歌分析出站链接事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆