Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Created May 30, 2012 09:07
Show Gist options
  • Save DimitarChristoff/2834807 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/2834807 to your computer and use it in GitHub Desktop.
pixel tracking ftw
;(function() {
var lazyLoadScript = function(url) {
// make sure the script being loaded does not do document.write and can be deferred.
var ns = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
ns.type = 'text/javascript';
ns.async = true;
ns.src = url;
s.parentNode.insertBefore(ns, s);
}, makePixelRequest(url, pixelType) {
// ensure SSL is kept/enforced.
document.location.protocol == 'https:' && (url = url.replace('http:', 'https:'));
if (pixelType == 'javascript') {
lazyLoadScript(url);
} else {
// non-blocking get request
setTimeout(10, function() {
var img = new Image();
img.src = url;
});
}
};
makePixelRequest('http://cm.g.doubleclick.net/pixel?google_nid=invitemedia&google_cm', 'image');
makePixelRequest('http://ad.yieldmanager.com/pixel?id=1836922&id=1836923&t=2', 'image');
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment