var CTracker = new Class({ options: { target: 'index.php?option=com_company&controller=tracker&format=raw', clickTask: 'click', impressTask: 'impress' }, event: {}, initialize: function(options) { this.setOptions(options); document.addEvents({ mousedown: function(e) { this.event.down = e; }.bind(this), mouseup: function(e) { this.event.up = e; var target = this.getTarget(); var button = this.getButton(); var rel = target.getProperty('rel'); if(button != 'right' && target && target.getTag() == 'a' && rel !== null && rel.match(/external/)) { var entryId = this.getEntryId(target); var isCP = target.getProperty('data-type') == 'Company Profile'; var isSearch = $$('body#com_solr').length !== 0; var tableName = isCP ? 'company' : (isSearch ? 'search' : 'feature'); var tag = ''; if(isSearch) { var match = document.location.search.match(/query=([^&]+)/i); if(match && match[1]) { tag = unescape(match[1].replace(/\+/g, ' ')); } } if(entryId) { this.trackEvent({ sobi2Id: entryId, link: target.getProperty('href'), requestUri: document.location.href, referrer: document.referrer, tableName: tableName, tableId: this.getTableId(), tag: tag }); } } }.bind(this) }); }, trackPageview: function(params) { return this.send(this.options.impressTask, params); }, trackEvent: function(params) { return this.send(this.options.clickTask, params); }, send: function(type, params) { var remote = new Ajax(this.options.target + '&task=' + type, { method: 'post' }); return remote.request(params); }, getTarget: function() { if(typeof this.event.up.target !== 'undefined' && this.event.up.target === this.event.down.target ) { return $(this.event.up.target); } else if(typeof this.event.up.srcElement !== 'undefined' && this.event.up.srcElement === this.event.down.srcElement ) { return $(this.event.up.srcElement); } else { return false; } }, 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; }, getTableId: function() { var url = window.location.href; var match = url.match(/(\d+)\.html$/i); var id = 0; if(match && match.length) { id = match[1]; } return id; }, getEntryId: function(a) { var p = a; var match; while(p.getParent && (p = p.getParent())) { var id = p.getProperty ? p.getProperty('id') : null; if(id !== null && (match = id.match(/item(\d+)/))) { return match[1]; } } return false; } }); CTracker.implement(new Options); var _ct = new CTracker();