(function() { var TrackExternal = new Class({ ie: false, event: {}, initialize: function() { document.addEvents({ mousedown: function(e) { this.event.down = e; }.bind(this), mouseup: function(e) { this.event.up = e; var target = this.getTarget(); var rel = target.getProperty('rel'); if(target && target.getTag() == 'a' && target.getProperty('target') == '_blank') { var ev = new AnalyticsEvent({ category: this.getLinkType(), action: this.getLinkLabel(), label: this.getLinkUri(), value: this.getValue() }); ev.track(); } }.bind(this) }); this.ie = this.getIEVersion(); }, getButton: function() { if(this.event.up.button === this.event.down.button) { e = this.event.up; if(this.ie !== false && this.ie < 9) { if(e.button === 1) { return 'left'; } else if(e.button === 4) { return 'middle'; } else if(e.button === 2) { return 'right'; } } else { if(e.button === 0) { return 'left'; } else if(e.button === 1) { return 'middle'; } else if(e.button === 2) { return 'right'; } } } return false; }, getIEVersion: function() { var match = /MSIE (\d)/.exec(navigator.appVersion); if(match && match.length == 2) { return Number(match[1]); } else { return false; } }, getLinkType: function() { var target = this.getTarget(); if(target) { var type = target.getProperty('data-type'); if(type) { return type; } } if(window.location.pathname.match(/\/companies\//)) { return 'Company Profile'; } else if(window.location.pathname.match(/\/product\//)) { return 'Product Snapshot'; } else if(target.hasClass('gs-title')) { return 'Custom Search'; } else { return 'Outbound Links'; } }, getLinkLabel: function() { var label = ''; if(typeof QueryString != 'undefined') { var qs = new QueryString(); label = qs.get('query'); } if(!label) { return document.title.split(' |', 1)[0]; } else { return label; } }, getLinkUri: function() { var target = this.getTarget(); if(target && target.getProperty('data-label')) { return target.getProperty('data-label'); } else if(target && target.getProperty('data-ctorig')) { return target.getProperty('data-ctorig'); } else if(target && target.getProperty('href')) { return target.getProperty('href'); } }, getTarget: function() { var target; if(typeof this.event.up.target !== 'undefined' && this.event.up.target === this.event.down.target ) { target = $(this.event.up.target); } else if(typeof this.event.up.srcElement !== 'undefined' && this.event.up.srcElement === this.event.down.srcElement ) { target = $(this.event.up.srcElement); } else { return false; } if(target.getTag() == 'img') { return target.getParent(); } else { return target; } }, getValue: function() { var button = this.getButton(); if(button == 'left' || button == 'middle') { return 1; } else { return 0; } } }); var AnalyticsEvent = new Class({ options: { category: 'Outbound Links', action: 'Category', label: '/', value: 0 }, initialize: function(options) { this.setOptions(options); }, track: function() { _gaq = _gaq || []; _gaq.push([ '_trackEvent', this.options.category, this.options.action, this.options.label, this.options.value ]); _gaq.push([ 'b._trackEvent', this.options.category, this.options.action, this.options.label, this.options.value ]); } }); AnalyticsEvent.implement(new Options); window.addEvent('domready', function(e) { new TrackExternal(); }); })();