Impression trackers are commonly URLs that you can hit by using the new Image().src method or something similar. I’ve only ever seen pixels or PHP scripts get hit in these URLs.
What happens when a third party wants a JavaScript code snippet to execute? Like the following
<script src="http://their.special/javascript.file.js"></script>
<script>
aFunctionThatExistsInThatSpecialFile();
if(someFlagSetInThatFile) {
someObjectInThatFile.setSomeProperty();
}
someOtherFunction();
</script>
Or it could look like
var myVar = document.getElementById('someID');
//... more JavaScript
The snippet could do whatever it wants like write out a cookie or something.
You can’t load this as the source of an img. You shouldn’t do a document.write because the impression event could fire after page load. A document.write could wipe the whole page.
So how do you use JavaScript to support this kind of impression tracker?
If you look at something like AdWords, you’d usually see something like:
That isn’t really what it looks like at all.
But it is what it does — basically.
These days, however, more programs are doing things like (consider GA):
And then at the bottom of the page, loading a script which will look for
trackerand make an image to track all of the data:Whenever it loads, it will go through the array of stuff that was handed to it, and put it together one by one.
If you’re talking about firing it on “Impression”, then you (or your company’s stakeholders — marketing or IT, or a higher-up in Analytics) will have to define what “Impression” means to them.
For a lot of people, just having it on the bottom of the page, so that it fires when the page loads (ie: an “impression” of the page), is sufficient.