Django: Implementing a Referral Program

I have an e-commerce website that works in a classic way: people register, buy a product using their CC.

It uses the standard Django authorization system for users, as well as the registration and session structure.

Now I want to implement a referral system in my system where people can invite other people by mysite.com/referral/123123/ their referral link (i.e. mysite.com/referral/123123/ ), and if a person signs up and buys an item, inviter gets $ 5.

How to implement this? For example:

  • After a new user logs into the site with a referral link, how can I track this user using a referrer? Saving session link?

  • What modification should I make for the django built-in user model to track these links and their links?

+7
django
source share
4 answers

Define a special set of URLs (in urls.py ) for referral links. Pass them through the Python function, which registers the referral, and then sends them to the regular view with the referral number as a parameter.

Is that what you had in mind, or what else would you like to know?

+4
source share

I did this a while ago and realized that my notes could help someone find this:

Create referral URLs

Whenever you send a referral address to your user, store it in a table. In my case, I had URLs for different purposes (“invite your friends”, “share this item”, etc.). Therefore, I also kept the type of referral. Add an entry point to your site, such as http://example.com/ref/jklejis , to handle the incoming URL. If you don’t like having an obvious “referral” URL, you can use middleware to simply grab the special url parameter on any URL to your website and handle it that way, i.e. http://example.com/items/123?r=jklejis

Tracked visitor

As soon as a visitor visits me from a referral, I set a cookie and any further requests from this user are tracked by a piece of middleware that tracks the actions in the table. Then I run a task to analyze the “action” table to issue loans to users. I didn’t have any requirements in real time here, but if you do, use a signal for specific actions to start your code.

I recently ran into this project, which seems to be still alpha, but it does something similar and can get started: http://pinax-referrals.readthedocs.org/en/latest/

+5
source share

You can use a very simple model to track them.

 class UserReferral(models.Model): referrer = models.ForeignKey(User) referred = models.ForeignKey(User) class Meta: unique_together = (('referrer', 'referred'),) 

Then you can calculate how much the user has indicated:

 UserReferral.objects.filter(referrer=user).count() 

Etc ..

+4
source share

Tracking a user session, especially after crossing the registration / login border, is a complex problem. I wrote a referrals app http://paltman.com/2012/08/17/how-to-easily-add-referrals-to-a-website/ .

+2
source share

All Articles