To copy what was discussed here , I want to update an existing plugin to help switch me to Google Analytics "Asynchronous Syntax", so onclick events can be applied to our outbound links for cross-domain tracking, as shown here:
<a href="http://example.com/test.html" onclick="_gaq.push(['_link', 'http://example.com/test.html']); return false;">click me</a>
This is my current implementation for tracking outbound links with jquery, which I hope can be modified to support Google Analytics "Asynchronous Syntax"
$(document).ready(function(){
$('a:not(.popupwindow)').filter(function() {
var theHref = this;
if (theHref.hostname && theHref.hostname !== location.hostname) {
$(theHref).not(".noAutoIcon").addClass("offSite");
$(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) {
var code=event.charCode || event.keyCode;
if (!code || (code && code == 13)) {
if(pageTracker){
var fixedLink = this.href;
fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
fixedLink = '/outgoing/' + fixedLink;
pageTracker._trackPageview(fixedLink);
};
};
});
};
});
});
When a user needs to click from example.comto mysite.com, and on both sites, my cookie information will be transmitted _link, and all this will be considered one visit.
Google Analytics:
try {
var pageTracker = _gat._getTracker("UA-111222333-1");
pageTracker._setDomainName(".example.com");
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
pageTracker._trackPageview();
} catch(err) {}
Google Analytics " "
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-111222333-1']);
_gaq.push(['_setXDomain', {
domainName: '.example.com',
include: /(firstsite.com|secondsite.com)/
}]);
_gaq.push(['_trackOutbound']);
_gaq.push(['_trackDownload']);
_gaq.push(['_trackMailTo']);
_gaq.push(['_trackError']);
_gaq.push(['_formAnalysis',{minFields: 3}]);
_gaq.push(['_setDayOfWeek']);
_gaq.push(['_trackPageview']);
CMS onclick , jquery, jquery .