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.