How To Dynamically Insert Affiliate Links or Track Referrals With Aweber

//How To Dynamically Insert Affiliate Links or Track Referrals With Aweber

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.

aweber creating a custom variable

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!

Similar Posts:

By |2014-12-30T14:48:41+00:00October 2nd, 2014|Tutorials & Tips|42 Comments

About the Author:

Alvin Poh lives in Singapore, and is interested in marketing, techy stuff, and likes to just figure out how the two can work with each other. He can also be found on Google+.

42 Comments

  1. Sherese August 11, 2010 at 5:58 pm - Reply

    you are the shit..thanks alot for the awesome info….

  2. Alvin Poh August 11, 2010 at 6:54 pm - Reply

    No problems!

  3. Thatcher Michelsen November 6, 2010 at 3:42 pm - Reply

    Bro! whats up man? Long time. I'm so glad I found your blog while looking for a solution to my desired dynamic aweber setup 😉 Let's catch up, get me on FB http://www.thatcher.tv

  4. Mike March 4, 2011 at 10:34 pm - Reply

    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.

  5. Alvin March 5, 2011 at 1:10 am - Reply

    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 🙂

  6. Mike March 5, 2011 at 11:19 am - Reply

    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.

    • Alvin March 5, 2011 at 11:41 am - Reply

      Hey Mike, I think there was a problem with the code. I’ve updated it – it should work now

  7. Frank March 29, 2011 at 2:55 pm - Reply

    Thank you! I’ve been searching for a solution for this for AGES.

  8. alex May 24, 2011 at 11:09 am - Reply

    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

    • Alvin May 24, 2011 at 12:04 pm - Reply

      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.

  9. alex May 25, 2011 at 5:27 am - Reply

    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

    • Alvin May 26, 2011 at 12:20 am - Reply

      A PHP document is a type of file. So instead of contact.html, you’ll have contact.php.

  10. Nick June 26, 2011 at 4:00 pm - Reply

    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

    • Alvin June 26, 2011 at 10:21 pm - Reply

      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.

  11. Devendra Patel July 1, 2011 at 6:54 am - Reply

    im struggling from last few days to achieve the same with Aweber and my capture pages but now working, it’s taking the default value only
    plz guide , thanks in advance

  12. Alvin July 1, 2011 at 9:39 am - Reply

    @Devendra What’s the default value?

  13. Devendra Patel July 1, 2011 at 1:10 pm - Reply

    in Aweber custom field always stored value i replace on “YourDefaultRefGoesHere” but it’s not capturing the actual Affilaite id from the link

    • Alvin July 1, 2011 at 8:24 pm - Reply

      Sorry, but I don’t understand

  14. Devendra Patel July 4, 2011 at 2:18 am - Reply

    Hi, ive applied perfect as per your instruction in Aweber and on my page [ i have replace only single value in script code i.e.=> else { echo ‘admin’; }

    Here Affiliate Link is http://www.fireyourboss90days.com?ap_id=psminc

    Aweber not inserting Affiliate id i.e. “psminc” but it always capture “admin”

    Please Guide to resolve

  15. Nick July 6, 2011 at 6:43 pm - Reply

    Alvin,
    Can you give us an example of using this code on an actual php page? One where we can view the source code so I can learn how to integrate aweber’s html form into php?

    Thanks,Nick

    • Alvin July 7, 2011 at 1:21 pm - Reply

      I don’t have one handy now, but a PHP page is just like a HTML page. In fact you can save a HTML page as a PHP page directly and see no difference. E.g. index.html -> index.php

      The only difference is that PHP pages allow you to run PHP code. Just put in the aweber HTML form into your page, save the page as a PHP file, and put the code (in the textfile in my post) just before the tag and you’re all set.

  16. Devendra Patel July 15, 2011 at 1:35 am - Reply

    Dear Alvin

    Thanks, Thanks a Lot again… it’s done.
    i created “ap_id” in Aweber Variable and it’s working well and capturing the Affiliate code in aweber.

    Regards,
    Devendra

  17. Nick July 26, 2011 at 12:34 pm - Reply

    Does the php code work for dynamic affiliate links that re-direct. For example, if some one clicks this link http://www.kickstartcart.com/app/?Clk=4274744 they get automatically redirected, say to this link: http://www.mysite.com where http://www.mysite.com is displayed in the address bar and the actual affiliate link is masked. Will that code still pull the “4274744” into the web form?

    Thanks,
    -Nick

    • Alvin July 26, 2011 at 1:16 pm - Reply

      Depends on how you do the redirection, because you can have the variables posted to the new page I think (I’m not that sure about redirections). Best way is to come up with a simple PHP script that just echoes out the code in place of the actual script, and see if that works in your scenario.

  18. Jolene September 22, 2011 at 1:25 pm - Reply

    Hi Alvin,

    When i’ve sent the “http://www.yourdomain.com/product.php?ref={!custom ref}” to my affiliates, they don’t see anything appearing on the custom ref portion of the url.

    Is it because i’ll have to manually add each one of their affiliate id into the aweber database one by one before it appears properly?

    Is there any way it can be done in an easier manner? generation of ids automatically when someone registers on the form.

    hope i’m making sense

    • Alvin September 22, 2011 at 10:31 pm - Reply

      Did you add the code (in the text file in my post)? That’s the trick that gives you the IDs dynamically.

  19. Hunter October 6, 2011 at 5:07 am - Reply

    For those affiliate marketers using Aweber, how have you satisfied the postal address requirement? Do you have a PO Box?

    • Alvin October 6, 2011 at 7:51 am - Reply

      Definitely a PO box or some other form of mail forwarding address, or your office. Your residential address should never be listed IMHO.

  20. Peter April 3, 2012 at 6:37 pm - Reply

    Hi Alvin,
    I have just found this post and wow, it’s just what I have been looking for, (I see it was posted a while ago but I hope you can still answer this)

    I have tried all the suggestions offered but I cannot seem to get it to work. I am using it on a wordpress site which I thought was PHP based but all I get in the ref field in aweber is the code

    any ideas why that might be?

    Thanks,

    • Alvin April 4, 2012 at 4:41 am - Reply

      Sounds like this is because of WordPress. Use a plugin that allows you to run PHP and see if that helps. I think ExecPHP is one such plugin.

  21. Peter April 4, 2012 at 11:19 am - Reply

    Brilliant.
    Thankyou Thankyou Thankyou.

    Works perfectly and solves a big problem for me.
    Thanks for sharing and keep up the great work.

    You are a star and I am a very hppy bunny.

    Will def refer others 🙂

    Peter

  22. biobanking April 26, 2012 at 6:49 am - Reply

    depends very much on how you do the redirection, because you can have the variables posted to the new page i suppose (I’m not that sure about redirections). Best way is to come up with a simple PHP wording note that just echoes out the code in place of the actual script, and see if that works in your scenario.

  23. Chris Mauric July 17, 2012 at 10:42 am - Reply

    Alvin,
    This code works fine as long as the visitor completes the form on the landing page. Once they leave and revisit, the ref code does not capture the id or if a default is set, it only captures the default id.

    Is there a way to add a cookie to this code?

    Thanks!

    • Alvin July 17, 2012 at 1:49 pm - Reply

      Added an update with the cookie code. Hope it helps.

  24. Pedro August 6, 2012 at 7:42 pm - Reply

    This is exactly what I was looking for!

    Thanks Alvin

    Btw, and if I want to store more than one var in that cookie?and make the Get action also for that new var

    Basically how to insert more vars in that code and get them to the gaps we want..

    I know the link will be something like this:

    ?ref={!custom ref}&var2={!custom var2}&var3={!custom var3}

    but don’t know the logical tags to insert in the php code…

    Thanks in advance

    • Alvin August 6, 2012 at 9:18 pm - Reply

      Yup the link that you came up with is correct. Just duplicate the PHP code that I’ve provided (and remember to create the variable in aweber as well)

  25. Nate November 3, 2012 at 10:34 am - Reply

    Thanks man, that cookie info was just what I was looking for!

  26. David March 7, 2013 at 12:24 pm - Reply

    Hi Alvin,

    Thanks for this post and this useful information.
    I took your code, but I’m trying to use a different way. Instead of taking an information from the URL, I want to take an information from a cookie. (Sometimes, people just short manually the URL before signup, and i’d like to avoid that)

    The affiliate ID is stored in a cookie, and can be return with a code like : or . Both of them are working, because when I put that code on a simple page, it displays the affiliate ID.

    But when it comes to put it in the “value” field, when someone signup, the custom field sent to aweber is the source code : , not the actual affiliate ID.

    Any idea of why this is happening and how to solve it ? Maybe some problem with PHP and Awebr … ?

    Thanks in advance for your help !

    • Alvin Poh March 7, 2013 at 12:29 pm - Reply

      : and . are pretty new to me – i haven’t seen any PHP codes using them before. If it’s PHP though, you can access cookie variables by $_COOKIE[“varnamehere”]. So you can add it to your HTML like so:

      value=”< ?PHP echo $_COOKIE["varnamehere"]; ?>“

  27. Lewi February 13, 2015 at 2:28 am - Reply

    Hi, great article and tip.

    In your instructions, where you say: “So just create your opt-in form as per normal, but without the ref field (you’ll see it in the form builder).”

    Does this mean I have to remove the ref field? Can you explain this a little more?

    Thanks in advance.

  28. Seth April 8, 2016 at 2:39 pm - Reply

    Hey Alvin,

    Thanks for this extensive tutorial – I’m not a coder and have been trying to figure this out with my WordPress site. I add the plugin your suggested but am still getting: in the “hop” field (I’m doing this for a Clickbank product).

    Do you think this is because the php isn’t executing?

    I was confused too by the directions — if you don’t need the “cookie” solution do you just add this line:

    <input name="custom ref" value="” type=”hidden” />

    to the aweber form and nothing else on the page, i.e. no php code on the page? Thanks for any insight.

Leave A Comment


*