Problems with tracking pixels and Gmail proxy
Asked Answered
B

2

7

I am trying to implement a custom Tracking Pixel for Emails sent out from wordpress.

Thanks to these post:

Tracking email with PHP and image

Tracking email opens with a real image

and especially

http://www.phpdevtips.com/2013/06/email-open-tracking-with-php-and-mysql/

I was able to implement the core idea.

The email loads the tracking pixel via <img src="https://www.example.com/tracking.php?order_id=1" width="100" height="100" />

and in the tracking.php

$graphic_http =  'https://www.example.com/GIF-example.gif';

header('Content-Type: image/gif');
readfile( $graphic_http );

Opening the tracking.php file in a browser opens up the gif image for download.

However the Tracking pixel/Tracking image doesn't show up in the Gmail Email. There is only a broken image logo and when I click to show the image this link is opened

https://ci5.googleusercontent.com/proxy/l2xUKFGnNFKm64zEYmJhOcUmEJm15w9MC1txRRF01tpKlcL3t3O16aMJgbYQkucBySV0xV2T0EsCwikOAC0Z4em6uPzSs38lkHrYBvosRRAk14EfPoEXqC5JdLxRm8ToZmGSQqt_RwHCaBE_3uLgQDVEB05Rdtkq-Xzuw30=s0-d-e1-ft#https://www.example.com/tracking.php?order_id=1

which states a Google 404:

Google 404. That’s an error.

The requested URL /proxy/l2xUKFGnNFKm64zEYmJhOcUmEJm15w9MC1txRRF01tpKlcL3t3O16aMJgbYQkucBySV0xV2T0EsCwikOAC0Z4em6uPzSs38lkHrYBvosRRAk14EfPoEXqC5JdLxRm8ToZmGSQqt_RwHCaBE_3uLgQDVEB05Rdtkq-Xzuw30=s0-d-e1-ft was not found on this server. That’s all we know.

It seems to be a problem that Google's proxy cannot read the php script. Both the tracking.php and the GIF-example.gif files have 775 rights and are accesible publicly.

On Hotmail this does work so it really seems to be a problem with the Google Proxies.

Does anybody know how to let the Google Proxies access this Tracking pixel?

Battery answered 6/7, 2016 at 14:3 Comment(0)
B
4

I figured out the answer: The problem was with the Google Proxies and the question mark ? in https://www.example.com/tracking.php?order_id=1

The Google Proxies address got messed up because it already had a question mark and resulted in a 404.

I resolved it using https://www.example.com/tracking.php/order_id=1 instead and then on the tracking.php I didn't use $_GET but $_SERVER['REQUEST_URI'] and parsed the /order_id= String.

The tracking pixel shows up in Gmail and it gets tracked in the tracking.php script.

Battery answered 8/7, 2016 at 11:15 Comment(1)
My tracking URL after sending the mail in Gmail looks like this <img src="ci5.googleusercontent.com/proxy/…" alt="" class="CToWUd">. But gmail is sending 2 server requests like ci5.googleusercontent.com/proxy/…........... Why is it removing my tracker URL in network request? Pls helpAnopheles
L
0

All your headers are trying to force the browser to download the file and ignore it's file type (since you never say what file type it is). For images to be displayed in the browser, you need to set the correct header.

This is basically all you need to do:

$orderId = isset($_GET['order_id']) ? $_GET['order_id'] : null;

if ($orderId) {
    // Save stuff in your DB or how you want to log it.
}

header('Content-Type: image/gif');
echo file_get_contents('/absolute/path/to/image.gif');
exit; // Not really necessary, but just to make sure there's no more output.
Lenni answered 6/7, 2016 at 14:34 Comment(2)
thanks for your feedback. I actually had the header('Content-Type: image/gif'); in my code but forgot to add it here in the question. Thanks for pointing tht out. However: Your suggested solution also does not work. neither file_get_contents nor readfile. The same broken image and google 404 on its proxied image content.Battery
What happens if you create a separate page and put the same <img src="...." /> tag on it? Does it work for you then? Or is it something server related?Lenni

© 2022 - 2024 — McMap. All rights reserved.