Claim Your
Free Copy!

Enter your first name and email address below to get a FREE digital copy of...

the big book of internet income secrets

101 JOBLESS WAYS TO EARN INTERNET INCOME STARTING TODAY

When you claim your FREE digital copy of my book by submitting the form above, you’ll be added to my email list where you’ll receive sporadic email newsletters and promotional offers from me. Your information is 100% secure. View my Privacy Policy.

Duston McGroarty

Internet Entrepreneur

Subscribe to my youtube channel
Free Stuff to make you more money

Free Affiliate Link Tracking Script

Facebook
Twitter
LinkedIn
Pinterest

Over the course of my affiliate marketing career, I’ve tried just about every tracking platform out there. Including (but not limited to):

ClickMeter, Thrive Tracking, ClickMagick, Improvely, Google Analytics, LinkTrackr, CPVLab, AdtrackzGold, HyperTracker… and others that I just can’t remember right now.

These are all great solutions, for different reasons. But when I was just getting started as an affiliate all of these choices were overwhelming and confusing.

I really only wanted to track two or three things… traffic source, ad id, and keyword id (on search networks). I wanted to know which traffic source was generating commissions and the exact ad (and keyword) from that traffic source was responsible for generating those commissions.

What I found during my weeks worth of research and trial and error with these different tracking platforms was they all offered way too many “bells and whistles”.

Stuff the average, beginning affiliate marketer just doesn’t need. Things like rotators, split-testers, sales funnel tracking, link retargeting, 301 redirects, and more.

The average beginning affiliate just needs to know whether or not the money they’re spending on advertising is producing a positive ROI.

It seemed simple to me but all of these tracking platforms made it so damn difficult.

I decided to take matters into my own hands.

I like to do things my own way and make it as simple as possible. I also like to “code” stuff.

I’m a dork.

I know just enough PHP to be dangerous but also just enough to do what I needed to do.

I’m gonna show you two different ways to set this up… depending on if you’re direct linking (sending traffic straight to the affiliate offer) or if you’re sending it to your site first.

But first, lets look at how to edit the tracking script.

=> Click Here to Download the Tracking Script (zip file)

This is the same tracking I include in my Done For You Affiliate Websites.

How to Edit the Affiliate Tracking Link Script

Inside the index.php file there are two things you’ll need to edit… your Clickbank Affiliate ID (red below) and the Vendor ID (blue below) of the offer you’re promoting. Or, if you’re sending traffic to a different affiliate network, just replace that whole Clickbank link with your affiliate link.

$cblink = 'https://ENTERCBID.VENDORID.hop.clickbank.net/?';

That’s it. That’s really all you have to edit inside this file. Just be sure your affiliate link contains a question mark at the end or it ends with a Clickbank Page ID parameter like this:

$cblink = 'https://ENTERCBID.VENDORID.hop.clickbank.net/?pid=1';

Once you’re happy with your index.php tracking script, it’s time to decide whether you’ll be direct linking or sending traffic to your site.

Option #1: Direct Linking

When you’re direct linking, you can just download my Free Affiliate Link Tracking Script here, make the necessary changes, and upload it to a folder on your site.

Simple as that. Let me  explain how the script works.

The destination link that you put into an ad platform, lets us Bing for this example, is actually gonna be a link to this tracking script page.

This page pulls in some data from the URL using PHP, then redirects the user to your desired affiliate link.

Here’s an example of what your destination URL will look like:

https://yourdomainname.com/go/example/?cid=bing&adid={OrderItemId}

Lets break it down.

The first part, https://yourdomainname.com/go/example/, is the actual page you’re sending people to on your site. It’s the index.php page inside the ‘example’ folder which is inside the ‘go’ folder.

Next, are the two URL parameters that tell me where the traffic is coming from and also what keyword sent the traffic. The {OrderItemId} actually spits out an 11-digit keyword ID that’s generated by Bing.

Most traffic sources will provide URL placeholders like this that dynamically enter data into your URL when the visitor clicks your link. Some other placeholders you might want to use are ad id, campaign id, keyword phrase, and there are a lot more.

Back to the tracking script…

Using PHP code on the index.php page (the tracking script file that you downloaded above), you can pull those two URL parameters and attach them to the end of your Clickbank affiliate link and the finished URL will look like this:

https://yourclickbankid.vendorid.hop.clickbank.net/?tid=bingx39578093586

The index.php page does all of this in a matter of milliseconds and then redirects the visitor to the Clickbank offer. You can obviously use this for any affiliate network, not just Clickbank.

Could you just use a naked Clickbank link with your tracking ID at the end as the destination URL in Bing?

Yes. But it probably wouldn’t last long. Since you have to include a Display URL, it would be Clickbank.com and that wouldn’t really look good to the person searching.

The ‘tid’ in the URL above is Clickbank’s URL parameter for a tracking ID. That allows you to see in your reports which tracking ID led to a sale. And by including the Keyword ID in your tracking ID, you can see which keywords lead to sales.

Option #2: Tracking Traffic Through Your Site

This option is a bit more labor intensive but still fairly simple to understand and implement.

I actually learned this method by studying other super affiliates and analyzing their code.

I’m going to break this up even further, into two parts:

  1. Tracking traffic through a pre-sell page on your site
  2. Tracking traffic through list-building on your site

Tracking Traffic Using A Pre-Sell Page

In case you don’t know, a pre-sell page is a single landing page on your site where you send traffic to warm them up to the idea of your offer. Here’s an example of a pre-sell page.

The goal here is to get someone to read your pre-sell page and get them to click through to the offer. So, from a tracking perspective, what we need to do is pull in the same URL parameters from our traffic source and pass them along when the visitor clicks through.

Not too hard really. So, your destination link in your traffic source will be your pre-sell page with your two URL parameters added to the end like this:

https://yourdomainname.com/your-presell-page/?cid=bing&adid={OrderItemId}

Still with me? Good.

Since we need to pull in the URL parameters using PHP, your pre-sell page will have to be a PHP page. To pull in the parameters, add the following code to the very top of your PHP pre-sell page:

if( isset($_GET['cid']) ) {
$campaignID = $_GET['cid'];
}


if( isset($_GET['adid']) ) {
$adID = $_GET['adid'];
}

This block of code checks to see if those parameters are set and if they are, it pulls the values in and saves them.

The next thing you need to do is add the following block of code to the bottom of your PHP pre-sell page:

<?php

if( empty($campaignID) && empty($adID) ) {
// No parameters set
} elseif( empty($campaignID)) { ?>
<script>
$(".addparam").attr("href", function() {
return this.href "<?php echo '?adid=' . $adID; ?>";
});
</script>
<?php } elseif( empty($adID)) { ?>
<script>
$(".addparam").attr("href", function() {
return this.href "<?php echo '?cid=' . $campaignID; ?>";
});
</script>
<?php } else { ?>
<script>
$(".addparam").attr("href", function() {
return this.href "<?php echo '?cid=' . $campaignID . '&adid=' . $adID; ?>";
});
</script>
<?php } ?>

You don’t really need to know how this code works. Just understand it’s role. It pulls the saved data from the tracking link and adds it to the end of every hyperlink with the class of “addparam”.

So, you need to make sure that every link on your pre-sell page that clicks through to your offer has the class of “addparam” like this:

<a href="https://yourdomainname.com/go/example/" class="addparam">Click here to watch the video!</a>

Now, you can send all the traffic from your pre-sell page to your tracking link script that you configured above. It will automatically pull in the URL parameters and add them to your Clickbank link.

Tracking Traffic Through List-Building

Much like the example above, you’re gonna need to include all the same blocks of code on your squeeze page (or wherever you’re capturing visitor information).

What I’m going to show you how to do is take the URL parameters that we pull in using PHP and store them as custom fields in your email autoresponder program.

I use Aweber so I’ll be showing you how to do that with their form code.

To start, you’ll need the same PHP code at the top of your squeeze page to be able to pull in the URL parameters:

if( isset($_GET['cid']) ) {
$campaignID = $_GET['cid'];
}


if( isset($_GET['adid']) ) {
$adID = $_GET['adid'];
}

You don’t need the javascript code at the bottom though, since your goal is to have the visitor enter their email address and not click through somewhere else.

Instead, we need to take those saved values that we pulled in and insert them into hidden custom fields in our Aweber form.

In Aweber, they require you to manually create custom fields for whatever list you’re adding people to. You can do that by choosing the list at the top of your Aweber dashboard, then hover over Listing Options, and choose Custom Fields.

Then you need to grab your web form code. Here’s what that looks like without any styles:

<form method="post" class="af-form-wrapper" accept-charset="UTF-8" action="https://www.aweber.com/scripts/addlead.pl" >
<input type="hidden" name="meta_web_form_id" value="2046684592" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="evergreenniches" />
<input type="hidden" name="redirect" value="https://www.aweber.com/thankyou.htm?m=default" id="redirect_c98e5274140bb646e690b003c1f5c798" />
<input type="hidden" name="meta_adtracking" value="My_Web_Form" />
<input type="hidden" name="meta_message" value="1" />
<input type="hidden" name="meta_required" value="email" />
<input type="hidden" name="meta_tooltip" value="" />
<input class="text" id="awf_field-81415407" type="text" name="email" value="" tabindex="500" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " />
<input name="submit" id="af-submit-image-2046684592" type="image" class="image" style="background: none; max-width: 100%;" alt="Submit Form" src="https://aweber.com/images/forms/plain/buttons/grey.png" tabindex="501" />

</form>

What you need to do is add in two hidden custom fields. Here’s what those look like:

<input type="hidden" name="custom FIELDNAME" value="VALUE" />

Replace the word FIELDNAME with whatever you named your custom field inside of Aweber. You’ll need one for the CID and one for the ADID.

Then you’ll need to insert the values you pull in from the URL in these two hidden custom fields where you see the word VALUE.

Here’s what your final web form code will look like:

<form method="post" class="af-form-wrapper" accept-charset="UTF-8" action="https://www.aweber.com/scripts/addlead.pl" >
<input type="hidden" name="meta_web_form_id" value="2046684592" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="evergreenniches" />
<input type="hidden" name="redirect" value="https://www.aweber.com/thankyou.htm?m=default" id="redirect_c98e5274140bb646e690b003c1f5c798" />
<input type="hidden" name="meta_adtracking" value="My_Web_Form" />
<input type="hidden" name="meta_message" value="1" />
<input type="hidden" name="meta_required" value="email" />
<input type="hidden" name="meta_tooltip" value="" />
<input type="hidden" name="custom cid" value="<?php echo $campaignID; ?>" />
<input type="hidden" name="custom adid" value="<?php echo $adID; ?>" />
<input class="text" id="awf_field-81415407" type="text" name="email" value="" tabindex="500" onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " />
<input name="submit" id="af-submit-image-2046684592" type="image" class="image" style="background: none; max-width: 100%;" alt="Submit Form" src="https://aweber.com/images/forms/plain/buttons/grey.png" tabindex="501" />
</form>

You can see above where I highlighted the two hidden custom fields in blue. In red you’ll see how I inserted the values that we pulled from the URL parameters and in green are my custom field names.

Now, any time you link to an affiliate offer from an email, add these two custom fields to the end as URL parameters using the same method as above, send the traffic to your affiliate redirect page, and you’ll be able to track those sales back to the original source.

To use custom fields in an email inside Aweber, you can click the Personalize button and choose the custom field from the drop down list.

Just be sure you link to your redirect page and don’t use a Clickbank link directly in your email. It’ll get flagged as spam.

Hopefully this helps you in your journey to affiliate success!

Claim Your
Free Copy!

Enter your first name and email address below to get a FREE digital copy of...

the big book of internet income secrets

101 JOBLESS WAYS TO EARN INTERNET INCOME STARTING TODAY

When you claim your FREE digital copy of my book by submitting the form above, you’ll be added to my email list where you’ll receive sporadic email newsletters and promotional offers from me. Your information is 100%. View my Privacy Policy.

Duston McGroarty

Internet Entrepreneur

Subscribe to my youtube channel
Free Stuff to make you more money

Claim Your
Free Copy!

Enter your first name and email address below to get a FREE digital copy of...

the big book of internet income secrets

101 JOBLESS WAYS TO EARN INTERNET INCOME STARTING TODAY

When you claim your FREE digital copy of my book by submitting the form above, you’ll be added to my email list where you’ll receive sporadic email newsletters and promotional offers from me. Your information is 100% secure. View my Privacy Policy.

3 Responses

  1. Really good code. Thanks for sharing. I am in search for a php redirect script to put on my server. I saw your post and will add the code to my solution.

  2. Hi Duston, can we Traffic Using A Pre-Sell Page when traffic coming from Google Ads?

    Can’t find what to replace {OrderItemId} for Google Ads

    1. Google’s parameter for their keyword ID is {targetid}. You can also set up conversion tracking in Google and put your Google Ads Conversion Pixel inside your Clickbank account.

Leave a Reply

Your email address will not be published. Required fields are marked *