Update to PPC Click Tracking Script for Yahoo and MSN…

December 14th, 2007

Sorry for the long time between posts. Just things have been very busy lately. Here’s an update to the click tracking code for tracking your conversions to include yahoo and msn pay per click. I just pulled this direct out of my system. This also includes a way to exclude bots by IP. Using the list from iplists.com I in a file called ip_list.txt in the same directory as you tracking file. So that your tracking doesn’t record bot visits. Below have included the updated sql schema for click tracking, it’s a little messy and could be better but just haven’t had time to improve it. If someone has a better click tracking schema around I’d be interested in seeing it.

So our urls to use to track

Yahoo Search Marketing:

http://www.yourdomain.com/index.php?s=ysm&n=1

To make this work properly you need to enable tracking URL’s in your account. This will pass all the appropriate variable automatically.

Google Adwords:

http://www.yourdomain.com/index.php?s=ggl&qs={keyword}&k={keyword}&n=1

This could be improved to scrape the query out of the referer and use that for the Query String in the table, it’s on the list.

MSN Adcenter:

http://www.yourdomain.com/index.php?k={Keyword}&s=msn&qs={QueryString}&mt={MatchType}&oii={OrderItemId}&ai={AdId}&n=1


<?
$keyword = addslashes(trim($_GET['k']));
session_start();
DEFINE('DB_HOST','host');
DEFINE('DB_USER','username');
DEFINE('DB_PASS','password');
DEFINE('DB_PRIMARY','tracking');
@mysql_connect(DB_HOST,DB_USER,DB_PASS);
@mysql_select_db(DB_PRIMARY);
if(mysql_ping() == true)
{
if(!isset($_SESSION['id']))
{
// Server variables
$ip = $_SERVER['REMOTE_ADDR'];
$referer = $_SERVER['HTTP_REFERER'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$source = addslashes(trim($_GET['s']));
$site = addslashes(trim($site));
$niche = trim($_GET['n']);
if($niche == ''){ $niche = 1; }
$loc = trim($_GET['loc']);
if($loc == ""){ $loc = "us"; }
if($source != "ysm")
{
$keyword = str_ireplace("_"," ",$keyword);
$query = addslashes(trim($_GET['qs']));
$matchtype = addslashes(trim($_GET['mt']));
$item_id = addslashes(trim($_GET['oii']));
$ad_id = addslashes(trim($_GET['ai']));
$clickid = addslashes(trim($_GET['gclid']));
}else{
$query = addslashes(trim($_GET['OVRAW']));
$keyword = addslashes(trim($_GET['OVKEY']));
$matchtype = addslashes(trim($_GET['OVMTC']));
$ad_id = addslashes(trim($_GET['OVADID']));
}
if(!CheckBotIp($ip))
{
$sql = "INSERT INTO `clicks` (`keyword`,`source`,`ip`,`referer`,`useragent`,`time`,`site`,`querystring`,`matchtype`,`orderitemid`,`adid`,`clickid`,`niche`,`country`) VALUES ('$keyword','$source','$ip','$referer','$useragent',NOW(),'$site','$query','$matchtype','$item_id','$ad_id','$clickid','$niche','$loc')";
//echo $sql;
mysql_query($sql);// or die(mysql_error());
$id = mysql_insert_id();
$_SESSION['id'] = $id;
$_SESSION['keyword'] = $keyword;
$_SESSION['referer'] = $referer;
}
}else{
$id = $_SESSION['id'];
$keyword = $_SESSION['keyword'];
$referer = $_SESSION['referer'];
}
}
/**
* Functions
*/
function CheckBotIp($ip)
{
$flag = 1;
$ips = file("/home/ip_list.txt");
$ips = array_map("trim",$ips);
foreach ($ips as $listip)
{
if($ip == $listip)
{
return 1;
}
}
}
?>

Here’s the updated schema to record for all systems. As I mentioned before it’s crude and needs some work so if anyone wants to contribute I’d be happy to post it and give you credit.

– phpMyAdmin SQL Dump
– version 2.11.0-dev
– http://www.phpmyadmin.net

– Host: localhost
– Generation Time: Dec 14, 2007 at 02:34 PM
– Server version: 5.0.22
– PHP Version: 5.1.6

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


– Database: `tracking`

– ——————————————————–


– Table structure for table `clicks`

CREATE TABLE IF NOT EXISTS `clicks` (
`id` double NOT NULL auto_increment,
`keyword` varchar(255) NOT NULL default ”,
`source` varchar(255) NOT NULL default ”,
`ip` varchar(15) NOT NULL default ”,
`useragent` varchar(255) NOT NULL default ”,
`referer` varchar(255) NOT NULL default ”,
`time` datetime NOT NULL default ‘0000-00-00 00:00:00′,
`site` varchar(100) NOT NULL default ”,
`querystring` varchar(255) NOT NULL default ”,
`matchtype` char(2) NOT NULL default ”,
`orderitemid` varchar(255) NOT NULL default ”,
`adid` varchar(255) NOT NULL default ”,
`medium` varchar(50) NOT NULL,
`network` varchar(10) NOT NULL,
`clickid` varchar(50) NOT NULL,
`niche` int(11) NOT NULL,
`country` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `medium` (`medium`),
KEY `source` (`source`),
KEY `time` (`time`),
KEY `useragent` (`useragent`),
KEY `country` (`country`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

– ——————————————————–


– Table structure for table `conversions`

CREATE TABLE IF NOT EXISTS `conversions` (
`id` double NOT NULL auto_increment,
`click_id` double NOT NULL,
`source` varchar(50) NOT NULL,
`date` date NOT NULL,
`campaign` varchar(255) NOT NULL,
`campiagnID` varchar(20) NOT NULL,
`transactionID` varchar(50) NOT NULL,
`lineitemID` varchar(20) NOT NULL,
`commission` decimal(10,2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `transactionID` (`transactionID`),
KEY `click_id` (`click_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

Great Post By Diorex on a PPC Plan of Attack

November 28th, 2007

I don’t know how many of my readers are into pay per click affiliate advertising but for those of you who are I just read a great post with a plan of attack for how to take on a new campaign. If you’re not familiar with his blog he has a ton of good info on how to make landing pages that convert, finding affiliate offers and scaling your operation. If you get a chance and are interested check out his blog and this post in particular.

Diorex

P.S. Try to see past the boasting :D He’s really a nice guy.

Making Big Easy Money with Google Local Search

November 27th, 2007

As most of you know I’m quite heavily involved with the Payday Loans niche. So I’m constantly scavenging anything I can for information and ideas. Right tip top on that list is searching for things in google and seeing what new pop’s up. And that’s exactly where this idea came from.

Yesterday I was looking at buying a few thousand payday domains for local stuff and was doing some searching in Google to try and find out what would be the best play when I came along a guy that was VERY effectively spamming local for payday loans. He’s in position 1 for all the good payday loan terms + the major city name.
If you don’t know what a local listing looks like it’s the listings in the the search results next to the the map at the top of the page when you include a city or city, state in your search. For example here’s a search for cash advance atlanta, ga. Do you see how the map shows up with the listings? Cool huh, couldn’t pick a much better location for natural serp results then that.

So I’m sure you’re asking yourself how to I get in the google local? Well it’s frairly simple from a web prospective all you do to sign up for google local is setup a google account then click here to sign up for google local.

Now comes the tricky part, Google is going to send you a post card and you have to figure out some way to get that back to them. Now if you live in a major city you can just use your personal address and maybe a business address. But what if you wanted to do it on a large scale? You’d need to find some sort of service that would allow you to use them as a mailbox and then would forward you their mail from there…..

So lets return to that Cash Advance Atlanta, GA result. Now if you didn’t see it the first time the position one spot is a spam site. http://www.atlantacashadvancepaydayloans.com ( cut and paste the as the guy is redirecting traffic from here ) , you see it now? :D So it has an address associated with it, if we do a little search on what that address is low and behold it’s a mailboxes etc/ups store as you can see from a search for the address.

Now that we know this I called and found out how much a box was at this Atlanta store with forwarding. What they told me was it’s $69 for 3 months which is their minimum subscription time. Then 5$ for each batch forwarding plus postage. Since we only need to get one postcard it’d probably cost you 69 + 5 = $74 to set this up. And you have a unique address in a flash :D To make things easier all the UPS Stores use the same sheet for sign up so you can just get a list of a bunch of stores then fax the same sheet to all of them. Waah laah we have local businesses in all the major cities. For a quick text list of the top 50 major cities by population in the U.S. Then just go to http://www.theupsstore.com and get a list of stores you want to use in each city. There’s lots!

Also you’ll notice that domain the fellow is using is keyword rich http://www.atlantacashadvancepaydayloans.com.

If has the city name and both the top keywords for the payday niche.

  • payday loans
  • cash advance

If you wanted to compete in the payday niche I’d suggest something like atlantapaydayloanscashadvance.com or atlantacashloancashadvance.com. Then just take and point the domains to the same location using Virtual Hosts in apache. Reference my domainer timed redirect post if you want to know how to do that. Or easier just tell your hosting provider you want to point all your domains to the same place. Then they can make a catch-all and any domain you point to the server that doesn’t have a listing in the config file will go to your page. To make things a little more targeted you might want to write a little script on the page that parses the domain name then uses the city name with a on the fly find and replace. So you’d grab the domain and parse the name, then in your template would put <? echo $c; ?> rather then hard coding the city. So your template would look like this.

<?
// loads all the cities for a file into your array
$cities = file(“cities.txt”);
//gets the domain that is being called
$domain = $_SERVER['SERVER_NAME'];

// runs through each city in the city list to see if it matches the one in the domain
//if it matches then it assigns that to the $c variable which is what we’ll use in
// our text output.
foreach($cities as $city)
{
if(strpos($domain,$city))
{
$c = $city;
}
}
?>
<html>
<head>
<title>This is my page title for city <? echo $c; ?></title>
</head>
<body>
<H1>Header for City <? echo $c; ?></H1>
<p>Text for city <? echo $c; ?></p>
</body>
</html>

Now we have a dynamic created page based on the city being passed. We’re getting a list of all the cities we’re using. We know that the city name is in the domain so we check which city we’re using. Then we assign that to a dynamic variable we echo out in our on page copy. Pretty easy huh. Couldn’t make a post with no coding in it so I went back and added this later :D

Another thing I noticed is his domains are listed in a few of the other local searches like Superpages and I’d suggest submitting it to as many local places as possible as that’s going to give the site even more exposure. However I’m not sure this is necessary as most of these scrape google anyways.

“That’s great smaxor but how do I make money now that I have the listing?” Well the easiest is to use something like he is which is a affiliate company that allows you to private label their offers. He’s using http://www.leadpoint.com, which you can tell by the secure rights tag on page 2 of the site once you click the button. Another company that allows you to integrate their stuff into your own pages is LeadPile (affiliate link, thanks if you use it ) both companies are good however LeadPile takes everyone and Leadpoint can be picky and not take advertisers.

And that’s it! So how much is potential with something like this? Well a payday lead on average sells for 20-30$. And I know that with position 1 in Google for the keyword “payday loans” it’s worth at least 150 minimum leads a day. Now this is more targeted and could get a better click through and conversion I would assume as people think they’re local near them. So only 4 leads a day from each local listing would pay for the whole setup. I’m sure you’d get a lot more then 4 leads a day in cities like Los Angeles, New York, Atlanta, Chicago. Yup there’s a truckload of cash to be made with this if you put in the time. There’s a lot of niches this will work with I just happened to find it with payday.

And lastly lets take a look at how this guy is doing with his rankings

Atlanta, GA
payday loans
cash advance

San Francisco, CA
payday loans
cash advance – only listing

Chicago, IL
cash advance

New York
cash advance
payday loans

And the list goes on, I’m not going to list all of them but you get the point :D

Now get out there and make some coin.

P.S. You’re probably going to ask why did I reveal this and I’m not doing it myself? To many projects I wish I had time because this seems like a real money maker. Good Luck!!!!

Free – Open Source Analytics/Statistics Package

November 3rd, 2007

I was poking around trying to find a nice analytics package the other day when I came across a fantastic open source one. If you’re interested in tracking and analytics of your sites you might want to check out:

Free Analytics and Statistics Package – http://www.phpmyvisites.us 

Now I know it doesn’t do everything that a lot of the  of the paid services do with click streams and the like. However if you’re currently using something like statcounter.com this is definately a better solution as it gives you:

  1. One it’s a free analytics/statistics package
  2. Has heatmapping built in
  3. You host it so you’re not sharing your data with anyone.
  4. You get a lot of the features that statcounter charges you extra for for Free.

I’ve been looking at it and it would be great to hybrid it with a a click tracking system for PPC. I haven’t done a ton of research into the code yet but if someone was interested in working on this together it might be pretty cool to build a click/conversion tracking plug-in for it. Then eventually move that to a bid management plug-in of some sort. Let me know what you think.

Easy “PHP Proxy Checker” Writing Tutorial

October 31st, 2007

I started to write this on Eli’s forum but decided to add it here so everyone could reference it.

If you have a list of proxies that you’ve got from somewhere and want to verify if they’re good or not this is simple script that will read a text file and check them.

First we’ll make a text file with our proxies on each line of the file in the format IP:PORT with one per line.

127.127.127.127:2487
123.123.123.123:3248

then save that text file as “proxylist.txt” in the same directory as the php file you’re going to make. Then we’ll start our php file with our proxy checking in it. Here’s the complete script that just echo’s the status of each proxy out to the screen. We’ll make a few changes and have it write a new file with only the good proxies next.

// This is the page that that we're going to request going through the proxy
$testpage = "http://www.google.com";
// This loads all the proxies from the file into an array
$proxies = file("proxylist.txt");
// Here we loop through each cell of the array with the proxies in them testing each one until we get to the end of the array
foreach($proxies as $proxy)
{
// This script utilizes cURL which is library you can read more about
//using curl in my intro tutorials
// starting curl and setting the page to get
$ch = curl_init($testpage);
// sets the proxy to go through
curl_setopt($ch,CURLOPT_PROXY,$proxy);
// sets to use a tunnel proxy which most http proxies are
curl_setopt($ch,CURLOPT_HTTPTUNNELPROXY,$proxy);
// makes the curl call do it's work based on what we've set previously and
//returns that fetched page to $page
$page = curl_exec($ch);
// cleans up the curl set
curl_close($ch);
// this will check that there was some html returned, now some sites might block some
//proxies so you'd want to set for that specific site in the $testpage var and then
//find something on that page to look for with the below function.
$check = stripos($page,'</html>');
// if there was a match in the stripos (string postion) function echo that the
//proxy got the data and works
if($check > 0)
{
echo $proxy." Works!
";
// or else echo it doesn't work
}else{
echo $proxy." Is Dead!
";
}
}
?>

There’s your code. The gist of this is that we load each line from a file into an array. Then we loop through each array element checking if we can get the google page going through the proxy. Then if it pulls data it prints on the screen that the proxy works or if it doesn’t get something returned it doesn’t.

Now we might not want to print things to the screen and would rather make a new file with the the good proxies. To do that we’d swap this code:

if($check > 0)

{

 echo $proxy." Works!";

// or else echo it doesn't work

}else{

 echo $proxy." Is Dead!";

}

with:

if($check > 0){file_put_content("newproxylist.txt",$proxy."n",FILE_APPEND);}

rename('proxylist.txt','proxylistold.txt)';

rename('newproxylist.txt','proxylist.txt');

}

And that will write a new file and add each of the good proxies to it. Then rename the the original file to proxylistold.txt in case there was an error it’s good to have a backup. Then we rename the newpoxylist.txt to the standard proxylist.txt and it’s all fresh and ready to go. There you have it a nice simple proxy checker.

P.S. make sure you make the dir that they’re in writable as there’ll be issues with creating a new file in an unwritable dir.

P.P.S Trying this new code plug-in and well let me tell yah. IT’S A HUGE PAIN IN THE ASS!

Domainer Time Based Redirect PHP script – Part 1

October 21st, 2007

As most of you know I’m no domainer. I think I own a grand total of 100 domains or less. However one of our readers is and asked for an easy script to redirect their domains in a time based fashion. He mentioned that after tracking his domains he finds that sometimes redirecting the traffic to a parked page makes him more money for those times then it would redirecting it to an affiliate offer.

Denis:
“I am looking for some kind of script, apps, or any kind or solution that will let me have a complete archive of all of may domain names and basically redirect each one to either my server, parking program or affiliate pages.

I know there are certain scripts out there with a control panel to organize /redirect domains but I want to take my domains one step further and have some of them redirect only on a hour, day, week, month schedule.”

You can read the comments where the conversation stemmed from here here.

The Domainer Time Based Redirect Project

For this project we have a few goals

  1. Make domains point to the same server.
  2. Have that server forward all domains that it doesn’t recognize to the same file to be process and controlled by that file.
  3. Design some sort of data structure to hold the incoming domains and where they should be forwarded to
  4. Build a file that will look for that domain in a database and then verify against what time it is to determine where it should send the traffic to.

Sounds fairly simple but it’ll be a bit complicated. That’s why I’m going to split this tutorial into 2 parts.

  • Part 1 – Will be how to setup your DNS and Apache to take all domains that are pointed at it and forward it to the same file.
  • Part 2 – Will cover how we’re going to hand the data structure with a database.
  • Part 3 – Will finish it up with the file to control the traffic based on looking at the data structure.

Let’s get going.

How to point your domains at your server using Namecheap.

Since I’m talking to domainers I imagine that most of you know how to handle DNS and how to point your domains at a server. However I’ll cover how I handle it using Namecheap. I’ve mentioned before I’m a huge fan of Namecheap as their control panel and features are fantastic. If you don’t use Namecheap and use some other registrar you’ll need to get your domains pointing to your server on your own.

First thing we’re going to need to get is the Ip address of your server where you’re running apache and we’re going to be pointing your domains at. If you don’t know this the easiest way is going to be to use a command like ping to the server if you’re used to using a domain. you’ll get back a number that has 4 parts separated by periods called an IP address. This is where we’re going to point your domains at when we login to namecheap. Let’s use oooff.com as an example. Lets say I didn’t know the IP of oooff.com there’s a few ways we could get it. One way would be just ping the address by going to start/run then typing in “ping oooff.com”. Or there’s a lot of services out there to get IP’s for example you can go here., put in the domain server domain and it’ll return a number that looks like this 64.202.163.77. This is going to be the IP address for oooff.com.

Once we have the IP address we’re going to go to namecheap and login like you normally do. Go to manage domains then click on the domains or select all the domains and hit bulk edit for the domains you want to point at this server. Next we’ll click on “All Host Records” in the left menu column. Once we’re in all host records we’re concerned with the two spots at the top. the “www” and “@”. The “www” is of course going to be where you want the http://www.oooff.com sent and the “@” is going to be where you want http://oooff.com sent. In our case we want them both sent to the same place can you guess what that is? Yep the IP address we got using the ping tool. Also we want to set “Record Type” on both to “A (Address)” as this will use the Namecheap name servers and point them at that IP. Typically this will take 5-10 minutes to update but once this time has passed when you put the domain in your browser you will probably get the default page for you server, a 404 cause your server isn’t setup to handle random domains pointing at it, really just something different then you were getting when you started.

Now that we have our domains pointing to the server we need to do some configure apache to make it do the right thing with the incoming domains. If you’ve never messed with Apache and the Apache Config file before this might be a little intimidating so I’ll make it as simple as possible. Basically the /etc/httpd/conf/httpd.conf file is what controls Apache and tells it how to handle incoming domains basically what folder/directory to send them to. So go to you server via FTP or SSH and find the httpd.conf file. It’s usually in /etc/httpd/conf/ directory if not you might need to do a little searching around to find it. Once you find it open it up and take a look through it. What we’re concerned about is the lines right towards the bottom. Called the VirtualHhost section. There’s a couple of lines in that section we’re concerned about.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

This tells the server to use domain base Virtual Hosting which is what we want to do. Then the second lines we care about are

<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>

What this section is saying is take any incoming domain that doesn’t have a specific record and send it to that location on the server. Now the /var/www/html dir is the default for most apache servers. If yours looks like this we only need to change one thing and that’s to change the document root to somewhere else where we’re going to put our PHP file that’s going to handle all our incoming domains. If that directory doesn’t exist then I suggest making it :) In our example we’ll make a directory dcontroller in /var/www/html. So our virtual host entry would look like this

<VirtualHost *:80>
DocumentRoot /var/www/html/dcontroller
</VirtualHost>
And that’s it. Just save the file then restart your Apche if you’re in on the comman line via SSH just type “server httpd restart”. Or if you have a CPanel/WHM setup you can go to the interface and restart the server there. Now if you have a hard time with this just ask your hosting company as they can easily do it for you. However it’s a great thing to know how to do and understand. Every little piece helps.

Now lets test is our setup is working right. One last piece we’d need to test our setup is working it putting a index.html file in our new directory. Just make a little html file that has a “<h1>Working</h1>” in it. Save this file then go to your browser and type in the domain you setup to point to your server. If you see “Working” displayed in the browser you know you’re golden. If not you know something went wrong. Just contact your hosting support and they’ll guide you I’m sure.

That concludes part 1 of the domainer time redirection system, I’ll try and get the next part written in the next week. Let me know if you have any questions or suggestions and I’ll help if I can. I’m no *nix expert, I just know enough to get by :D

Powerful Open Source ( FREE ) Click tracking tools to improve your Pay Per Click Conversions

October 20th, 2007

Couple of great open source resources for Heat Mapping and click path tracking. Find out where people are clicking and how long they’re staying.

http://www.labsmedia.com/clickheat/index.html

Also if you have a complex site and are looking to track paths of your visitors to find out where they’re leaving you can check out.

http://www.phpopentracker.de

It has the capability of adding plug-in’s to it that will allow you to track conversion. It’s written in PHP and easily extendable to suit your needs. A great place to start if you want to create a full fledged tracking system for and E-commerce site or a large scale site with paths to a sale.

More Advanced Click & Keyword to DirectTrack System Conversion Tracking

October 2nd, 2007

keyword tracking statistics

If you’re in a highly competitive niche where pay-per-click, clicks cost 2-10$ per click you need to do everything you can to improve the conversion ratio’s of those highly expensive clicks. As I’m rather new to Pay-Per-Click advertising I’m learning as I go probably just like a lot of you.

In checking my stats and watching my logs ( making myself crazy ) I found that certain days of the week never seemed to produce conversions. So I decided to stop advertising on those days and what do you know my conversion ratio’s and return went up quite a bit. I don’t know why but certain days of the week people like to click ads but not take action for a couple of my niches. With that said I was wondering if there were certain times of the day that leads didn’t convert. Now I’ve run a lot of BlackHat leads to offers in the past and being as it didn’t matter when what converted I had never looked into tracking at this level, sure wish I would have. Needless to say, times of the day made quite a difference and increased my return on investment even more.

If you’ve been following my blog you’ve probably read through my blog you probably saw the last script I put up on tracking which keywords convert for you. In wanting to check if things converted at certain times of the day the old tracking method I was using wasn’t going to cut it anymore. Because DirectTrack, which is the affiliate system Copeac, CPAEmpire and various other smaller companies I work with run on, doesn’t give you a time only a date. So we need to reinvent how we’re going to do our tracking. Rather then by keyword like in the last tracking script we’re going to track the specifics of every click to the database.

The general premise is that rather than having a keyword ID in the database with a count attached to it we’re going to track each and every click that comes through the site. And rather then having the keyword ID passed for the subid to match those up we’re going to pass the click ID. Then when we go to pull and analyze what converted we can see where the click originated, where the click came from, what keyword triggered it, what time it was, etc.

With this layout there’s going to be a tracking.php file that will be included in the landingpage.php file that will record the click and then return the id for the recorded click. Then that id will be replaced in anything that references the affiliate link.

Layout:

First we’ll have our file somelandingpage.php this is the actual page the user is going to be going to. Very simple for this example we’re going to just make it pretty much blank. We’ll just add a couple things so we can test things properly. Of course you can just add whatever you want to the page later or move the code to a real landing page.

<?
$site = “mydomain.com”;
include(“tracking.php”);
?>
<h1>My landing page</h1>
<a href=”http://www.afffiliatelink.com/affid/offerid/<? echo $id; ?>”>link</a>

That’s it! Let’s talk about what’s going on with somelandingpage.php.

First we’re setting the variable $site which will be used in tracking.php which you’ll find out about very shortly. This is going to be the value to track which site or page the click that’s being recorded came through. In our example case we’re going to use a fictitious domain, mydomain.com. So in the database the click will be recorded as coming through mydomain.com. This will allow us to track a lot of domains or pages in the same db. Something else you might do is if you’re split testing landing pages you can just setup two different ones then rotate between them and give them different site names. Then the clicks will be tracked for each page in the db.

Next we’re including the file tracking.php file which will be what we discuss next. If you don’t know, whenever we include a file that means execute the code in the file just like it was written in the somelandingpage.php file itself. It executes it inline just like it was in it. This allows us to make one tracking file and then include it in a lot of pages.

Then we close out the PHP code and put a little HTML just so we can see on the screen that that page actually loaded. The last line of the file is going to give us the link to an offer with the click ID for the click data we inserted. You’ll see how this works shortly. Just understand that we’re going to passing the click ID for the subid in the affiliate link. Then we can go back later and match up the subid on the conversions and match it up with the click ID to see everything about the originating click.

Now lets talk about the tracking.php file.

So tracking.php is going to be the file that’s included on the landing page. Now keep in mind if you have 100 pages on a site and you want to track each one all you have to do is do is set the $site=”site.com/thispage.html”; and include(“tracking.php”); then it’ll start tracking clicks on that page as well.

The gist of the script is

1. we connect to the db
2. we get some environment variables that are set by the server (ip address, referrer, useragent)
3. get data being passed in the url. I’m tracking keyword and source of the click. Now we could get the source through the referrer but setting it when we run our ads is a lot more reliable.
4. we insert the data we gathered into the database.
5. get the id of the record we just inserted.
6. remember the affiliate link in the previous file? Well now we just echo out the id into it where the subid goes and we have the click tracked in the subid. So if that click converts we can go back and see where the click came from, what time it was, what keyword it was. All important stuff wouldn’t you say?

<?
//connecting to the database we setup
DEFINE(‘DB_HOST’,'localhost’);
DEFINE(‘DB_USER’,'login’);
DEFINE(‘DB_PASS’,'password’);

DEFINE(‘DB_PRIMARY’,'tracking’);

mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_PRIMARY);

// Server variables
$ip = $_SERVER['REMOTE_ADDR'];
$referer = $_SERVER['HTTP_REFERER'];
$useragent = $_SERVER['HTTP_USER_AGENT'];

// capturing data we passed in the url
//ie. http://domain.com/page.php?k=my+keyword&s=yahoo
// I’ve added the engine the click is coming from as
// I’m starting to branch out to other engines now
$keyword = trim($_GET['k']);
$source = trim($_GET['s']);

$sql = “INSERT INTO `clicks` (`keyword`,`source`,`ip`,`referer`,`useragent`,`time`,`site`) VALUES (‘$keyword’,'$source’,'$ip’,'$referer’,'$useragent’,NOW(),’$site’)”;
mysql_query($sql);

$id = mysql_insert_id();

?>

Lastly here’s the Database structure you’re going to need. I created a new database called “tracking” and added the table “clicks” with fields for each data piece we want to hold. Here’s the SQL for the click tracking table:

CREATE TABLE IF NOT EXISTS `clicks` (
`id` double NOT NULL auto_increment,
`keyword` varchar(255) NOT NULL,
`source` varchar(255) NOT NULL,
`ip` varchar(15) NOT NULL,
`useragent` varchar(255) NOT NULL,
`referer` varchar(255) NOT NULL,
`time` datetime NOT NULL,
`site` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;

Now all you have to do is go and pull your advanced report from your directtrack based affiliate system. Or any affiliate system that supports SubId’s. And match up the subid’s on your conversions to your click ID’s. Then you know exactly what’s converting for you when.

Next post I’ll cover Building a table for the conversion records and how to automate pulling the data from the directtrack system to populate it. Also I might show you how to make a little system to see what Conversion ratio you’re getting for what words. The last thing which I haven’t implemented myself if finding what bids on words are costing, which could be referenced from reports from the ppc engines.

Stay Tuned!

How do I pick and Affiliate Offer to run?

September 17th, 2007

Ubaidabcd from http://www.wickedfire.com forums wrote saying he was having some issues finding offers that worked on the affiliate networks. I started to respond on wickedfire then decided I needed a new blog post.

Bottomline – is a LOT of offers SUCKKKKKKK. Think about this. For most affiliate companies, all you have to do to run an offer is put up a small retainer even if they don’t know you at all. Now anyone can put up and offer, can you think of how many people might try that? What skin is it off their neck to just throw up and offer? Talk about the greatest opportunity for online marketing there is this is a guarantee’d ROI. You don’t pay unless you get something you’re going to make more money on. Now don’t get me wrong there’s definately some fraud in CPA offers, but that’s not the focus of this post. What I’m saying is you have thousands of people trying to make money as affiliates but only a few actually are good at it. The same thing is true for people running offers.

Just for fun lets take Payday Loans as an example. This is a high competition niche and there’s a million offers out there for it. I’ve run most of them, at one time or another, at least as a try. With varying payouts from 14$/loan to 56$/loan. And I’ve seen varying conversion rates from .5% to 18%. Now think about this for a second often times people talk about payout, payout, payout. Well payout is only one part of the equation. Conversion combined with payout is what you’re looking for and to be honest most offers landing pages just don’t convert. Then you get to something like payday loans and there’s another variable to the equation, you typically don’t get paid on most offers unless the lead sells on the backside. Now this happens instantly and most affiliates never see this and a lot don’t even know this is happening. Often times you’ll get a nice conversion on the landing page to an application. However the loan doesn’t sell on the backside for some reason which means you don’t get paid. But this is just another variable in the equation.

I’m no PPC pro but I’m starting to run it more and more. Typically what I do, to find offers is run some blackhat traffic to it which is free for me. Then I test all the offers I can find with random split testing. Then after I’ve run enough traffic to it I just go with the best performing offer and move on to PPC and growing a blackhat/greyhat network for it.

Learn what to look for and know what converts and what doesn’t. Study landing page methodology. Look at the big, highly competive niches you hear about because if you’re not good in these niches you die. Then compare that to the offers you’re looking at. Ask yourself would I buy from this page?

If you don’t have simple split testing code here you go. This will just randomly go through your affiliate urls. Then track your offers at your destination for clicks vs. conversions.

<?

$urls = array(
“http://www.affiliateurl1.com”,
“http://www.affiliateurl2.com”,
“http://www.affiliateurl3.com”,
“http://www.affiliateurl4.com”);

$url = $urls[array_rand($urls)];
$destination = “Loation: $url”;
header($destination);

?>

Also if you don’t want to redirect you can just replace that last line with an iframe and remove the destination line.

The iframed version:

<?

$urls = array(
“http://www.affiliateurl1.com”,
“http://www.affiliateurl2.com”,
“http://www.affiliateurl3.com”,
“http://www.affiliateurl4.com”);

$url = $urls[array_rand($urls)];

echo “<meta http-equiv=’refresh’ content=’0; url=$url’>”;

?>

How to Track Converting Keywords for your Affiliate Marketing advertising using PHP.

August 31st, 2007

Do it yourself keyword conversion tracking

I started to write this on http://www.wickedfire.com then figured I needed some new content this week.

Have you ever wanted to find out which of your keywords are converting on your campaigns you’re running?

This is actually a relatively simple thing to do if you pass the keyword as your subid. However because we never know who’s looking at our keywords we’re going to want to rewrite the keyword as a number that we have reference to. If you’re traffic to a content site or something other then a straight redirect bounce page, you can track them with a cookie or session or both. So a very simple solution for an affiliate redirect page that tracks your conversion by keyword might be.

<?
include(“dbconnect.php”);

//
$keyword = trim($_GET['keyword']);
$keyword = mysql_real_escape_string($keyword);

// Finding the keyword in the database if it’s there
$sql = “SELECT * FROM keywords WHERE keyword = ‘$keyword’”;
$sql_out = mysql_query($sql);

if($sql_out){

$row = mysql_fetch_assoc($sql_out);
$id = $row['id']; //gets the id associated with the word
$sql = “UPDATE keywords SET count = count + 1″; // sql to increment the counter for that word
mysql_query($sql);

}else{

// This chunk puts our new word in the database and grabs it’s ID
$sql = “INSERT INTO keywords (keyword) VALUES (‘$keyword’)”; // sql to insert the new keyword we don’t have cataloged
mysql_query($sql);
$id = mysql_insert_id(); // gets the id of the record we just inserted.
}

// Here we’re redirecting to the end location with our replaced keyword with the new ID
$location = “Location: http://location.com/subid=$id”;
header($location);

?>

SQL for this is just a table is very simple. Just a 3 fields.

1. id set to primary key and auto-increment
2. keyword set to varchar 200 and indexed
3. count set to double no indexing

And that should do the trick….

This will take the incoming visitor and log the keyword, then redirect to the offer based with the subid for the keyword. This is a straight redirect bounce page with replacement keyword tracking.

Now if you want to track based on them coming to a site do two thing make your page based on php. and at the top put that same code, just remove the header and location lines. Then when you generate your page replace your links with with the $id so for example that php page would look like this.

<?
// previous code here minus the header redirect
?>

<h1> here is some text</h1>
<p> here more text and a <a href=”http://destination.com/subid=<? echo $id; ?>”>link</a><p>

now you’ll see we’re calling the php inline to echo the number we’ve retrieved from the keyword above. Then when you run that page in your browser you’ll see the id’s replaced :) pretty slick huh.

A couple ideas for this that could be added are geoip tracking and redirection based on the location of the visiting guest. Or how about finding out where your visitors are coming from? Do you know if you’re getting natural traffic? And if you do know, do you know where’s it coming from and which of those locations are converting for you? If you found a link to your site that was bringing a lot of nice traffic that was converting it might make sense to run a banner ad or something like that there wouldn’t it?

Tracking is Simple, Powerful and fun using a little PHP ingenuity.

another freebie from http://www.OOOFF.com