Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Pixel Tracking across domains in PHP

I understand the basics of pixel tracking, I'm able to insert a pixel that references an image on my tracking domain to other websites.

However, how do I increment that actual pixel count on my tracking domain? Is there some kind of log that tells me every time that pixel image was served up? Am i able to do something like:

<img src="http://www.foo.com/serveImage/getImage.php?id=5123" />

then have the getImage page, serve up the image, and increment based on the id that was passed in? or is there a better way to achieve this?

Thank you in advance.

like image 942
Petrogad Avatar asked Jul 23 '09 18:07

Petrogad


Video Answer


3 Answers

if you want to just output a gif this is a quick simple way, just make sure your script doesn't output anything else before or after:

header("Content-type: image/gif");
header("Content-length: 43");
$fp = fopen("php://output","wb");
fwrite($fp,"GIF89a\x01\x00\x01\x00\x80\x00\x00\xFF\xFF",15);
fwrite($fp,"\xFF\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00",12);
fwrite($fp,"\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02",12);
fwrite($fp,"\x44\x01\x00\x3B",4);
fclose($fp);
like image 184
nsbucky Avatar answered Sep 17 '22 18:09

nsbucky


Yes you have the right idea.

You give each site or page a unique ID, which is then passed in the image src. So in your example the ID is 5123.

In your getImage.php script then use this ID to increment the database (or however you record the data) and return any image that you want to. If you want the image you return to show the number of hits you can create an image on the fly with the GD extention - see the PHP manual for more information on it.

like image 37
Jacob Wyke Avatar answered Sep 19 '22 18:09

Jacob Wyke


this is my track code:

<?php

$id = $_GET['site_id'];

// do track

$imageFile = 'images/pixel.jpg';
$im = imagecreatefromjpeg($imageFile);
header('Content-type: image/jpeg');
imagejpeg($im);


?>
like image 25
Gabriel Sosa Avatar answered Sep 18 '22 18:09

Gabriel Sosa