Pinax

Anafero: a referral app


There are times when you have a publicly available site, so you don't need invites to join a private site. However, you would like to encourage users to tell people about your site and reward them for doing so. This is where anafero comes in as a referral app.

By hooking up anafero to your Django project, you can easily provide functionality for users to not only general referral links to your site but also to record activity to specific objects. In addition, there are hooks so that you can do things like award points to reward your users for the referral activity.

I am not going to rehash all the docs on installing and hooking the bits up but did want to illustrate a usage example.

Somewhere in a template in your project:

{% load anafero_tags %}

{% url my_named_url as myurl %}

{% create_referral myurl %}

and then in the footer or wherever you like to store your javascript:

$(function () {
    $("form.referral").each(function(i, e) {
        var form = $(e);
        options = {
            dataType: "json",
            success: function(data) {
                form.html('<input type="text" value="' + data.url + '" />');
                form.find("input[type=text]").select();
            }
        }
        form.ajaxForm(options);
    });
});

This JavaScript assumes the use of jQuery and jquery.form plugin.

That's all there is to it. A simple tag to display a form for creating a referral URL, and then a bit of JavaScript to submit and handle the response via AJAX.

Users will be able to then copy and paste and tweet out the code and when users click that link they'll be associated with the user that generated the link and events.

Again, there are more details in the documentation but hopefully this is enough to let you know about what anafero does.