How To Dynamically Insert Affiliate Links or Track Referrals With Aweber

Thu, May 27, 2010

Tutorials & Tips


Aweber 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!).

See the 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, 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}.

{!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 the “jack” put into the custom variable of “ref”, and 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 :D 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:

Tags: , , , , , , , , , , ,
, , , , , , , , , , ,

This post was written by:

- Alvin is a Singaporean who's interested in marketing, techy stuff and likes to just figure out how the two can work with each other. On top of his blog, you can also follow him on Twitter.

Get Alvin's Report On How To Blog Successfully - Free!

29 Comments For This Post

  1. Sherese Says:

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

  2. Alvin Poh Says:

    No problems!

  3. Thatcher Michelsen Says:

    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 Says:

    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 Says:

    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 Says:

    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.

  7. Alvin Says:

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

  8. Frank Says:

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

  9. alex Says:

    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

  10. Alvin Says:

    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.

  11. alex Says:

    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

  12. Alvin Says:

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

  13. Nick Says:

    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

  14. Alvin Says:

    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.

  15. Devendra Patel Says:

    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

  16. Alvin Says:

    @Devendra What’s the default value?

  17. Devendra Patel Says:

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

  18. Alvin Says:

    Sorry, but I don’t understand

  19. Devendra Patel Says:

    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

  20. Alvin Says:

    If you’re using my code exactly, then your variable name needs to be ref, not ap_id. e.g. http://www.fireyourboss90days.com?ref=psminc

  21. Nick Says:

    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

  22. Alvin Says:

    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.

  23. Devendra Patel Says:

    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

  24. Nick Says:

    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

  25. Alvin Says:

    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.

  26. Jolene Says:

    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

  27. Alvin Says:

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

  28. Hunter Says:

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

  29. Alvin Says:

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

Leave a Reply

*