Earlier this week E-consultancy's own Drama 2.0 discussed current click fraud rates with PPC ad programs.

As an active user of PPC marketing, I wanted to chime in with my strategy for dealing with the issue.

There are a lot of companies that offer services designed to help online advertisers detect and defeat click fraud but if you have some basic skills with PHP and MySQL (or other languages/databases), you may not need them.

A few years ago, I developed my own little application that I use to keep track of my clicks and I'd like to share some of the basic components with you.

The Database

Create a MySQL table using the following:

CREATE TABLE `click_log` (
  `click_id` int(10) unsigned NOT NULL auto_increment,
  `group_id` int(10) unsigned NOT NULL,
  `timestamp` int(10) unsigned NOT NULL,
  `date` int(10) unsigned NOT NULL,
  `ip` varchar(25) NOT NULL,
  `user_agent` varchar(200) NOT NULL,
  `referer` varchar(300) NOT NULL,
  PRIMARY KEY  (`click_id`)

This table stores the following important pieces of data:

The ad group from which the click came, the time of the click, the IP address of the clicker, the user agent of the clicker's browser and the website that referred the click (if any).

The Script

When setting up your campaigns, you will want to use a script that tracks the click and then redirects the user to the proper page.

I've cut out of my application the core code that deals with the tracking:



 $conn = @db_connect();
 $gid = trim(htmlentities(strip_tags($_GET['gid'])));
 $timestamp = time();
 $date = date("Ymd", $timestamp);
 $referer = $_SERVER['HTTP_REFERER'];
 $user_agent = $_SERVER['HTTP_USER_AGENT'];
 $log = @mysql_query("INSERT INTO click_log (group_id, timestamp, date, ip, referer, user_agent) VALUES ('$gid', '$timestamp', '$date', '$ip', '$referer', '$user_agent')");
 //Add logic for redirecting the user based on the group ID - $gid

 header("Location: $url");


Note: db_connect is a common function included in functions.inc.php that connects to the MySQL database

The script is very straightforward. It inserts all of the data we've collected about the click into the database and redirects the user to the desired page based on the group ID associated with the ad campaign.

What's Next?

Once you're collecting this data, there's really no limit to what you can do with it. The front-end that I built allows me to analyze the data and provides visual representations of the clicks my campaigns have received. It also lets me manage my campaigns.

If you're collecting data and closely monitoring your campaigns, you will notice patterns and when you see something out of the ordinary (increasing number of clicks from a specific campaign, lots clicks coming from a specific geographic region, etc.), you can take appropriate action to try to determine if this is likely to be fraudulent and most importantly, can take action to make modifications to your campaigns if it is.

If you want to take things even further, you can expand your application to compare click data to the data provided by the PPC services you use (like AdSense). You can also integrate with web analytics software to gain insight into which clicks might be fraudulent by tracking what a "user" does on your website after the click.

One important thing to note is the fact that some of the data we're collecting, such as referer, can be forged. But this does not mean that our methodology is flawed.

Remember - eliminating click fraud altogether is impossible. The goal is to catch click fraud patterns early on so that your losses aren't greater than they need to be.


Published 12 November, 2008 by Patrick Oak

82 more posts from this author

You might be interested in

Comments (3)



Hi, thanks for this. I assume your code is only useful to publishers, not advertisers?

I only dabble with code, so would appreciate any further instructions or examples regarding the //Add logic for redirecting the user part


almost 10 years ago


Chris P.

I don't bother with PPC models anymore. They simplly drain too much money from my budget. Recently moved my retail affilation over to Sortprice.com, which uses a flat fee monthly system rather than PPC and I recommend people explore that option as well:


almost 10 years ago


Patrick Oak, Blogger at Econsultancy


The code can be used by anyone. If you have a server that supports PHP/MySQL, you can set this up and redirect users to sites that are run by clients, partners, affiliate program operators, etc.

Here's some sample logic:

if ($gid == 1)
$url = "http://www.e-consultancy.com&quot;;
if ($gid == 2)
$url = "http://www.emailbuild.com&quot;;

This redirects the user to E-consultancy's website if the "gid" variable in the query string is set to 1 and to your website if the "gid" variable in the query string is set to 2.

Once again, you can implement a lot more depending on your needs. Here are some suggestions:

- Add a database table that contains the group IDs (gids) and their associated URLs so that you can add more easily without having to hard code for each gid.

- Add an extra variable - campaign ID - so that you can track things more granularly.

Hope this helps.

almost 10 years ago

Save or Cancel

Enjoying this article?

Get more just like this, delivered to your inbox.

Keep up to date with the latest analysis, inspiration and learning from the Econsultancy blog with our free Digital Pulse newsletter. You will receive a hand-picked digest of the latest and greatest articles, as well as snippets of new market data, best practice guides and trends research.