Free Affiliate PHP Script to Track Multiple Traffic Sources

The Magic Script Page

Note: if you’re not comfortable editing HTML and PHP, this might not be the best tracking option for you.

To try and make this easier to understand, I created a diagram of how it works:

Click to enlarge.

I’ll cover each of the five pieces of the diagram above in a second.

Basically, the way this works is, any time you’re driving traffic that could possibly lead to a sale… you’ll actually be sending that traffic to the “Magic Script Page”.

This single page tracking script really is magic. It can track a lot of the same metrics that many of the different paid online tracking software platforms charge decent money for.

All it takes is a little a technical know-how to get it uploaded and functioning. Now, since there’s no online user interface to go along with this, it’ll require you to do some manual spreadsheet work to get an overall view of your stats.

Lets take a closer look at how it works.

An Overview of the Mechanics

Ok, lets break down the diagram above.

#1: Drive Traffic

In this example, I demonstrated an ad campaign that’s driving traffic to a squeeze page. Instead of sending that traffic directly to the squeeze page though, I’m sending it to the script page which then forwards it on to its destination.

The script page first checks to see if they’ve already been “cookied” by me before. If not, then it automatically pulls in any data I add on to the end of my URL from my Facebook campaign. Normally things like: traffic source, campaign ID, and ad ID. I’ll explain later on how that all works but it basically takes that data and places cookies on the visitor’s computer so I know what ad they came from. More on that later.

#2: Redirecting to the Script Page

This is the first page in my new subscriber instant upsell funnel. After someone opts in for my lead magnet, they see this first upsell page. If they decide to click through to see the offer, they’re first sent to the script page once again (yes, the same exact script page).

The script page works the same every time no matter where the traffic is coming from. It checks to see if the visitor has already been “cookied”. If they haven’t, data is pulled in from the URL and cookies are then set.

#3: Sending the Visitor to the Destination Page

In this example, since the visitor has already landed on the script page once and cookies have already been set, the script page sees that and sends the visitor on their way to the destination page.

Except for one small difference. Since they’ve already been cookied, the script knows that you’re sending the visitor to an offer page and it appends their unique traffic data to the end of the destination page as a tracking ID.

In my case, I mostly promote Clickbank offers so my visitors’ unique traffic data is combined into one long string of text and added to the end of my Clickbank affiliate link as the tracking ID.

This happens in the background, all in a matter of milliseconds, without the visitor having the slightest clue. They’ll never see a Clickbank link or your tracking ID (unless they look at the bottom of the Clickbank shopping cart) and it won’t create any kind of bottlenecks in your funnels.

#4: Continuing On Through the Funnel

If the visitor decides to pass on the first upsell, they’re taken to the second upsell. Here they can click through to view the offer where they’ll follow the same path as #3, or they can pass again and then they’re shown the third upsell.

#5: Emails Get Redirected to the Script Page Too

This is the coolest part of this entire tracking hack. Since you’re “cookieing” people the moment they click on one of your ads, you don’t need to worry about what happens when you promote products via email.

All of that initial traffic data stays the same. If they decide to buy what you’re promoting, the sale will be attributed to that initial ad that they clicked on. All you have to do is first send your email traffic to the script page so it can append the “cookied” data.

Fun Facts About the Script Page

Here are a few cool features of the Magic Script Page:

  • It can be hosted on any domain and any hosting account as long as it can run PHP
  • It can be used on an unlimited number of domains
  • It can be used to track an unlimited number of domains
  • With the addition of a little code snippet you can add a retargeting pixel when a visitor clicks a specific link (you can do this for an unlimited number of links—it’s best used to set a retargeting pixel when a visitor clicks a link to view an offer you’re promoting)
  • Since the script page follows the first click attribution model, you can track lifetime sales per visitor (or subscriber) based on the first ad campaign link of yours they clicked on

Getting Started With the Setup

To start, I recommend registering a short domain name that you can use solely for tracking purposes. This is where you’ll upload the one-page tracking script. You can use the same domain as your funnel but then you’re kinda limited to just one domain for your tracking script page.

I like to register a domain name that’s somewhat generic so I can use it across many different affiliate niches.

For example, you could register the domain name ‘’. I recommend creating a folder on this domain where you can upload the tracking script to.

You could call the folder ‘track’. So, when linking to your tracking script page, the URL would be Make sure the tracking script filename is index.php so it loads automatically when someone visits that URL.

You’ll also need to install Google Analytics (which I’ll refer to as GA from now on) on all of your funnel pages — not on your tracking domain though.

We’ll be using GA to pull in traffic stats to use in our tracking spreadsheet. We’ll also use GA to track some click-through events in our new subscriber instant upsell funnel.

Once you have your tracking domain ready and GA installed on every funnel page, it’s time modify the Magic Script Page before you upload it.

Modifying the Magic Script Page

First off, you’ll need to download the Magic Script Page here…

Want to see the rest of this post? Get FREE access here »

You might also like

Leave A Reply

Your email address will not be published.