Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Tracking Pixel for Gmail

I am trying to create a tracking pixel that will log the time an email is opened in my database. I am doing this by calling a php link in the URL path.

<img src="http://example.com/lp/index.php?p=tp&ord=xxxx" />

Then in my controller I have the code that logs the time followed by this bit of code that reads a 1x1 image and displays it to the screen.

$fileOut = 'inc/sections/common/tpixel.jpg';
header("Content-Type: image/jpg");
header('Content-Length: ' . filesize($fileOut));
readfile($fileOut);

This works as expected if the img tag is placed in the HTML of a web page and the web page is viewed in a browser. However when I place this image tag into an email and view it using gmail the timestamp does not fire nor does the image display. It just returns a 404 error.

Any ideas as to why viewing the image in gmail would return not found? Is this not the best way to do this? This is my first attempt at a tracking pixel.

Also please note I do click the show images in the email to activate it.

like image 618
user3167249 Avatar asked Oct 31 '22 12:10

user3167249


1 Answers

This will happen if your URL is not publicly accessible.

This is because GMail proxies images: https://blog.filippo.io/how-the-new-gmail-image-proxy-works-and-what-this-means-for-you/ -- so it is not enough that you can access that tracking pixel's URL from your browser: GMail's servers need to be able to access it, too.

like image 73
jsalvata Avatar answered Nov 09 '22 07:11

jsalvata