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

Affiliate Marketing, PHP Automation Coding 23 Comments »

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

Found a Great Design Patterns Book!

PHP Automation Coding 6 Comments »

First off for those of you who know me at all, you know I’m a huge advocate of learning. I consistently have a bare minimum of 3 books stacked on my nightstand ( sometimes gathering dust, but they’re there ). A book always in my car. Also usually 2-3 books when a travel. With my one goal of doing a little more research to try and pick up just one good idea that’s going to help my php coding, php architecture, marketing copy, negotiations skills, sales skills, motivation, etc etc etc and the list goes on. There’s a very famous quote that says

“If you’re not growing, You’re dying. ”

And I seriously believe this with all my heart. That’s one of my passions about this business is there’s always something else to learn. Whether to do with computers, marketing, sales, business, economics, etc. There’s always something to learn sometimes to my detriment. :)

Just a small background on myself. Back in August of2005 I knew nothing about computers, for the most part. I could muttle my way around Google and check my email. I even understood what a server was but really had no idea much beyond that. About this same time the company I was working for was about to go into bankruptcy so I got laid off and decided I was going to make a go at another off-line business I was already working part time. Now though the plan was to promote it on the internet full steam.

So after messing around with some SEO, buying a few scripts and reading a couple ebooks I decided I really NEEDED to learn to code. It always seemed like the scripts I bought just needed a few more peices for automation. Or the tracking scripts weren’t quite right. Once I decided that I was going to take the leap and teach myself to speak computer I tried to figure out what language would be the best. Because I had an Excel spreadsheet course in college that delved a tad bit into the VB side I decided to jump into that first. WELL VB sucked for what I wanted to do so I shifted over to PHP. [ sidenote - you ever feel like you’re on a tangent? that’s what I feel like right now. ]

So lets fast forward to the end of last year. I’d been working this business full time for about a year and had picked up some PHP skills through books, trial and error and about 14 hours a day of time. Keep in mind I knew NO ONE in this business at all that could help me forthe most part. I got a little help from the guys in #RSSGM on freenode but not much. By the end of the year I could hack a script together pretty well and could understand most other peoples code. Most of the stuff I wrote really looked like spaghetti was a nightmare to alter, update or maintain. You know what I’m talking about right? Where there’s a couple functions at best! And the rest of the code is like 300-500 lines of all procedural…. Have you ever tried to change or maintain something like that?

As you know things in in the Internet Marketing business can change rather quickly. Let’s say you have a Squidoo lense builder. Today it could work tomorrow they could change the whole thing. Or maybe you built the system around a niche and then you found out another niche was very profitable as well. How hard is it to change your scripts that involve building, research, tracking, interaction with the providers, etc etc. It’s a pain isn’t it if all your code is procedural.

The other thing I was beginning to notice at this time was that I was writing the same code again and again. Think about this for a second. What are some common themes to building an account on something like Blogger or Squidoo. Is there commonalities among those? You betcha! So rather the rewriting your code over and over again I figured there must be some way to make my code reusable or at least build a basic framework for things that I was doing repetitively. Because I’ll be honest with you I really enjoy making the interaction classes. Doing things like tracing headers and figuring out nuances of how to reverse engineer a website or web service. That part is fun to me. However once you have all your interaction classes built, making the management side is usually pretty boring in comparison.

Code architecture… what the fuck is that? That’s what I was asking myself when I first started looking into it. Now keep in mind I’m just a businessman that’s decided to learn how to code out of seeing a great profit potential. I’m as far from a coder as one could possibly get. Or at least was. I think I’m getting closer and closer to being a real coder everyday ( not sure if that’s good or bad ). But that strictly comes out of necessity for building bigger and bigger systems. Now keep in mind this isn’t Windows XP we’re talking about. But the systems I’m building do seem to get larger and more elaborate all the time. Because of this I’ve forced myself to switch to Object Oriented Programming which I knew nothing about 6 months ago.

So back to those books I was talking about in the beginning. I buy at least 2 books a month if not a lot more. Was wasting some time today and went to Borders Bookstore. knowing I really want to learn code architecture basics I’ve been snapping up quite a few books about object oriented coding, design patterns, UML, and Use Cases in order to find one that might help me get one more good idea and put the puzzle pieces into place just a touch more. Typically I’ve been having to buy books that revolve around Java as most architecture stuff is written for Java or C/C#. Java really isn’t hard to understand once you have a firm understanding of how the OOP basics work in PHP.

So at the bookstore I made a couple of purchases today but there’s one I’m really stoked about. and that’s ( drum roll please )

“Design Patterns for Dummies” - Steve Holzne, PhD.

Now, laugh all you want and talk shit all you want but I’ll be straight forward with yah. I’m not the smartest tool in the shed and a lot of times I need things broken down into Engrish ( for you DigitalPoint guys ), especially tech stuff, as that’s not how I think usually. I’m a huge advocate of the for Dummies series yes some of them really do suck. But I’ve bought every non-Dummies book I could get my hands on about design patterns ( probably about 5 - 9 books ) and just haven’t been able to wrap my head around things. Some people just get it, some people don’t. I think I’m one of the ones that don’t. Persistence is the one attribute I do have though, if I really want to do or learn something there’s not much that’s going to stop me. I know some of you have looked at my suggestions for learning PHP and really the for Dummies books are excellent if you just don’t get it or need things broken down and simplified just a little more. Design patterns are a fairly hard concept in my opinion, especially real composition. However there’s some really cool stuff you can do with them that will save you a TON of time in the long run.

On that note I’ve been looking for a good pattern for sometime that I could use to interface a lot of sites that all do similar things. Lets take making blog posts for example. We all know not all public hosted blog sources support XMLRPC. Therefore we might need to do XMLRPC posts to some, form posts to others and maybe email posts to other still. Now just for fun lets say we had 50 different hosts, all places we could host blogs for free.

How could we go about designing a system in such a way that we could treat them all the same and handle them all the same way from a management side?

And really encapsulate the specific functionality of each to be maintained separately?

What are some of the things that might be in common between them? Login(), Post(), UpdateBlogroll()?

Wouldn’t it be cool to be able to treat all these different hosts the same from the prospective of the management layer? Well check out the Factory pattern it might be what you’re looking for…

How To make a Script to check your Affiliate Landing Page is UP!!!!

Affiliate Marketing 13 Comments »

It’s midnight on Tuesday and all of a sudden the offer you were promoting isn’t working anymore!

Have you ever had this happen to you? There’s nothing worse then paying for clicks that aren’t going anywhere. Especially if those are 2-3$ clicks for a niche like mortgage or payday loans. You call your affiliate manager the next day, or even worse don’t notice for a few days, and ask them “hey what happened to xyz campaign?” Do you know what the words out of their mouth are always? “Oh I sent you an email…” but some how it ended up in your spam box or you didn’t pay attention as you get lots of emails from all the affiliate companies every day.

Now what if you had a way to make sure your offers were working and you had control rather then waiting for someone else to alert you? In this example we’re going to make it so that the alert comes to your email but of course this could be adapted to instant messenger, a text message, or any other communication device with a little finessing.

In all these tutorials I’m going to assume you’ve at least coverered the intial tutorials on OOOFF.com on how to do some scraping and parsing of data. If you haven’t please go read the php screen scraping and parsing tutorials.

First step in solving this problem is we need to make a simple script that will go request the affiliate’s landing page you’re promoting. To do that we’ll just use the file_get_contents() function which we know is going to go grab the data from a file or website based on a string we put into the parameters. Then we’re going to assign that to a variable or holder called $page. If you don’t know a $ always indicates a variable. Then lastly we’ll echo the contents that we reach out and grabbed using the echo statement which just echo’s what is in the variable $page to the screen. Here’s what your code should look like.

<?

$page = file_get_contents(”http://www.oooff.com”);
echo $page;

?>

I invite you to make a little text file on your server and called: offer_check.php and putting the lines of code above in it. Of course you’re going to want to replace your destination url with an actual url of your affiliate company. However now comes the bad news. As most offers bounce through a redirect url this simple file_get_contents() function isn’t going to work for most things. However I just wanted to start with it. Now we’re going to a little more robust library and start to use curl. So if we were to do that exact same thing again but this time using curl it would look like this.

<?

$ch = curl_init( “http://www.mylandingpage.com/offer/affid” );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
echo $page;

?>

Most of this is fairly intuitive however there’s a couple of things I’d like touch on. With the Curl library we have the option of setting different things we want to do where the file_get_contents() is only going to request a single page. So if they link goes to Copeac then bounces to the affilliate landing page nothing is going to be returned by file_get_contents() because it will only get the first redirect page. Now we could manually parse and follow each redirect however it’s much simpler to just use Curl who’ll follow the redirects automatically for us if we set the right options.

As you probably guessed the easiest way you set a url in Curl is in the initialization statement. Then we’re assigning that initialized object to the variable $ch. However we haven’t done anything with it yet, this hasn’t requested the page. This just made a container to set some options in. To set those options I’m sure you saw the function curl_setopt() basically it takes arguments of the object/variable holding the contatiner, $ch in this case, to set options on. The second parameter is the option we want to set. We’re setting 2 in this example:

  • CURLOPT_FOLLOWLOCATION - Follows redirects automatically
  • CURLOPT_RETURNTRANSFER - Returns the page output to a variable

So in a nutshell we’re initalizing a container and setting the variable for the url inside that container to the url of our affilaite program. Then we’re telling Curl to automatically follow all redirects to the final destination. Next we say hey don’t just do this but return the page to me so I can do some stuff with it. Curl_exec() pulls does the actual work based on all the options we’ve set in the container and returns that data to the var $page.

Now as long as Curl is enabled on your server or where ever you run your PHP scripts you’re going to get the actual page affilaite page back even if there’s a redirect. I strongly encourage you to take this code and put it on your server and run it. Make sure it works before we go on to the next step.

Now that we have our offer page in the variable $page and we need to find someway to check whether it is up or not. Being that we have the actual source code of the page lets look for something we could check for. For this example we’ll go back to using the homepage of oooff.com. Now direct your browser to oooff.com. After taking a look around I decided the thing most likely to change is the title of the page. So I grabbed the words “PHP Scraping Tutorials” and decided if those didn’t show up then there was something wrong with the landing page. The checking script is going to look like this.

<?

$url = “http://www.mylandingpage.com/offer/affid” ;
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);

if(strchr($page,”PHP Scraping Tutorials”)){
echo “still works!”;
}else{
mail(”email@oooff.com”,”Offer is down”,”The offer $url is down.”);
}

?>

The quick and dirty on the second part is it’s saying if this to this, if not this then do something else. What we’re doing is in our if statement we’re using the function strchr() which returns a number for the first position of our string. Guess what happens if there’s no match? That’s right it returns null. In which case the initial if() isn’t true so it moves on to the else. At which time the script emails you to the email you enter, with the subject “Offer is down” and then body “The offer http://www.mylandingpage.com/offer/affid is down.” Now you can manually go check if this is working or not. And if not pause your campaigns until it comes back up or you can talk to an affiliate manager.

The last part of this is to set it to run on a cron or timer automatically. In linux as that’s the OS i use you set a cron using >crontab -e where the -e is for edit. I suggest running this every 10 minutes so you’ll want to enter a line that reads:

*/10 * * * * /home/username/scripts/offer_check.php

Now of course this location is going to be for where ever your script is located on your server. What this will do is run the script and check whether your offers are up ever 10 minutes. And email you if your offers are down.

One quick addition to make this simpler to manage would be to add a second text file to hold the list of offers and matching strings. It would look something like this:

offers.txt

http://www.url1.com/locaiton,text to check
http://www.url2.com/2ndlocation,more text to check

offer_check.php

<?
$lines = file(”offers.txt”);
foreach($lines as $line){

$parts = explode(”,”,$line);

$url = trim($parts[0]);
$search_string = trim($parts[1]);

$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);

if(strchr($page,$search_string){
echo “still works!<br />”;
}else{
mail(”email@oooff.com”,”Offer is down”,”The offer $url is down.”);
}

}

?>

( If you take this code and copy it the double quotes do something funny. Make sure you replace them with real double quotes. )

Quickly this takes the lines from a file and loads them into an array. After that it loops through each of the lines in the array. Then splits those array’s based on a comma as that’s the format we used for our file. At which time it tests all the conditions just like we did for the single one.

I hope this tutorial helps you save some money in affiliate marketing with offers that have been canceled that you don’t know about. This way you can pause or redirect your google adwords campaigns, CPM buys or where ever else your traffic comes from.

Did you get some good information from this Post? If you did, would you do me a favor and link to it?

10 Minute - Ebay, YouTube & Amazon Mashup site

General No Comments »

Found this while doing some reasearch on google and thought I’d share. This is just a simple example of how you can make a site that looks amazing with just a few api’s. There’s a lot of API information out there and some good mashup api resource sites. Add a little of your own content and you should have a nice site where anything they click on you’re going to get paid for if they follow through.

10 minute Ebay, Amazon and Youtube Mashup Site

Hope you like it.

SQUIRT Link Building Automater….

PHP Automation Coding 1 Comment »

As most of you know I wrote a tool to automate submissions to SQUIRT, BluehatSEO’s ( Eli’s ) automated link building tool What the script I wrote allows you to do is que a list of domains in a file so you don’t have to go the the site and make submissions everyday. I’ve read on a lot of boards that people were having some issues with it and just wanted to let you know if you’re having trouble please leave your questions here. I tested it again yesterday and it seems to work just fine on my server so maybe you have something configured incorrectly. Some things to check:

  1. Is your cookie dir writable?
  2. Do you have your root directory set right?
  3. Does your cookie dir exist?

Let me know~!

New tutorial on Filling Forms using PHP added

PHP Automation Coding 1 Comment »

Sorry for the long delay in between tutorials. Looks like about a month and a half. With the summer time here there’s a lot going on non-work related. So if you’ve been waiting for the first newbie tutorial on how to post data to forms using PHP, it’s here!

Basic PHP Form Fill Tutorial

Please let me know what you think. I tried to cover all the steps from start to finish on posting to a form using Curl and PHP. If you have any suggestion to add to the tutorial please leave them here. Keeping in mind this is a super basic all for beginner tutorial. Good Luck!

Welcome to the OOOFF.com Blog….

General 3 Comments »

In an effort to let everyone who’s intersted in coding for SEO and Affiliate marketing with a HEAVY emphasis on PHP coding have a voice I decided to setup a blog so that others could

  • leave comments
  • ask questions
  • make connections
  • respond to what was being posted on OFFF.com for tutorials

I’ll try and post on a weekly basis but no promises. This will definately be easier then make a new page each time I want to post something new on the site. As there’s constantly news and good information I’m finding everyday.

I look forward and appreaciate your readership.

Success!