// This will need to be called by EVERY page. Best to call this in a header file or someplace that is always loaded. // The first page will call this and fall straight thru since tracking_uid won't be set at that time. It will be called again by ConvTrackCreateUidCallback once uid is set. function ConvTrackPageHit() { ConvTrackAction("page_hit"); } // ConvTrackPageHit // This will need to be called by page(s) that complete a conversion. // valid action types are: (case-insensitive) // PAGE_HIT // CONTACT // SIGNUP // PURCHASE // CONTEXTUAL_AD_CLICK // REFERRAL // CLICK // CLICK2 // CLICK3 // DOWNLOAD function ConvTrackAction(sActionType) { if (tracking_uid == "") ConvTrackInit(); if (sActionType == null) sActionType = ""; if (tracking_uid != "" && sActionType != "") { // var img = new Image(); // img.src = "/include-mt/ajax-conv-tracking.asp" // + "?sectoken=" + encodeURIComponent('{76656CAC-9B12-4D26-9BAD-EF1183D06A46}') // + "&tracking_uid=" + encodeURIComponent(tracking_uid) // + "&site_name=www%2Etheworldracedev%2Ecom" // + "&op=action" // + "&action_title=" + encodeURIComponent(sActionType); var sParams = "tracking_uid=" + encodeURIComponent(tracking_uid); sParams += "&site_name=www%2Etheworldracedev%2Ecom"; sParams += "&op=action"; sParams += "&action_title=" + encodeURIComponent(sActionType); sParams += "&domain_name=theworldracedev%2Ecom"; ConvTrackAsyncCall(sParams); } } // ConvTrackAction // This can be called FIRST (before ConvTrackPageHit) to set the default page for a given website or folder. // If not set will be index.asp function ConvTrackSetDefaultPage(sPageName) { if (sPageName == null) sPageName = ""; conv_tracking_default_page = sPageName; } // ConvTrackSetDefaultPage // **************************************************** // // The functions below are NOT called directly // // **************************************************** var tracking_uid = ""; //var tracking_uid = ""; //if (tracking_uid != "" && tracking_uid.search(/^\d+$/) != -1) // make sure it is all numeric. // ConvTrackSetUID(tracking_uid); // Create/overwrite the cookie. //else // tracking_uid = ""; //alert("tracking_uid = " + tracking_uid + "\ncookies = " + document.cookie); //var tracking_uid = ""; var conv_tracking_default_page = "index.asp"; function ConvTrackInit() { //alert("tracking_uid: " + tracking_uid); //tracking_uid = ""; try { // Get the tracking number for first time. // If this throws an error then don't retry, just zero out the cookie. if (tracking_uid != "") { // ConvTrackPageHit(tracking_uid); //alert("tracking_uid: " + tracking_uid); } else { var http_referer = ""; var search_phrase = http_referer.match(/(\?|&)(q|p)=([^&]+)/i); search_phrase = (search_phrase == null) ? "" : search_phrase[3]; var sParams = "op=create"; sParams += "&entry_page=" + encodeURIComponent(window.location.pathname); sParams += "&ip_address=38%2E107%2E191%2E107"; sParams += "&default_page=" + encodeURIComponent(conv_tracking_default_page); sParams += "&ppc_source="; sParams += "&http_referer=" + encodeURIComponent(http_referer); sParams += "&search_phrase=" + encodeURIComponent(search_phrase); sParams += "&campaign="; sParams += "&site_name=www%2Etheworldracedev%2Ecom"; sParams += "&domain_name=theworldracedev%2Ecom"; //alert("params: " + sParams); //alert("url: " + "/include-mt/ajax-conv-tracking.asp?sectoken=" + encodeURIComponent('{76656CAC-9B12-4D26-9BAD-EF1183D06A46}')); ConvTrackAsyncCall(sParams, ConvTrackCreateUidCallback); // tracking_uid = Ajax("/include-mt/ajax-conv-tracking.asp", "op=create&page=" + encodeURIComponent(window.location.pathname)); // tracking_uid = tracking_uid.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); //alert("header2: " + tracking_uid); } } catch (e) { // tracking_uid = ""; // alert("create code exception: " + e.message); } } // ConvTrackInit function ConvTrackAsyncCall(params, callback) { if (params == null) params = ""; var xmlHttp = null; try { xmlHttp = new XMLHttpRequest(); } catch (e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHttp"); } catch (e2) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHttp"); } catch (e3) { xmlHttp = null; } } } if (xmlHttp != null) { try { if (callback != null) { xmlHttp.onreadystatechange = function() { //alert("readyState = " + xmlHttp.readyState + "\nstatus = " + xmlHttp.status); if (xmlHttp.readyState == 4 && xmlHttp.status == "200") { callback(xmlHttp.responseText); } } } // if (params != "") { xmlHttp.open("POST", "/include-mt/ajax-conv-tracking.asp?sectoken=" + encodeURIComponent('{76656CAC-9B12-4D26-9BAD-EF1183D06A46}'), true); // This is the default HTTP post type. xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // } // else { // xmlHttp.open("GET", "/include-mt/ajax-conv-tracking.asp?sectoken=" + encodeURIComponent('{76656CAC-9B12-4D26-9BAD-EF1183D06A46}'), true); // } // Make the call and wrap it up - if there was a callback defined it will get called soon enough. xmlHttp.send(params); } catch (e) { // eat it //alert("ConvTrackAsyncCall exception: " + e.message); } } // if xmlHttp defined } // ConvTrackAsyncCall function ConvTrackCreateUidCallback(sResponse) { //alert("callback data: [" + sResponse + "]"); // Trim it. tracking_uid = sResponse.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); //if (tracking_uid != "") // alert("after trim: [" + tracking_uid + "]"); if (tracking_uid != "") { ConvTrackSetUID(tracking_uid); // ConvTrackPageHit(tracking_uid, params, callback); } } // ConvTrackCreateUidCallback function ConvTrackDoLinkFixup() { //alert("no cookie"); // Do this AFTER any other page load functions - make sure we have a tracking ID if this is the first page. window.setTimeout('ConvTrackDoLinkFixupFinish();', 1000); } // ConvTrackDoLinkFixup function ConvTrackDoLinkFixupFinish() { var uid = ConvTrackGetUID(); // If the cookie hasn't been set yet no need to try to fix up anything. if (uid != "") { var arr = document.links; var theHostName; for (var i = 0; i < arr.length; i++) { theHostName = arr[i].hostname.toLowerCase(); if (1==0) { // Since this function can/will be called multiple times check we haven't already fixed up this link. if (arr[i].search.indexOf("tuid") == -1) arr[i].search += ((arr[i].search != "") ? "&" : "") + "tuid=" + uid; } // condition if } // for } // if } // ConvTrackDoLinkFixupFinish function ConvTrackGetUID() { if (tracking_uid != "") return tracking_uid; else { // var value = ""; var oArr = document.cookie.match(/tracking_uid=(\d+)(?:\D|$)/i); if (oArr != null) return oArr[1]; // 0th item is the full string, 1st item is the 1st grouping. else return ""; } /* var pos = document.cookie.indexOf("tracking_uid="); if (pos != -1) { var start = pos + "tracking_uid".length + 1; var end = document.cookie.indexOf(";", start); if (end == -1) end = document.cookie.length; value = document.cookie.substring(start, end); } return decodeURIComponent(value); */ } // ConvTrackGetUID function ConvTrackSetUID(uid) { //SetCookie("tracking_uid", uid, 0.5); var sCookie = "tracking_uid=" + encodeURIComponent(uid); var expires = 180 * 24 * 60 * 60 * 1000; // 180 days - we delete rows from Conv Tracking table after 180 days (SQL1 cleanup job), so will need to get a new cookie. var dtExpire = new Date(); dtExpire.setTime(dtExpire.getTime() + expires); sCookie += ";expires=" + dtExpire.toGMTString(); sCookie += ";path=/"; sCookie += ";domain=theworldracedev.com"; //alert("sCookie: [" + sCookie + "]"); document.cookie = sCookie; //alert("all cookies: [" + document.cookie + "]"); } // ConvTrackSetUID // **************************************************** // This will fixup external links with a tracking UID. // **************************************************** // In case there is a really long page load object go ahead and do a first pass now. window.setTimeout('ConvTrackDoLinkFixupFinish();', 1000); // Call it again after the page has fully loaded. if (typeof window.addEventListener != "undefined") window.addEventListener("load", ConvTrackDoLinkFixup, false ); else if (typeof window.attachEvent != "undefined") window.attachEvent("onload", ConvTrackDoLinkFixup); else { var fnOldOnload = window.onload; if (typeof fnOldOnload != "function") window.onload = ConvTrackDoLinkFixup; else { window.onload = function (e) { fnOldOnload(e); ConvTrackDoLinkFixup(); }; } }