I’m going to continue down the road of sharing some of the coding knowledge I’ve been slowly picking up with my next Affiliate Hack – setting up your first tracking link.
The tracking link is perhaps the most fundamental piece of building your own tracker, as it’s the first tangible piece of your campaign as well as the last (you send a user to your page using a tracking link and then send them off to the offer via your tracking link). Rather than start from the beginning and write out a sequential guide to building a tracker, I’m just going to share what a basic tracking link looks like and how you can use it in your affiliate campaigns. Like I said the essence of all PHP trackers are built on this so it’s good knowledge to start with.
There are free trackers out there like Prosper202, but using your own tracking is challenging, rewarding, and can offer a more robust and customized product for yourself.
Split Testing Headlines with a Tracking Link
For this example I’m going to show you how you can test multiple headlines on your landing page and track which one leads to more sales. Say we have a page selling Printer Ink (hey that was big online in like 2006 remember?), and we want to test a few headlines at the top of our page and see how they perform. We want to test these 3 headlines:
- $49 Printer Ink Blowout!
- Cheap Brand Name Ink
- Clearance Sale on Ink (50% Off)
The first question is: How do we rotate these 3 headlines on our page? Which then follows up with the question Once they’re rotating, how do I actually track performance? Let’s break down each question:
How do we rotate these 3 headlines on our page?
This problem has a pretty easy solution with PHP using PHP arrays and a couple nifty functions. Here’s the code you’ll place at the very top of your landing page:
Let’s break down what we’re doing line by line:
The $h1-$h3 lines : These lines simply define the headlines we’re split testing. The first headline would be called with $h1 so that if you ran the code ‘echo $h1′, the screen would display “$49 Printer Ink Blowout!”.
The $headlines array : this is where we create the array (kind of like a container or bucket) to store our headlines. This is a multidimensional array (a bucket with a bucket inside of it) that initially complicates things a bit more but will save us time in the end. Our $headlines array contains 3 arrays within it, 1 for each headline. The individual arrays store two things, first ‘h1′, which is just the name we’re going to use to track the headline (you can make this whatever you want). That way when we run a report in our affiliate network, the subid will show up as “h1″ so that you know the sale came from that headline. The second part of the array stores the headline itself, which are the variables we defined at the top.
Setting the count ($c) : The next thing we’ll do to simplify our code is take a basic count of all of our headlines so that we can pick one randomly. The count($headlines) function will tell us that there are 3 headlines to pick from, we then add -1 at the end because arrays start with 0, meaning our headlines are actually 0,1,2 and not 1,2,3. The -1 tells $c that the count ends at 2 instead of 3 so that we don’t echo out a headline that doesn’t exist (blank).
Setting the $headline : Now we get to randomly select our headline. $headlines[rand(0,$c)]; tells us to first look at our $headlines array (which contains the split tests) and then select randomly between 0 and 2 (remember our headlines are 0,1,2 so we’re getting all 3 here).
Now we’ve randomly selected our headline! It’s time to use it. From the code above we’ve produced two tangible variables:
When you want to use the actual headline in your page and display it, simply paste this:
That’s going to pull our randomly selected headline array and echo the SECOND value, which is the headline itself (remember again arrays start with 0, so the second piece of the array has a 1 value). $headline will echo out ‘h1′, ‘h2′, or ‘h3′, depending on the random selection.
Once they’re rotating, how do I actually track performance?
Cool, now we’ve got a few headlines out there rotating to our customers. It’s time to actually track which ones are leading to clicks and sales, which is where our tracking link comes in. On your page, at some point you’re going to link to the affiliate offer, which very basically would look like this
We’re going to change that link to this
This is going to be the outbound tracking link you use on your call to action buttons, links, etc. You’ll see that we’re adding ?h= to the end of our URL…this will pass the subid for the headline (h1, h2, h3) to our redirect link. Now we have to build out the redirect.php so our customers get rerouted to the offer with the conversion data we’re testing for. The redirect.php file will look like
This one is nice and easy.
The $subid : Here we’re just pulling the ?h= from the landing page.
The $go : Now we build out our tracking link, which is just our affiliate link from before but now with $subid attached to the subid portion of the URL. Most affiliate networks have similar subid structure, either subid, s1, sub1, etc.
The header redirect : Once we have our affiliate link populated with a subid, we’re all good to send them off to the offer!
See, it wasn’t that hard was it? A few lines of code and you’re now testing multiple headlines (or images, or colors, or anything) and tracking which ones lead to clicks and sales. You can even compare CTR on the headlines very crudely by simply looking at how many clicks each subid receives in the affiliate network.
Once you understand the core concept of the tracking link, building out other elements of the tracker aren’t nearly as daunting as they might seem. Prosper202 and other trackers largely rely on what we just did – setting a variable to test and then tracking it via subid. In the exact same way you can rotate and test landing pages, offers, traffic sources, ad copy, and anything else you want to follow. The real fun comes when you want to compile all of the data and interface it for reporting.
As always, if there are holes in my code or things that could be more efficient, please comment so I can update.