window.onload = function () { var query = window.location.search.split('?'); var articleName = window.location.pathname .substring(1) .replace(/^(\/+)|(\/+)$|(\.\w{1,4})/gi, '') // replace trailing slashes ; var parameters = {}; if (query.length > 1) { var data = query[1].split('&'); var parameter; var i; for (i in data) { parameter = data[i].split('='); if (parameter.length === 2) { parameters[parameter[0]] = decodeURIComponent(parameter[1]); } } } var debug = Boolean(parameters['debug'] || false); debug && console.log('article: ' + articleName) if (articleName) { var getCookie = function (cname) { var name = cname + "="; 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); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } var id = parameters['id'] || getCookie('greatagent-campaign-tracker-lead-id') || null; debug && console.log('lead: ' + id); // track article reading if (id) { query = { ts: + new Date(), action: 'read-article', id: id, tags: articleName }; parameters = []; for (i in query) { parameters.push([i,query[i]].join('=')) } debug && console.dir(parameters); var img = document.createElement("img"); img.src = "/leads-web-activity/endpoints/tracker.php?" + parameters.join('&'); debug && console.log('src: ' + img.src); document .getElementsByTagName('body')[0] .appendChild(img); } } };