/*############################################################################ # Document: Phone Tracking Script # # Originally Developed: 8/27/10 # # By: Sean Gallagher # # # # Company: Gallagher Website Design # # Web: http://www.GallagherWebsiteDesign.com # # Email: webmaster@gallagherwebsitedesign.com # # # # Proprietary Software - Legal Note # # # # This entire document was created by Sean Gallagher and Gallagher Website # # Design. The creator maintains all rights of ownership of this document and # # it's contents in part or whole. # # # # Only those who have been granted rights of use through an authorized # # license, which is granted by the script creator, my use this document in # # part or whole. All licenses are good for only one website domain unless # # otherwise granted by the script creator. Unauthorized use of this script # # is subject to legal repercussions. # # # # Copyright 2012. Gallagher Website Design. All Rights Reserved. # ############################################################################*/ /////////////////////// // DEFINE VARIABLES // ////////////////////// var phoneReplace = '1-415-370-8756'; // phone number to replace var phoneDirect = ''; // Direct/refer phone number var phoneSEO = '415-749-9218'; // SEO phone number var phonePPC = ''; // PPC phone number var phoneImgOnly = false; // Set to true for only swapping out images (no text numbers are changed) ///////////////////////////////// // START CALL TRACKING SCRIPT // //////////////////////////////// var ct_run = 1; addErrorEvent(phoneDyn); var startCallTracking = new ct_domFunc(phoneDyn); ///////////////////////// // ADD ON ERROR EVENT // //////////////////////// function addErrorEvent(func) { var oldOnError = window.onerror; if(typeof window.onerror != 'function') { window.onerror = func; } else { window.onerror = function() { oldOnError(); func(); } } } ///////////////////////////////// // REPLACE ALL FOR STRING OBJ // //////////////////////////////// String.prototype.ReplaceAll = function(stringToFind,stringToReplace) { var temp = this; var index = temp.indexOf(stringToFind); while(index!=-1) { temp = temp.replace(stringToFind,stringToReplace); index = temp.indexOf(stringToFind); } return temp; } ///////////////////////////////// // GET IMG WITH REL ATTRIBUTE // //////////////////////////////// function getImgByRel(rel) { var imgs = document.getElementsByTagName("img"); var e = []; for(i=0;i1) { return; } window.ct_run++; ////////////////////////// // CHECK VISITOR REFER // ///////////////////////// // Checks where visitor came from: PPC or SEO var refer = getRefer(); ////////////////////////// // GET PHONE #s TO USE // //////////////////////// var phoneNum = window.phoneDirect; switch(refer) { case 'seo': phoneNum = window.phoneSEO; break; case 'ppc': phoneNum = window.phonePPC; break; } /* // Parse phone numbers from files phonePPC and phoneSEO var phoneNum = (refer=='seo') ? window.phoneSEO : window.phonePPC; if(!phoneNum) { return false; } // fail safe if no phone number */ //////////////////////////////// // REPLACE ALL TEXT PHONE #s // ////////////////////////////// // Replace all text phone numbers with PPC or SEO number // document.body.innerHTML = replacePhones(phoneNum,phoneReplace,document.body.innerHTML); if(!phoneImgOnly) { replacePhones(phoneNum,phoneReplace,document.body.innerHTML); } ///////////////////////////////// // REPLACE ALL IMAGE PHONE #s // //////////////////////////////// // Replace all image phone numbers with PPC or SEO number image by using: rel="seo[image_url.jpg],ppc[image_url.jpg]" var x,r,s,p; var imgs = getImgByRel(); for(x in imgs) { r = imgs[x].getAttribute('rel'); if(refer=='direct' && r.split('seo[').length==2) { s = r.split('seo['); s = s[1].split('],'); s = s[0]; imgs[x].src = s; } else if(refer=='seo' && r.split('seo[').length==2) { s = r.split('seo['); s = s[1].split('],'); s = s[0]; imgs[x].src = s; } else if(r.split('ppc[').length==2) { p = r.split('ppc['); p = p[1].split(']'); p = p[0]; imgs[x].src = p; } } ///////////////////////////////// // SHOW/HIDE ALL DIV PHONE #s // //////////////////////////////// // Hide divs not for the phone number and show divs for the phone number if(refer=='seo') { jQuery('.calltrackingSEO').css("display","block"); jQuery('.calltrackingPPC').css("display","none"); } else { jQuery('.calltrackingSEO').css("display","none"); jQuery('.calltrackingPPC').css("display","block"); } ////////////////////// // SET FORM VALUES // ///////////////////// if(refer=='seo') { jQuery('.referInput').val('SEO'); } else { jQuery('.referInput').val('PPC'); } } /////////////////// // GET REFERRER // ////////////////// function getRefer() { var source = 'direct'; if(_readCookie('__ct')) { source = _readCookie('__ct'); } else if (substr_count(window.location.search,'?gclid=')>0 || substr_count(window.location.search,'&gclid=')>0) { source = 'ppc'; } else if (document.referrer.substr(0,31)=='http://www.googleadservices.com' || document.referrer.substr(0,32)=='https://www.googleadservices.com' || document.referrer.substr(0,27)=='http://googleadservices.com' || document.referrer.substr(0,28)=='https://googleadservices.com') { var source = 'ppc'; } else if (document.referrer.substr(0,21)=='http://www.google.com' || document.referrer.substr(0,22)=='https://www.google.com' || document.referrer.substr(0,17)=='http://google.com' || document.referrer.substr(0,18)=='https://google.com') { var source = 'seo'; } else if(document.referrer=='' || !document.referrer) { var source = 'direct'; } var date = new Date(); date.setTime(date.getTime()+(1800000)); var expires = "; expires="+date.toGMTString(); document.cookie = "__ct="+source+expires+"; path=/"; return source; } ////////////////// // READ COOKIE // ///////////////// function _readCookie(c_name) { if(document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if(c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return null; } /////////////////// // SUBSTR COUNT // ////////////////// function substr_count(string,substring,start,length) { var c = 0; if(start) { string = string.substr(start); } if(length) { string = string.substr(0,length); } for (var i=0;i= 60) { //clear the timer clearInterval(t); } }, 250); }; /* * jQuery replaceText - v1.1 - 11/21/2009 * http://benalman.com/projects/jquery-replacetext-plugin/ * * Copyright (c) 2009 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/