Tracking Email Opens/Clicks

stealthisblog

Regular Member
Joined
May 26, 2008
Messages
289
Reaction score
163
Hey. I was wondering if there were any scripts out there that tracked who opened an email or clicked the link inside of it? This would be great for checking out email deliverability and finding ways to get passed spam filters. I know some people have shown stats of opens and clicks before, I'm just not sure how.

If no one knows of any I'll whip one up, its really easy. I just figured a nice polished script would be better than a half assed one I made in a few minutes ;)

Thanks for any replies!
 
Ok forget it, just made my own. Thanks anyway.
 
Would u mind telling us how you made it? I was looking also for a solution.
 
The way I track email open/clicks is by looking at the stats on my domain. Obviously if they came from anything with mail contained in the referrer then they responded to my email. You can further refine this to track creatives and split test (i.e. 2 different urls and then compare the page requests to determine the better creative). Send a constant amount of email with the creatives split between the two to see which one 'wins out'.

After this I can check who clicks on my cpa offer from that landing page via 301 redirect requests which also has a section in awstats. This you can form rudimentary numbers and this is totally a DIY solution.

I'm sure there is software out there which other people can chime in about that will do all this for you.
 
You can also have an image load into the email, and have that image in a specific spot on your domain (like in a folder specific to that email, so you know).

Of course having html in an email can effect delivery. Does anyone know if it counts as an image load if someone opens the email but outlook blocks the image? Or would it come up as an error?

Matt
 
Sorry guys, forgot about the script. Just create a database named emailstats and run the SQL queries in the comments to build the needed tables.

Code:
<?php

/*
For database `emailstats`

CREATE TABLE  `emailstats`.`logs` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` TEXT NOT NULL ,
`campaign` INT NOT NULL ,
`opens` INT NOT NULL ,
`clicks` INT NOT NULL
) ENGINE = MYISAM ;

CREATE TABLE  `emailstats`.`campaigns` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`url` TEXT NOT NULL
) ENGINE = MYISAM ;
*/



$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "emailstats";

mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);

switch($_GET['act']){
	case "open":
		$ip = $_SERVER['REMOTE_ADDR'];
		$campaign = (int)$_GET['campaign'];
		if(mysql_num_rows(mysql_query("SELECT * FROM logs WHERE ip='$ip' AND campaign='$campaign'"))==0){
			mysql_query("INSERT INTO logs (ip, campaign, opens, clicks) VALUES ('$ip', '$campaign', '1', '0')");
		} else {
			$opens = mysql_query("SELECT * FROM logs WHERE ip='$ip' AND campaign='$campaign'");
			$opens = mysql_fetch_assoc($opens);
			$new_opens = $opens['opens'] + 1;
			$rowid = $opens['id'];
			mysql_query("UPDATE logs SET opens='$new_opens' WHERE id='$rowid'") or die(mysql_error());
		}
		break;
	
	case "click":
		$ip = $_SERVER['REMOTE_ADDR'];
		$campaign = (int)$_GET['campaign'];
		if(mysql_num_rows(mysql_query("SELECT * FROM logs WHERE ip='$ip' AND campaign='$campaign'"))==0){
			mysql_query("INSERT INTO logs (ip, campaign, opens, clicks) VALUES ('$ip', '$campaign', '0', '1')");
		} else {
			$clicks = mysql_query("SELECT * FROM logs WHERE ip='$ip' AND campaign='$campaign'");
			$clicks = mysql_fetch_assoc($clicks);
			$new_clicks = $clicks['clicks'] + 1;
			$rowid = $clicks['id'];
			mysql_query("UPDATE logs SET clicks='$new_clicks' WHERE id='$rowid'");

			$camp = mysql_query("SELECT * FROM campaigns WHERE id='$campaign'");
			$camp = mysql_fetch_assoc($camp);
			$camp = $camp['url'];
		}	
		header("Location: $camp");
		break;

	default:
		echo "Internal Server Error. Logged.";
		break;
}

?>
 
most common method is to load an image in the email.
 
Oh sorry, I didn't specify what to do with my logger.

Say you installed it on site.com/log.php

You would first add your campaign URL to the database. Say you add google.com and its the 1st row.

For the link in your email, you would do <a href="http://site.com/log.php?click=1">Google</a>. It would redirect to Google and log the click.

At the end you would put <img src="http://site.com/log.php?open=1" style="visibility: hidden">. This would log whenever the user opens the email.

Then you would just check the logs database table and see the opens and clicks!
 
Back
Top