Oct 14 2009

How To Track Your Keywords With PHP & SUBID’s

  • (23) Comments. Got a say in it?
  • Published October 14th, 2009 in Affiliate Marketing by Dan
Learn the techniques I used to make over $4,000,000 in affiliate commissions! Check out my Free Affiliate Marketing Guide and learn the "how to" for Facebook Ads, PPC Affiliate Marketing, PPV / CPV Affiliate Marketing, And Media Buying!

Who's the guest?

Dan Walker has guest posted here a while back with his tutorial on htaccess tips and tricks. He was out of the affiliate game for a while but he's just jumped back in, check out dans blog to see what he's up to!

Hey Guys!

Hey again, good to be back, I love this blog =] Today we're going to look at something a little technical again as that's my field, but it's fantastic when used properly and can really help you tweak your campaigns.

Getting comfortable with SUBID's

Hopefully most of you know how subid's work and how useful they are, for those of you who don't here's a quick runthrough. At your affiliate network (my favorite is Azoogle, so we'll use them for our examples), you can see how many clicks, actions and often an eCPC with some other various data for each of your offers. With subid tracking we can make that information a bit more useful, for example we could add;

  • What keywords sent the click
  • Which search engine displayed the ad
  • Which ad was displayed
  • And more...

For our example we're going to pretend we have a landing page about halloween costumes. You've setup PPC campaigns with Google and Yahoo with various keywords that point to your landing page. Once on your landing page, you pre-sell to users and then send them on their way to your Azoogle affiliate link. Azoogle registers your click and then if the user completes a sale, Azoogle registers an action and you get paid. We all know this.

Now, wouldn't it be cool if Azoogle could tell you what we talked about above? It can! Normally by default, you don't pass a subid to Azoogle, so you just get the bog standard information. If we add more information, it'll show up. Knowing this, let's use it to track some of our keywords!

When someone clicks your ad, you can use dynamic tags in the link. What I mean by this is if your URL contains {keyword}, it will be replaced with whatever keywords brought up your ad. So if the user searched for 'cheap halloween costumes' then the url would go from this;

http://www.somelandingpage.com/?keywords={keyword}
to this
http://www.somelandingpage.com/?keywords=cheap%20halloween%20costumes

Awesome! So to set something like this up, we'd enter an URL like this in Yahoo SM;

Yahoo

Great, now our landing page gets our keywords. Now with a bit of PHP wizardry, we can pass these keywords to our network as subid's and have them show up in our network reports - let's crack on!

The PHP Part

I'm assuming a little PHP knowledge here, if you have none though you should be able to follow along. Our keywords should now be stored in $_GET['keywords']. Now we're going to put the keywords in our affiliate link so they get passed to the network.

It's important to know that each network handles subid's differently, for this post I'll be using Azoogle, they handle their subid's like this;

http://x.azjmp.com/12345?sub=subidgoeshere

That link above is your affiliate link, with the subid 'subidgoeshere'. Now thanks to the wonderful PHP, we can create this URL when the page loads, and append the keywords to the subid. At the top of your landing page (the file extension should be pagename.php) put this code;

<?PHP $subid = urlencode($_GET['keywords']); ?>

This code puts the keywords in a variable called $subid and makes it a little more secure. Now secondly, you want to replace all of your outbound affiliate links with this code;

<?PHP echo "http://x.azjmp.com/12345?sub=" . $subid; ?>

Obviously, replace the affiliate link with your own and this will print out your affiliate link with the keywords appended as a subid. Now when you check your reports at your network you should be able to track by keyword. Make sure you turn on subid's in your reports, in Azoogle you do this by pressing "Show Search Criteria" and clicking subid's.

Conclusion

I haven't wrote tutorials in quite a while, but hopefully you'll enjoy this one. If you found this one useful, let me know via the comments below and I'll follow up with a part two on how to make the URL's look a lot prettier and some other tips and tricks!

If you have any questions, again please comment below and I'll try my best to reply as soon as I can!

Dan

  • (23) Comments. Got a say in it?


Before you act upon this post, read this disclaimer.

23 Responses to “How To Track Your Keywords With PHP & SUBID’s”

  1. Greg says:

    Can this be applied to organic search traffic or does it just work with ppc?

  2. Buy My House says:

    Nice tips, this will helpful me!

  3. Wow, great! your tips are so nice.

  4. Paul says:

    This is great advice. I would love more info about making links better looking and possibly even encrypting keywords at the same time.

    If you could write a post about that, you’d rock!

  5. browie says:

    Good tutorial. I still love me some Prosper.

  6. Lee says:

    Hey Jonathan,

    The “proper” way to do this would be using urlencode() instead of htmlspecialchars().

    urlencode is designed specifically for sending data as a query in a URL, while htmlspecialchars is typically used for data that will be displayed as output where you don’t want HTML in the output.

  7. Mid says:

    Dan, Thanks for the info. I have two questions,

    If I am putting my landing page in a WP blog, which already has many posts and pages, and I am using one of these pages as a landing page, where should I add the code: Should I add it in page.php? in footer.php?

    The second question is… If I am also getting some organic traffic to my site, and this organic traffic (from a SE) makes the sale, is there any way of knowing which organic keyword made the sale with subid’s?

    Thanks for a great informative post!!

  8. ATV Auction says:

    This post is a real eye opener for me. I have always wanted to know more information about my affiliate sales. I had never thought of passing that kind of info through sub ids. Now I want to rush home and set this up. Thanks!

  9. Bart5QE says:

    This is great, I would like to see more technical posts along this line.

  10. You might not wanna pass on all your keywords to the affiliate network though, so if you wanna encrypt it you can use Smax0r’s old code that I posted a tutorial on here; http://profitapolis.com/featured/how-to-set-up-sub-id-encryption-with-a-php-redirect.html

  11. This is cool, looking forward to see your prettier URL post. Hope to see it soon, right?

    • Dan says:

      Hopefully soon =] Glad you enjoyed it, the prettier URL technique is pretty quick so I’ll probably post it as a quick tip rather than an in depth tutorial! Cheers, Dan.

      • Lee says:

        If you want to encrypt your keywords so that the affiliate network can’t see them (there are some dishonest ones out there who will steal your keywords), you can send an md5 encrypted version your keyword before sending it. You’ll also have to track/record every unencrypted keyword that gets encrypted (you will need this for decryption in the next step). Then, when you are viewing your subids that get sales, it will be an md5 hash. To find out what keyword this was, you’ll have to loop through all your keywords that you should have tracked/recorded (like I mentioned above), and compare the md5 value of it to your md5 subid. When they match up, that’s your keyword that got you the sale. You have to do it this way because md5 is one-way encryption. This would be the most secure way to make sure nobody knows your keywords but you!

        Enjoy :)

        • Dan says:

          One thing I’d note, and this is being paranoid, if you really don’t want your keywords stolen, when you use md5 use a salt too. With standard md5, a reverse lookup would be pretty easy and probably spit out your keywords. Good point though Lee =]

  12. [...] Jonathan Volk's blog for the second time, hopefully I'll be following it with a third soon! =] http://www.jonathanvolk.com/affiliate-marketing/track-keywords-php-subids.html No Comments – Be The First! Read the RSS [...]

  13. Steve says:

    I haven’t considered tracking the keyword in this way but it makes sense. I track the site and it is helpful to know where the conversions are coming from. But more data would be helpful.

  14. EID says:

    Your mailing listb is very googk

  15. Excellent information that you posted.Thanks for the ideas and tips.

  16. What if you are using a htaccess redirect on your affiliate links? Where do you place the php tracking code?

    For example, a link on my landing page is example.com/go/affiliatewebsite

    but in that folder is a redirect using my affiliate link.

    Should the code be like this:

    Get Free Widgets Here

    Or should it be in the htaccess file?

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>