if (document.URL.indexOf('portsidemitsubishi') !== -1) { Math.ClientId = 6499; } var AVurl = 'http://analytics.avanser.com/'; function loadScript(url,idname) { mySessAV = new Date(); nocache = mySessAV.getTime(); url = url+'&time='+nocache; newscript = document.createElement('script'); newscript.setAttribute('type', 'text/javascript'); newscript.setAttribute('src', url); newscript.setAttribute('id', idname); scriptblock = document.getElementById(idname); myHead = document.getElementsByTagName('head')[0]; if(scriptblock){ // reload/replace a script already loaded myHead.replaceChild(newscript,scriptblock); } else { // load a brand new script document.getElementsByTagName('head')[0].appendChild(newscript); } } // define getElementsByClassName if not defined [start] if (document.getElementsByClassName == undefined) { document.getElementsByClassName = function(className) { var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)"); var allElements = document.getElementsByTagName("*"); var results = []; var element; for (var i = 0; (element = allElements[i]) != null; i++) { var elementClass = element.className; if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass)) results.push(element); } return results; } } function __is_array(o) { if(o != null && typeof o == 'object') { return (typeof o.push == 'undefined') ? false : true; }else { return false; } } //define getElementsByClassName if not defined [start] // try counter var __getGoogleTry = 0; // raw umtz will be stored here var __rawUtmz = ""; // parsed campaign (once parsed) var __parsedCampaign = ""; /** * keep the session alive * @param logId */ function AvanserKeepAlive(logId) { loadScript(AVurl+'keepalive.php?logId='+logId,'AVscript2'); setTimeout(function() { AvanserKeepAlive(logId); }, 60000); } /** * Read from the cookies the specified cookie * * @param c_name cookie name * @param special lowercase the return if needed * @returns */ function AvanserGetCookie(c_name, special) { 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; var cookie_to_use = unescape(document.cookie.substring(c_start,c_end)); if (special) { return cookie_to_use.toLowerCase(); } return cookie_to_use; } } return ""; } /** * Main "replace" function * * @returns null|void */ function AvanserCore() { if (__getGoogleTry>20) return null; __rawUtmz = AvanserGetCookie('__utmz', true); if ( __rawUtmz=="") { __getGoogleTry++; if (__getGoogleTry>20) { __rawUtmz='error'; } setTimeout(function() { AvanserCore(); },200); // in millsec return null; } var myUtmz = encodeURIComponent(__rawUtmz); var myUtma = encodeURIComponent(AvanserGetCookie('__utma', true)); var myUtmb = encodeURIComponent(AvanserGetCookie('__utmb', true)); var myUtmc = encodeURIComponent(AvanserGetCookie('__utmc', true)); var myRealFer = encodeURIComponent(document.referrer); var calledURL = encodeURIComponent(document.URL); var trackCode = Math.trackingcode; if( __is_array(trackCode) ) trackCode = trackCode.join(); var myUrl = AVurl+'track.php?clientId='+Math.ClientId+'&trackingcode='+trackCode+'&utmz='+myUtmz+'&utma='+myUtma+'&utmb='+myUtmb+'&utmc='+myUtmc+'&real='+myRealFer+'&called='+calledURL ; loadScript(myUrl,'AvanserDynNum'); } /** * Click callback, exec the AvanserCore been sure that the cookie is arrived. * * @returns {Boolean} */ function AvanserReplaceCallback() { if ( typeof AvanserReplaceCallback == 'undefined' ) { setTimeout(function(){AvanserReplaceCallback(); }, 200); } else { AvanserCore(); } return false; } //campaign chooser [start] /** * Parse the campaign type from the google cookie * Once the cookie has been parsed is stored into the __rawUtmz variable. * The campaign type is also stored into __parsedCampaign variable. * * @returns null if the cookie is not yet available, * false if the maximum tries reached, * the campaign type otherwise */ function AvanserCampaignParser() { __rawUtmz = AvanserGetCookie('__utmz', true); if ( __rawUtmz=="") { __getGoogleTry++; if (__getGoogleTry>20) { __parsedCampaign = 'direct' return __parsedCampaign; } setTimeout(function() { AvanserCampaignParser(); },200); // in millsec return null; } // find the campaign type var arr = __rawUtmz.split('|'); try { for(var i = 0; i < arr.length ; i++) { if( arr[i].match(/utmcmd/g) ) { __parsedCampaign = arr[i].split('='); __parsedCampaign = __parsedCampaign[1]; if( __parsedCampaign.match(/none/g) ) __parsedCampaign = 'direct'; break; } } } catch(e) { __parsedCampaign = 'direct'; } return __parsedCampaign; } /** * Change the numbers in the page, based on the output of AV_parseCampaign() function. * Please note that the function will return null until the cookie is read or max tries are reached. * * @returns null if the cookie is not yet available, * false if the maximum tries reached, * the campaign type otherwise */ function AvanserChooseCampaign() { var campaign = AvanserCampaignParser(); if(campaign == null) return null; if(campaign == false) return false; // choose which one we have to display var ENABLECPC = false; var ENABLEORGANIC = false; var ENABLEDIRECT = false; switch(campaign) { case 'cpc': ENABLECPC = true; break; case 'organic': ENABLEORGANIC = true; break; default: ENABLEDIRECT = true; break; } // execute the script var cpcList = document.getElementsByClassName('avanser-cpc'); var organicList = document.getElementsByClassName('avanser-organic'); var directList = document.getElementsByClassName('avanser-direct'); for(i = 0; i< cpcList.length; i++) cpcList[i].style.display = ENABLECPC ? 'block' : 'none'; for(i = 0; i< organicList.length; i++) organicList[i].style.display = ENABLEORGANIC ? 'block' : 'none'; for(i = 0; i< directList.length; i++) directList[i].style.display = ENABLEDIRECT ? 'block' : 'none'; return campaign; } // campaign chooser [stop] // retro-compatibility [start] if( typeof AV_parseCampaign == 'undefined' ) { function AV_parseCampaign() { return AvanserCampaignParser(); } } if( typeof AV_chooseNumbers == 'undefined' ) { function AV_chooseNumbers() { return AvanserChooseCampaign(); } } if( typeof bbgetcookie == 'undefined' ) { function bbgetcookie(c_name, special) { return AvanserGetCookie(c_name, special); } } if( typeof keepAValive == 'undefined' ) { function keepAValive(logId) { return AvanserKeepAlive(logId); } } //retro-compatibility [stop] function AvanserEntryPoint() { if( typeof Math.autostart == 'undefined' || Math.autostart == true) { AvanserCore(); } if(typeof Math.campaignAutostart == 'boolean' && Math.campaignAutostart == true) { AvanserChooseCampaign(); } } /* * Function ends here */ if ( (typeof Math.autostart == 'undefined' || Math.autostart == true) || (typeof Math.campaignAutostart == 'boolean' && Math.campaignAutostart == true) ) { if( typeof window.addEventListener != 'undefined' ) { window.addEventListener( "load", AvanserEntryPoint , false ); } else if( typeof window.attachEvent != 'undefined' ) { window.attachEvent("onload", AvanserEntryPoint ); } else { window.onload = AvanserEntryPoint; } }