2

As I understand it, a "tracking pixel" is a script that contains code that includes a header that make the response appear to be an image, which is then called using an image tag, like:

<img src="mytrackingpixel.php">

...so that the code runs automatically/silently, when the page loads the images, for tracking or other purposes.


If I'm correct so far, then my questions are:

  1. What's the advantage? How is this any different from just includeing another .js file, with the same code?

  2. Images are often cached (but also refreshed sometimes) - so won't the code run at somewhat unpredictably/irregularly?

1
  • oh and # - do they sometimes have actual images attached?
    – ashleedawg
    Jan 15 '19 at 9:50
1

Here are a few reasons one might choose tracking pixels over a script:

  • Images are less likely to be blocked on the client-side than scripts.

  • You can easily prevent the pixel from being cached (and therefore prevent any cache jank) by using a Cache-Control HTTP header that tells the browser to never cache the pixel.

  • For basic server-side tracking, JavaScript is not needed anyways, as the server can get all the info it wants from the HTTP headers.

  • If you are doing server-side tracking, a tracking pixel is simpler to implement than JavaScript code.

Tracking pixels and tracking JavaScript both have their pros and cons. The tracking pixel is a simple, basic server-side approach that is often enough if the webmaster's needs are not too advanced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.