Google Analytics - Outbound Link Tracking

About

Steps

Snippet

Based on the Capture outbound links documentation, this site capture all external link created with a anchor with this snippet.

jQuery(function () {
	jQuery('a.urlextern, a.interwiki').click(function () { // urlextern and interwiki are classes set for outbound link that we want to track
		var url = this.href;
		if(ga && ga.loaded){
			e.preventDefault();
			ga('send', 'event', 'outbound', 'click', url, {
				'transport': 'beacon',
				'hitCallback': function(){
                                // Doc: https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#hitcallback
                                if (target !== '_blank') {
                                document.location = url;
                                }
                            }
			});
		}
	});
});

Report

In google analytics, you can see them in the behavior section.

Example with the outbound links to amazon

_


Powered by ComboStrap