Return to Snippet

Revision: 40688
at April 21, 2011 06:52 by rgsmith007


Updated Code
<script type="text/javascript">
  $(document).ready(function() {
	$('body a').filter(function() {
		var theHref = this;
 
		if (theHref.hostname && theHref.hostname !== location.hostname) {
			$(theHref).not(".noAutoLink").attr('target', '_blank').bind('click keypress', function(event) {
				var code = event.charCode || event.keyCode;
 
				if (!code || (code && code == 13)) {
                                        var fixedLink = this.href;
                                        var _gaq = _gaq || [];
                        
                                        fixedLink = fixedLink.replace(/https?:\/\/(.*)/, "$1");

                                        _gaq.push(['_trackEvent', 'Outbound', 'Click', fixedLink]);
				};
			});
		};
	});
  });
</script>

Revision: 40687
at February 5, 2011 03:17 by rgsmith007


Updated Code
<script type="text/javascript">
  $(document).ready(function() {
	$('body a').filter(function() {
		var theHref = this;
 
		if (theHref.hostname && theHref.hostname !== location.hostname) {
			$(theHref).not(".noAutoLink").attr('target', '_blank').bind('click keypress', function(event) {
				var code = event.charCode || event.keyCode;
 
				if (!code || (code && code == 13)) {
                                        var fixedLink = this.href;
                                        var _gaq = _gaq || [];
                        
                                        fixedLink = fixedLink.replace(/https?:\/\/(.*)/, "$1");

                                        _gaq.push(['_setAccount', 'UA-XXXXX-X']);
                                        _gaq.push(['_trackEvent', 'Outbound', 'Click', fixedLink]);
				};
			});
		};
	});
  });
</script>

Revision: 40686
at February 5, 2011 03:15 by rgsmith007


Initial Code
<script type="text/javascript">
  $(document).ready(function() {
	$('body a').filter(function() {
		var theHref = this;
 
		if (theHref.hostname && theHref.hostname !== location.hostname) {
			$(theHref).not(".noAutoLink").attr('target', '_blank').bind('click keypress', function(event) {
				var code = event.charCode || event.keyCode;
 
				if (!code || (code && code == 13)) {
                                        var fixedLink = this.href;
                                        var _gaq = _gaq || [];
                        
                                        fixedLink = fixedLink.replace(/https?:\/\/(.*)/, "$1");
                                        fixedLink = '/outgoing/' + fixedLink;

                                        _gaq.push(['_setAccount', 'UA-XXXXX-X']);
                                        _gaq.push(['_trackEvent', 'Outbound', 'Click', fixedLink]);
				};
			});
		};
	});
  });
</script>

Initial URL


Initial Description
This uses the Event Tracking system rather than a '/outbound'

Initial Title
Auto-tag Outbound Links for Google Analytics, Async Version, Event Variant

Initial Tags


Initial Language
jQuery