Categories: Miscellaneous

How To Dynamically Insert Affiliate Links or Track Referrals With Aweber

If you are looking to build an email list, and want to be able to use custom variables in the emails that you send out, then this guide is for you. Here are some example use cases:

  • Tag subscribers to affiliates, so that you can add their Clickbank hop ID to all your links, in all your future email broadcasts/autoresponders
  • Track total revenue based on where you acquired a subscriber. E.g. track Google Analytics variables by appending them to all future links that you email out

I chose Aweber because it is a great email marketing service that is very popular because of the advanced features that it allows.

One great feature is the fact that Aweber allows you to use custom variables, but many people don’t know or don’t use this feature. You should though, because this allows you to a lot of cool things. In this post, I’ll show you how you can automatically track who referred a subscriber to you, and insert their affiliate link in your emails. This is good to have for merchants, because you can run an email list on your sales page, and still get affiliates to wholeheartedly refer visitors to you still.

Requirements:

  1. PHP
  2. Aweber

To do this, you’ll need to setup a custom variable in Aweber. Let’s call it “ref”. Here’s a screenshot of where to do this in Aweber.

Now that you have a custom variable, we need to use it in our opt-in forms. The problem here though, is that the form builder in Aweber doesn’t allow you to insert PHP code (which is what we require for this to work).

So just create your opt-in form as per normal, but without the ref field (you’ll see it in the form builder). Now this is where things differ: when it asks you to publish as Javascript or HTML, choose HTML. Grab that code, stick it on your website where you want it, and paste this line of code right before the </form> tag. Remember to change the words YourDefaultRefGoesHere. This will set a default ref to use, just in case the visitor got to your form without a referrer (Thanks Mike!).

Note: A cookie-version of the code has been added (Thanks to Chris’s suggestion!). What it does is to cookie visitors, and then read the cookie when they visit your page again. Instructions within the text file.

  1. See the code here (txt file)
  2. Cookie-version of code here (txt file)

Alert: The only drawback for this method is unlike the Javascript method, you won’t be able to track impressions on your form. The benefit is that EVERYONE can view a HTML form, whereas some people may turn off Javascript support in their browsers, or have a browser that does not support Javascript, so they won’t be able to see your Javascript form.

Now that the form and variable is complete, we’ll need to actually use it. The following screenshot shows you how to do so. Simply create a broadcast or followup message as per normal, but click on the “Personalize” link, and choose your custom variable, as shown.

You’ll notice 2 variants of your variable listed, and here’s what they mean. For our case, we can just use the first version, which is {!custom ref}. These are basically the only two variants that you’ll be faced with:

  • {!custom variable_name}: Whatever information is stored in the variable_name custom field
  • {!custom_fix variable_name}: Whatever information is stored in the variable_name custom field, with the first letter of each word capitalized

After this, anyone who gets referred to your page like so: YourPage.php?ref=jack will automatically have “jack” stored into the custom variable of “ref”. In future, anytime you want to dynamically insert the referring affiliate, just use {!custom ref} in your emails.

An example link will be:

http://www.yourdomain.com/product.php?ref={!custom ref}

Viola. Now you can dynamically insert affiliate links in your emails or track referrals with Aweber! If you don’t already have Aweber, I highly recommend it because of the features and performance that it offers. The above technique is just one small feature that Aweber offers – think about Geo-targeting, or split-testing…just some more of the advanced features that Aweber offers.

Update: This works if you’re a Clickbank affiliate as well. Just change “ref” to “hop”, and you can use the following URL structure:

http://{!custom hop}.MERCHANT.hop.clickbank.net

Now your affiliates who refer visitors to your email list can continue earning their rightful commissions!

Alvin Poh

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world. Read more about my story here.

View Comments

  • Hi, this is an awesome post! I was trying to figure out how to do this for Clickbank hop codes and Aweber for ages.

    I've stumbled upon a problem with your code that I'm just not knowledgeable enough to fix right now though. If there is no hoplink, then the value recorded by Aweber is null, so when you email out your hoplinks via Aweber some of then will be http://.MERCHANT.hop.clickbank.net which is an invalid URL.

    Is there a way to set a default hoplink (like NONE) in the PHP instead of null?

    Thanks, Mike.

  • ah, good catch. there is a way actually, and i've updated the code with the changes (the form code that you have to put on your page). this will allow you to default to a certain hoplink when the referrer is null. Just look for the part that says YourDefaultRefGoesHere and change that to the default ref that you want :)

  • Hi Alvin,

    Thanks for the quick response!

    Unfortunately, I can't get your new code to work. At first I thought it was because of the quote symbols in the php code, but even after changing the "s to 's, my server just shows a blank page. :(

    Any ideas?

    Thanks, Mike.

  • Hi alvin I used the code exactly as you said but when i put in the {!custom ref} into my emails the value that it uses is a load of php code!

    This leads me to believe that the code is wrong somewhere.

    Do you have any ideas?

    Many Thanks

    Alex

    • From what you described, I'd say you're using the code on a HTML page. Use a PHP file instead to contain your form and you should be all set.

  • Great advice alvin i will try this. But how do I point to the php file from my html page?

    Ie what do I put into my html page to activate the php file.

    Many Thanks for your response alvin!

    Alex

  • Hi Alvin,
    Thanks for the code. Before I use it, does this violate aweber's terms of service. Here's what they said: "Submitting subscribers to AWeber via a server-side script (PHP, ASP, ColdFusion, etc.) is not permitted. "

    Since this is using a php code, is this in violation?

    Thanks!
    -Nick

    • Plenty of people use server scripts. Even the wordpress blog here is on PHP. The key is submitting subscribers. They don't want you to submit subscribers without their explicit consent (which you can do with scripts). Tracking referrals is perfectly fine.

Recent Posts

Best Protein Bar Review: Which Is The Healthiest Of Them All?

Protein bars have become the go-to snack for fitness enthusiasts, busy professionals, and health-conscious snackers…

2 days ago

What Salary Raise To Give Your Philippines Team

A salary raise can significantly enhance the motivation and loyalty of your Philippines team members.…

2 weeks ago

3 Myths About Venture Capital and Entrepreneurship

The narrative of young entrepreneurs securing vast sums from venture capitalists for their startups, particularly…

3 weeks ago

Ultimate List of Top 80 Sites to Submit Your Startup to Promote It in 2024

Launching a startup is challenging. Despite many founders having innovative ideas, only a handful successfully…

3 weeks ago

Why Retirement Isn’t What It’s Cut Out To Be

What is retirement after all? A better way of looking at retirement is that it’s…

1 month ago

Fix ElementsKit Mega Menu On Mobile Problems

ElementsKit has a very simple and easy-to-use Mega Menu for Elementor, but it has a…

7 months ago