How to: PHP Click Tracking Pixels
Tracking information about the visitors to your website helps you determine how frequently people are loading a specific page and at what times. Click-tracking works by placing a single one-by-one pixel image on a page and linking it to a remote script that saves information about the visitor into a database or file. Code the tracking script yourself to avoid having to download an entire tracking or web-analytic software package.
Instructions
-
-
1
Open your HTML file in a text editor, such as Windows Notepad.
-
2
Create a link to a transparent, one-by-one pixel GIF image by adding the following code in the body of your HTML file:
<img src="http://www.myserver.com/pixelclick.php?id=1"/>
Replace "?id=1" with the unique "id" you want to use for the specific site. Each web page needs a separate "id" to differentiate between them.
-
-
3
Save and close the file.
-
4
Create a new document in your a text editor.
-
5
Create a PHP script to handle the tracking code. Type the following code at the top of the empty file:
<?php
header("content-type: image/gif");
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");$s=date("Y-m-d H:i:s") . ": ". $_SERVER['REMOTE_ADDR'] . " : " .$_GET['id']. "\n";
file_put_contents("my_track_file.txt", $s, FILE_APPEND);
?>The script creates and sends the transparent GIF image with the "header" and "base64_decode" functions. It then creates a string containing the visitor's IP address, the current date and the "id" for the remote website. Finally, it appends the string's text to a tracking file.
-
6
Save the PHP file as "pixelclick.php" and close the text editor.
-
7
Upload the PHP file to your server. Upload the HTML file to the remote server you want to track.
-
1
Tips & Warnings
Make sure the PHP script doesn't output any data before the "header" call.