javascript 基于jQuery的出站链接跟踪,包含新窗口的案例以及相同的窗口位置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 基于jQuery的出站链接跟踪,包含新窗口的案例以及相同的窗口位置相关的知识,希望对你有一定的参考价值。

/**
 * Outbound link tracking
 * 
 * This code largely based on examples from 
 * [Google Analytics Help](http://www.google.com/support/googleanalytics/bin/answer.py?answer=55527).
 */
jQuery(function($){
	$('a:not([href*="' + document.domain + '"])').click(function(event){
		// Just in case, be safe and don't do anything
		if (typeof _gat == 'undefined') {
			return;
		}
		
		// Stop our browser-based redirect, we'll do that in a minute
		event.preventDefault();
		
		var link = $(this);
		var href = link.attr('href');
		var noProtocol = href.replace(/http[s]?:\/\//, '');
		
		// Track the event
		_gat._getTrackerByName()._trackEvent('Outbound Links', noProtocol);

		// Opening in a new window?
		if (link.attr('target') == '_blank') {
			/* If we are opening a new window, go ahead and open it now
			instead of in a setTimeout callback, so that popup blockers
			don't block it. */
			window.open(href);
		}
		else {
			/* If we're opening in the same window, we need to delay 
			for a brief moment to ensure the _trackEvent has had time
			to fire */
			setTimeout('document.location = "' + href + '";', 100);
		}
	});
});

以上是关于javascript 基于jQuery的出站链接跟踪,包含新窗口的案例以及相同的窗口位置的主要内容,如果未能解决你的问题,请参考以下文章

使用GA和jQuery跟踪出站链接

javascript 使用Universal Analytics或Google Analytics for jQuery的出站/入站点击事件跟踪

javascript 如何跟踪出站链接

javascript Google Analytics出站链接跟踪

javascript Google Analytics可跟踪出站链接

javascript 跟踪Google Analytics中的下载和出站链接