Tweet diff --git a/_includes/sqlstyle.guide.md b/_includes/sqlstyle.guide.md index 6ddae11..3eff628 100644 --- a/_includes/sqlstyle.guide.md +++ b/_includes/sqlstyle.guide.md @@ -1247,7 +1247,7 @@ ZEROFILL ZONE ``` -[simon]: https://www.simonholywell.com/ +[simon]: https://www.simonholywell.com/?utm_source=sqlstyle.guide&utm_medium=link&utm_campaign=md-document "SimonHolywell.com" [issue]: https://github.com/treffynnon/sqlstyle.guide/issues "SQL style guide issues on GitHub" diff --git a/scripts.js b/scripts.js index 3569d55..d1fc010 100644 --- a/scripts.js +++ b/scripts.js @@ -30,4 +30,56 @@ $(document).ready(function(){ window.location.hash = target; }); }); -}); \ No newline at end of file +}); + +// http://exisweb.net/link-tracking-universal-analytics +(function trackOutbounds() { + var hitCallbackHandler = function(url,win) { + if (win) { + window.open(url, win); + } else { + window.location.href = url; + } + }; + + var addEvent = function(el, eventName, handler) { + + if (el.addEventListener) { + el.addEventListener(eventName, handler); + } else { + el.attachEvent('on' + eventName, function(){ + handler.call(el); + }); + } + }; + + if (document.getElementsByTagName) { + var el = document.getElementsByTagName('a'); + var getDomain = document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]; + + // Look thru each a element + for (var i=0; i < el.length;i++) { + + // Extract it's href attribute + var href = (typeof(el[i].getAttribute('href')) == 'string' ) ? el[i].getAttribute('href') : ''; + + // Query the href for the top level domain (xxxxx.com) + var myDomain = href.match(getDomain); + + // If link is outbound and is not to this domain + if ((href.match(/^(https?:|\/\/)/i) && !myDomain) || href.match(/^mailto\:/i)) { + + // Add an event to click + addEvent(el[i],'click', function(e) { + var url = this.getAttribute('href'), win = (typeof(this.getAttribute('target')) == 'string') ? this.getAttribute('target') : ''; + // Log even to Analytics, once done, go to the link + ga('send', 'event', 'outbound', 'click', url, + {'hitCallback': hitCallbackHandler(url,win)}, + {'nonInteraction': 1} + ); + e.preventDefault(); + }); + } + } + } +})(); \ No newline at end of file