1

I have tracking pixels on a webpage that uses image tags. These leave empty spaces on the page. I want to hide them using css. I already verified that both of these examples:

<img src="https://placekitten.com/g/200/300">

vs

<img src="https://placekitten.com/g/200/300" style="display:none">

Produces a http request (as seen in the network tab of my browser's dev tools). Does anyone see any issues with hiding tracking pixels using css this way? I only tested in Chrome and the http request is still going through so it should be fine but are there other browsers which won't send the http request if the image in hidden?

1 Answers1

1

I think it's pretty safe to say that this is a suitable solution for 99% of the browser variants. Unless you specifically have a need to track antiquated browsers, browsers set in quirks mode, and ensure that 100% of the image hits are processed, this should be suitable.

If you're concerned with that 1% though, you could use an alternative solution, such as having the tracking script respond with a 1x1 pixel transparent GIF so you could keep it visible.

Or, you could position the image outside of the viewport position: absolute; left: -999%;, though some browsers may think negatively of this sort of behavior.

jeffjenx
  • 17,041
  • 6
  • 57
  • 99