function getUrlVarsParser() { var vars2 = {}; var parts2 = location.href.toString(); parts2.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m2,key2,value2) { vars2[key2] = value2; }); return vars2; } function isEmpty(str) { return (!str || 0 === str.length); } function b(a, c, d) { d || (d = document.body); var g, h, i, e = d.childNodes, f = new RegExp(a,"gi"), j = a.replace(/\D+/g, ""), k = c.replace(/\D+/g, ""); for (g = 0, h = e.length; g < h; g++) { if (i = e[g], 1 == i.nodeType && "A" == i.tagName) { var l = i.getAttribute("href"); l && i.setAttribute("href", l.replace(j, k)) } 3 == i.nodeType ? i.textContent ? i.textContent = i.textContent.replace(f, c) : i.nodeValue = i.nodeValue.replace(f, c) : b(a, c, e[g]) } } var ajax_tracking = {}; ajax_tracking.x = function () { var xhr; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } return xhr; }; ajax_tracking.send = function (url, callback, method, data, async) { if (async === undefined) { async = true; } var x = ajax_tracking.x(); x.open(method, url, async); x.onreadystatechange = function () { if (x.readyState == 4) { callback(x.responseText) } }; if (method == 'POST') { x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } x.send(data) }; ajax_tracking.get = function (url, data, callback, async) { var query = []; for (var key in data) { query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key])); } ajax_tracking.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'GET', null, async) }; ajax_tracking.post = function (url, data, callback, async) { var query = []; for (var key in data) { query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key])); } ajax_tracking.send(url, callback, 'POST', query.join('&'), async) }; document.addEventListener( 'DOMContentLoaded', function () { var referrer = ''; if (document.referrer.indexOf(location.protocol + "//" + location.host) !== 0) { referrer = document.referrer; } var ip = '3.80.224.52'; var child_id = 18; var gclib = getUrlVarsParser()["gclid"]; if (!isEmpty(gclib)) { referrer = referrer + '_gclib=' + gclib; } if (!isEmpty(ip)) { referrer = referrer + '_ip=' + ip; } ga(function(tracker) { var client_id = tracker.get('clientId'); ajax_tracking.post ( 'https://call-tracking.oq.dk/frontend/frontend_get_number', {customer_id: 18, google_client_id: client_id}, function(data) { if (data != '') { var data_received = data.split(";"); //replaceText('body', data_received[3], data_received[4], 'g'); b(data_received[3], data_received[4]); var str = data_received[3]; str = str.replace(/\s+/g, ''); //replaceText('body', str, data_received[4], 'g'); b(str, data_received[4]); if (data_received[5] == '1') { ajax_tracking.post ( 'https://call-tracking.oq.dk/frontend/frontend_ajax', {referrer: referrer, number_id: data_received[0]}, function(data) { } ); } } } ); }); }, false );