var Tracker = new function () { var srcId = 'tallyx_d4s6dhs7', sendCalled = false, type = 'sale', sales = [], trackParams = { refferer: replaceHttp(document.referrer), url: replaceHttp(window.location.href), campaignid: null } ; this.cleanTransactions = function () { sales = []; } function replaceHttp(text) { text = text.replace("http://", "H_"); text = text.replace("https://", "S_"); return encodeURIComponent(text); } function fixFloat(v) { if ((typeof v).toLowerCase() === 'string') { v = v.replace(',', '.'); } if (v === undefined) v = 0; if (isNaN(parseFloat(v))) v = 0; return parseFloat(v * 1); } function createSaleAction() { var saleObj = function () { var type = 'sale', total_cost = 0, fixed_cost = 0, order_id = 0, product_id = null, product_group = null, campaign_id = null, banner_id = null, level_id = null, level_name = null, partner_id = null, sub_ids = null, channel_id = null, coupon_id = null, custom_commission = null, currency = null, status = 'A', data_1 = null, data_2 = null, data_3 = null, data_4 = null, data_5 = null, have_basket = false, basket_items_id = '', basket_items = '' ; this.setType = function (v) { type = v; }; this.setBasketTracking = function (name) { have_basket = true; basket_items_id = name; } this.setTotalCost = function (v) { total_cost = fixFloat(v); }; this.setFixedCost = function (v) { fixed_cost = fixFloat(v); }; this.setOrderID = function (v) { order_id = v; }; this.setProductID = function (v) { product_id = v; }; this.setProductGroup = function (v) { product_group = v; }; this.setLevelID = function (c) { level_id = c; }; this.setLevelName = function (c) { level_name = c; }; this.setPartnerID = function (p) { partner_id = p; }; this.setSubIDs = function (c) { sub_ids = c; }; this.setChannelID = function (c) { channel_id = c; }; this.setBannerID = function (c) { banner_id = c; }; this.setCoupon = function (c) { coupon_id = c; }; this.setCustomCommission = function (cc) { custom_commission = fixFloat(cc); }; this.setCurrency = function (c) { currency = c; }; this.setStatus = function (s) { if (typeof s == 'string') s = s.toUpperCase(); if (s === 'A' || s === 'P' || s === 'D') status = s; }; this.setData1 = function (d) { data_1 = d; }; this.setData2 = function (d) { data_2 = d; }; this.setData3 = function (d) { data_3 = d; }; this.setData4 = function (d) { data_4 = d; }; this.setData5 = function (d) { data_5 = d; }; this.collectBasketItems = function () { var items_text = document.getElementById(basket_items_id).value; basket_items = Base64.encode(items_text); } this.collectParams = function () { if (have_basket) this.collectBasketItems(); var buff = { type: type, tc: total_cost, fc: fixed_cost, o: order_id, p: product_id, pd: product_group, c: campaign_id, b: banner_id, pa: partner_id, si: sub_ids, ch: channel_id, co: coupon_id, lv: level_id, ln: level_name, cu: currency, s: status, d1: data_1, d2: data_2, d3: data_3, d4: data_4, d5: data_5, bi: basket_items }, result = {}; for (var i in buff) { if (buff[i] !== null) { if (typeof buff[i] == 'string') { buff[i] = buff[i].replace(/'/g, '`'); buff[i] = buff[i].replace(/"/g, '`'); buff[i] = buff[i].replace(/&/g, 'and'); } result[i] = buff[i]; } } return result; } }, obj; obj = new saleObj(); sales.push(obj); return obj; } this.createSale = function (textarea_id) { sale = createSaleAction(); //alternative way getting params from textarea if (textarea_id != undefined) { text = document.getElementById(textarea_id).value; rows = text.split(/;/g); for (i in rows) { if (typeof rows[i] == "string") { row_data = rows[i].split(/=/g); if (typeof row_data[1] == "string") { row_data[1] = row_data[1].replace(/"/g, '`'); create_code = ('sale.set' + trim(row_data[0]) + '("' + trim(row_data[1]) + '");'); //console.log(create_code); eval(create_code); } } } } //end of alternative way getting params from textarea return sale; }; this.createLead = function () { var buff = createSaleAction(); buff.setType('lead'); return buff; }; this.createView = function () { var buff = createSaleAction(); buff.setType('view'); return buff; }; this.createClick = function () { var buff = createSaleAction(); buff.setType('click'); return buff; }; function collectTrackParams() { var path = '?'; for (var i in trackParams) { path += i + '=' + trackParams[i] + '&'; } path = path.substr(0, path.lastIndexOf('&')); return path; } function stringify(obj) { var t = typeof (obj); if (t != "object" || obj === null) { // simple data type if (t == "string") obj = '"' + obj + '"'; return String(obj); } else { // recurse array or object var n, v, json = [], arr = (obj && obj.constructor == Array); for (n in obj) { v = obj[n]; t = typeof(v); if (t == "string") v = '"' + v + '"'; else if (t == "object" && v !== null) v = stringify(v); json.push((arr ? "" : '"' + n + '":') + String(v)); } return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); } } function getScriptsUrl() { var url = new String(document.getElementById(srcId).src); return url.substr(0, url.lastIndexOf('/') + 1); } this.register = function () { var parentEl = document.getElementById(srcId), saleData = '', sF = null; for (var i in sales) { if (typeof sales[i] === 'object') { sF = document.createElement('script'); sF.height = sF.width = sF.border = 0; sF.style.display = 'none'; if (typeof sales[i].collectParams === 'function') { saleData = stringify(sales[i].collectParams()); sF.src = getScriptsUrl() + 'sale.js.php' + collectTrackParams() + '&sales=' + saleData; parentEl.parentNode.insertBefore(sF, parentEl.nextSibling); } } } }; this.registerView = function () { var parentEl = document.getElementById(srcId), viewData = '', sF = null; for (var i in sales) { sF = document.createElement('iframe'); sF.height = sF.width = sF.border = 0; sF.style.display = 'none'; saleData = stringify(sales[i].collectParams()); sF.src = getScriptsUrl() + 'ea_view.php' + collectTrackParams() + '&views=' + saleData; parentEl.parentNode.insertBefore(sF, parentEl.nextSibling); } }; this.registerClick = function () { var parentEl = document.getElementById(srcId), viewData = '', sF = null; for (var i in sales) { sF = document.createElement('iframe'); sF.height = sF.width = sF.border = 0; sF.style.display = 'none'; saleData = stringify(sales[i].collectParams()); sF.src = getScriptsUrl() + 'ea_click.php' + collectTrackParams() + '&clicks=' + saleData; parentEl.parentNode.insertBefore(sF, parentEl.nextSibling); } }; this.setCampaignID = function (i) { trackParams.campaignid = i; }; function correctNullValue(value) { if (value.toLowerCase() === 'null' || value === '' || value === 'undefined') return null; else return value; } function tryLandingTrack() { var s = window.location.search, qparams, buff, i, code, go = false, trackstr = 'click.php?js&lscp&', fEl = document.createElement('iframe') ; if (typeof mlcid !== 'undefined') mlcid = correctNullValue(mlcid); if (typeof mlpid !== 'undefined') mlpid = correctNullValue(mlpid); if (typeof mlbid !== 'undefined') mlbid = correctNullValue(mlbid); if (typeof mlsubid !== 'undefined') mlsubid = correctNullValue(mlsubid); if (typeof mlsubid1 !== 'undefined') mlsubid1 = correctNullValue(mlsubid1); if (typeof mlsubid2 !== 'undefined') mlsubid2 = correctNullValue(mlsubid2); if (typeof mlsubid3 !== 'undefined') mlsubid3 = correctNullValue(mlsubid3); if (typeof mlsubid4 !== 'undefined') mlsubid4 = correctNullValue(mlsubid4); if (typeof mlcid !== 'undefined' && typeof mlpid !== 'undefined') if (mlpid === false && mlcid === false) if (s == '') return; //check for refferer if no publisher was defined if (typeof mlpid !== 'undefined') if (mlpid === false) { var url_ref = document.referrer.split('/')[2]; var url_my = window.location.hostname; if (document.referrer == '') return; if (url_ref === url_my) return; } s = s.split('?').length > 1 ? s.split('?')[1] : ''; qparams = s.split('&'); if (s.lastIndexOf('mlcode') > -1) {//tracking by hash-code for (i in qparams) { buff = qparams[i].split('='); if (buff[0] === 'mlcode') { code = buff[1]; break; } } go = true; trackstr += 'code=' + code; } else {//try parse params and probe tracking if (typeof mlcid !== 'undefined') { trackstr += 'cid=' + mlcid; //set pub=1 as default for Laserservice /* if(mlpid===null) trackstr += '&pid='+1; else trackstr += '&pid='+mlpid; */ if (mlpid !== null) trackstr += '&pid=' + mlpid; if (mlbid !== null) trackstr += '&lbid=' + mlbid; if (mlsubid !== null) trackstr += '&subid=' + mlsubid; if (mlsubid1 !== null) trackstr += '&subid1=' + mlsubid1; if (mlsubid2 !== null) trackstr += '&subid2=' + mlsubid2; if (mlsubid3 !== null) trackstr += '&subid3=' + mlsubid3; if (mlsubid4 !== null) trackstr += '&subid4=' + mlsubid4; go = true; } else { for (var i = 0; i < qparams.length; i++) { buff = qparams[i].split('='); if (buff[0] === 'mlpid') { mlpid = buff[1]; trackstr += '&pid=' + buff[1]; go = true; } if (buff[0] === 'mlbid') { trackstr += '&bid=' + buff[1]; go = true; } if (buff[0] === 'mlcid') { trackstr += '&cid=' + buff[1]; go = true; } if (buff[0] === 'mlsubid') { trackstr += '&subid=' + buff[1]; go = true; } if (buff[0] === 'mlsubid1') { trackstr += '&subid1=' + buff[1]; go = true; } if (buff[0] === 'mlsubid2') { trackstr += '&subid2=' + buff[1]; go = true; } if (buff[0] === 'mlsubid3') { trackstr += '&subid3=' + buff[1]; go = true; } if (buff[0] === 'mlsubid4') { trackstr += '&subid4=' + buff[1]; go = true; } } } trackstr += '&refferer=' + replaceHttp(document.referrer) } if (!go) return; //check for repeat landing tracking if (typeof mlpid === 'undefined') return; var today = new Date(); var expire = new Date(); expire.setTime(today.getTime() + 31536000); document.cookie = "TallyX_LT=" + mlpid + ";expires=" + expire.toGMTString() + "; path=/"; //check for repeat landing tracking fEl.style.display = 'none'; fEl.style.width = '0px'; fEl.style.height = '0px'; fEl.src = getScriptsUrl() + trackstr; var next = document.body.nextSibling; if (next) { document.body.insertBefore(fEl, next); } else { document.body.appendChild(fEl); } } this.catchError = function (err) { var parentEl = document.getElementById(srcId), saleData = '', sF = null; sM = document.createElement('iframe'); sM.height = sM.width = sM.border = 0; sM.style.display = 'none'; sM.src = getScriptsUrl() + 'error_catch.php' + '?script=track.js.php&name=' + err.name + '&message=' + err.message + '&browser=' + navigator.appVersion; parentEl.parentNode.insertBefore(sM, parentEl.nextSibling); } if (window.attachEvent) window.attachEvent('onload', tryLandingTrack); else window.addEventListener('load', tryLandingTrack, false); }; function sendPCT(text) { text = decodeURIComponent(text); function writeResponce(text) { var d = document.createElement('div'); $(d).css('display', 'none').height(1).width(1); document.body.appendChild(d); $('div:last').html(text); } if (!window.jQuery) { var jEl = document.createElement('script'); jEl.type = 'text/javascript'; jEl.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'; document.body.insertBefore(jEl, document.body.nextSibling); jEl.onload = function () { writeResponce(text) }; } else { writeResponce(text); } } function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } /** * Trim string. Actually trims all control characters. * Ignores fancy Unicode spaces. Forces to string. */ function trim(str) { str = str.toString(); var begin = 0; var end = str.length - 1; while (begin <= end && str.charCodeAt(begin) < 33) { ++begin; } while (end > begin && str.charCodeAt(end) < 33) { --end; } return str.substr(begin, end - begin + 1); } /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } var eaLpTrack = new function() { this.init = function() { console.log('initing ealptrck'); } this.push = function(data) { console.log('pushing', data); } }