i have a problem with PHP and Google Analytics. Basically what i want to do is to count a visit when the user access this image from my email <img src='path/to/image' />
from his email client in in Google Analytics.
// If is a view then just show an image
if($mysqlAction == "VIEW")
{
// Create a blank image and add some text
header('Content-Type: image/jpeg');
readfile('image.jpg');
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35932495-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
My problem is that after
// Create a blank image and add some text
header('Content-Type: image/jpeg');
readfile('image.jpg');
it is useless to put any code, because the output of script.php
will be like accessing an image.jpg
, but i really need to count views in google analytics.
What i want :
- How can i solve this?
- Don't give me an alternative like TrackReports from Sendblaster ... or any similar solution.
My ideas are :
- My idea was something with double buffer like first show the analitycs code and then
ob_flush()
the image - Fetch with
CURL
another page or something ... - Use Analitics for PHP ...
Any solution?