1

I'm trying to add a tracking pixel in the wordpress single.php.

I found the tracking pixel code here: https://stackoverflow.com/a/18852257/1848279

and I wrote the logic, but I don't know how to include it in the theme so I can have a url with the image which to add in the single.php file.

The tracking pixel I'm trying to implement should expose a url like the following: https://www.example.com/pixel.gif

I tried other options but I'm using wp super cache which creates fully static html pages and serves them from nginx which blocks the tracking code from running.

Community
  • 1
  • 1
TaoJS
  • 109
  • 1
  • 2
  • 13

1 Answers1

1

I've seen analytics tools use javascript and fallback to pixels when javascript is not enabled. You need to create an image tag that point to a pixel file this could be a php or a location mapped to the php file. If it's going to be a pixel image then you should make sure that the image source has a randomness in it's url e.g. image.jpg?t=123123123 where it's current timestamp + random number.

Svetoslav Marinov
  • 1,498
  • 14
  • 11
  • Why is the randomness necessary? I'm checking the ip, browser, os and screen resolution to make sure that I'm only adding one view per device. Thank you for anwsering so fast. – TaoJS Feb 28 '17 at 00:35
  • if you use this https://www.example.com/pixel.gif browsers will cache it. – Svetoslav Marinov Feb 28 '17 at 12:38