//js //*****************************************************************************/ // Crazy Egg tracking script generated for: // forward Homepage2 // http://www.forward.com //*****************************************************************************/ /*===========================*/ /*= LIB =*/ /*===========================*/ var isSafari = (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? true : false; /*hack to force Safari to function properly sans animation*/ function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { //if(document.all) { obj.style.zoom = 1; } /* God IE is so stupid. This forces hasLayout mode to the element to get the proper dimensions */ curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) { curleft += obj.x; } return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { //if(document.all) { obj.style.zoom = 1; } /* God IE is so stupid. This forces hasLayout mode to the element to get the proper dimensions */ curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; } return curtop; } //NOTE: This is re-written from the Prototype library, to not rely on //any other Prototype library methods or classes Function.prototype.bind = function() { var __method = this; var args = []; for (var i = 0; i < arguments.length; i++) args.push(arguments[i]); var object = args[0]; for (var i = 0; i < args.length - 1; i++) args[i] = args[i + 1]; args.length--; return function() { return __method.apply(object, args.concat(arguments)); } } Function.prototype.bindAsEventListener = function(object) { var __method = this; return function(event) { return __method.call(object, event || window.event); } } if (!window.Event) { var Event = new Object(); } Event.pointerX=function(event) { return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)); } Event.pointerY=function(event) { return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); } var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } function logAll(message) { if (typeof message != 'string') {message = typeof message}; if (window.console) {window.console.log(message);}; if (log) {log(message)}; if (document.all) {alert(message)}; }; //A very simple delay function function delay(millis) { date = new Date(); var curDate = null; do { var curDate = new Date(); } while(curDate-date < millis); } /*=========================================*/ /*= CRAZY EGG TRACKER =*/ /*=========================================*/ //Create the class var CrazyEggTracker=Class.create(); //The list of tags that we track CrazyEggTracker.tracked_tags=["a","input", "textarea", "select"]; //This will be set below upon window onload CrazyEggTracker.main=null; //Define the class CrazyEggTracker.prototype={ initialize: function(target) { var date = new Date(); this.start_time = date.getTime(); this.track(target); }, track: function(target) { this.target=target; //Get the base URL this.base_url=this.get_base_url(); this.names=new Array(); //First find all the tracked elements on the page this.get_tracked_items(); }, get_base_url: function() { //Get the base url this.base_url=""; try{ this.base_url=this.target.getElementsByTagName("base")[0].href; this.base_host=this.base_url.replace(/.*?:\/\/(.*?)[:\/].*/,"$1"); if ( !this.base_host.match(/:/) ) { this.base_host+=":"; } }catch(e) { this.base_url=this.target.location.href.replace(/(.*\/).*/, "$1"); this.base_host=this.target.location.hostname+":"+this.target.location.port; } this.base_host=this.base_host.replace(/^http.*?\:\/\//,""); this.base_host=this.base_host.replace(/^www\./,""); }, get_tracked_items: function() { //Initialize array this.tracked_items=new Array(); //Shorter reference to CrazyEggTracker.tracked_tags var tags=CrazyEggTracker.tracked_tags; //Loop through all the tags and get all the elements that are of the tag //we are searching for (eg "a", "img", "input", etc) for(var i=0;i 0 ) { //...in which case init with the image tag instead this.init_with_img_tag(images[0]); } }, init_with_img_tag: function(element) { }, init_with_input_tag: function(element) { //Set the src_for_id if ( !this.src_for_id) { if ( element.name ) { this.src_for_id=element.name; } } if ( element.type.toLowerCase() == "text" || element.type.toLowerCase() == "password") { this.do_delay=false; this.attach_to_event="focus"; } }, init_with_textarea_tag: function(element) { if ( !this.src_for_id) { if ( element.name ) { this.src_for_id=element.name; } } this.do_delay=false; this.attach_to_event="focus"; }, init_with_select_tag: function(element) { if ( !this.src_for_id) { if ( element.name ) { this.src_for_id=element.name; } } this.do_delay=false; this.attach_to_event="change"; }, create_id: function() { //Just create a simple counter-incremented id var id="CEID_"; if ( !this.src_for_id) this.src_for_id = ""; //This is to handle old cases, where we automatically assigned //the id when we downloaded the source. if ( this.element.id.match(/^CEID(.*?)\d+$/) ) { //Just the id to the src, since we already created it... id=this.element.id; } else { //Create a new id //Make it underscore form this.src_for_id = this.src_for_id.replace(" ", "_"); this.src_for_id = this.src_for_id.replace(/\W/g, '_').replace(/_+/g, '_'); //Remove a trailing _ this.src_for_id = this.src_for_id.replace(/\_$/, ''); id+=this.src_for_id; //Shorten multiple contiguous underscores id=id.replace(/_+/g, '_'); //Remove any trailing numbers ( eg "some_id1", "some_id22" becomes "some_id" ) id=id.replace(/\d+$/,""); //See if this ID already exists var existing_count=0; for ( var i=0; i0 ? (""+c) : "")+"]"; this.tracker.names[orig_text]+=1; if ( this.tracker.names[this.text] ) this.tracker.names[this.text]+=1; else this.tracker.names[this.text]=1; } else { this.tracker.names[this.text]=1; } }, create_action: function() { //Bind the elements attach_to_event to this.track if ( !this.listener ) { this.listener = this.track.bindAsEventListener(this) if (this.element.addEventListener) { this.element.addEventListener(this.attach_to_event, this.listener, false); } else if (this.element.attachEvent) { this.element.attachEvent('on' + this.attach_to_event, this.listener); } } }, disable_action: function() { if ( this.listener ) { if (this.element.removeEventListener) { this.element.removeEventListener(this.attach_to_event, this.listener, false); } else if (this.element.detachEvent) { this.element.detachEvent('on' + this.attach_to_event, this.listener); } this.listener = null; } }, track: function(event) { //Dynamically create a script tag with the URL of the tracking url //and append it to the document var script = this.tracker.target.createElement('script'); script.src = this.get_tracking_url(event); script.type = 'text/javascript' script.charset = 'utf-8' // Safari bug script = this.tracker.target.getElementsByTagName('head')[0].appendChild(script) if ( this.do_delay ) { //Wait just a few milliseconds to the let the request fire delay(1000); } }, get_tracking_url: function(event) { var parameters = ""; //Basics parameters += "?pid=399"; parameters += "&token=878FA94F98B5872B"; parameters += "&text=" + encodeURIComponent(this.text); parameters += "&element_id=" + encodeURIComponent(this.id); //Time-to-click var date = new Date(); var time_to_click = date.getTime() - this.tracker.start_time; parameters += "&time_to_click="+time_to_click; //Location of click if ( this.attach_to_event == "click") { try { var click_x = Event.pointerX(event); var click_y = Event.pointerY(event); if ( isSafari ) { //If the item is an input element then the origin is actually in the lower-left corner //and we need to invert it if ( this.element.nodeName.toLowerCase() == "input") { //Find the bottom of the outside edge of the window (outerHeight+screenY) and then subtract //the screenY from that ( because it's an inverted origin ) click_y = (window.outerHeight+window.screenY)-event.screenY; } //Account for padding on the body click_y -= this.tracker.target.body.offsetTop; click_x -= this.tracker.target.body.offsetLeft; } //Find the relative positions only click_x -= findPosX(this.element); click_y -= findPosY(this.element); //Append to the params parameters += "&click_x="+click_x+"&click_y="+click_y; } catch(e) { //Ignore any errors that happened } } return "http://stage.crazyegg.com/track/new_method" + parameters; } } /*=============================*/ /*= SETUP =*/ /*=============================*/ var ce_tracker_old_onload=window.onload; window.onload=function() { if ( ce_tracker_old_onload ) ce_tracker_old_onload(); //Create the main CrazyEggTracker if ( !CrazyEggTracker.main ) { var target=document; CrazyEggTracker.main=new CrazyEggTracker(target); } }