I’m adding a javascript pixel tracker onto a website, but I’m only trying to have it display on a specific circumstance. That circumstance is being tested for in an external javascript file which then creates the HTML code to echo out.
My question is can the pixel tracking script just stay within that external javascript file? As in not be apart of the echoed out HTML Code that would display in a View Source of the page, and just stay hidden within that external js.
Here is the bulk of the tracking code:
(function () {
var oldonload = window.onload;
window.onload = function(){
__adx_loaded=true;
var scr = document.createElement("script");
var host = (("https:" == document.location.protocol) ? "https://adx.com" : "http://adx.com");
scr.setAttribute('async', 'true');
scr.type = "text/javascript";
scr.src = host + "/j/roundtrip.js";
((document.getElementsByTagName('head') || [null])[0] ||
document.getElementsByTagName('script')[0].parentNode).appendChild(scr);
if(oldonload){oldonload()}};
}());
Yes it can be in an external javascript file.