Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really Simple Affiliate Program

Tags:

php

I'm pretty new to PHP and MySQL. I'm interested in setting up a very simple affiliate program. It basically needs to be setup so that when someone clicks on the affiliate link it stays with the user until he/she signs up with my website.

So for example, I want to create some nice looking webpages that my affiliates could use to advertise my site. The URLs would look something like this (ideally). www.mysite.com/splash1.php?userid=Joe

So in this case, my affiliate, Joe, could use www.mysite.com/splash1.php and append ?userid=Joe and he would have an affiliate link.

From here, people could click on the link in this splash page which would bring them to the home page for my website and retain that affiliate ID. Also, if the user decides to browse around my site before signing up, I would like to make sure the affiliate ID sticks with the user throughout until he/she decides to signup.

I'm familiar with reading in the userid from the URL just not to familiar with how, best to pass that userid variable from page to page.

I'm not to concerned at this point with all the functions that come into play with the affiliate program, like comissions, showing affiliate stats, and all the other fancy stuff. I just want to make sure the persons affiliate ID sticks with the user up to the point he/she clicks "submit" to signup for my website.

I know I'm going to probably have to use cookies and/or sessions. just not sure which route to go.

like image 981
Charlie Avatar asked Dec 27 '22 21:12

Charlie


2 Answers

Building affiliate software is no small undertaking, especially for someone who is new to both PHP and MySQL. You could debate the implementations all day long, but basically the steps for how the program works are something like this:

  1. User clicks link
  2. You write cookie to user, and redirect that user to the "client." We'll use the term client to refer to the person or company that is actually doing something with your user. You will typically want to add something to the URL since you can't write cookies for a domain the user is not on, and you (or other sites) can not access cookies written for another domain. (This is Browser Security Protocol).

    After this point, you will need some kind of relationship with the client, so you can tell them what data they should be looking for in order to identify a user coming for an affiliate, and know that they have to send that back to you.

  3. You then have to set up a way for your client to tell you that the user has completed a registration (or whatever other action is required, often called a conversion).

The process itself is pretty simple, it's just a lot of data tracking. You essentially just need to be able to track any single conversion back to a specific click, and identify where it came from to give the appropriate affiliate credit. To do this, all you need to do is be a middle-man between the click and the redirect to the client, and add something to the URL so the client can tell you if that unique ID converted.

If you need to identify unique users within your system, outside of the client and across multiple affiliates, that's when you'd deploy cookies. Sessions are useless, because they are also a cookie - but are much more temporal and get destroyed with the browser exits.

If you are writing the client code (basically, accepting users from affiliates) you will want to initialize a long-term cookie (or a short term session, it depends on how much "time" you want to give your affiliate to get credit for a user which clicks their link). Once the user completes the action you want them to complete (converts) you tell the affiliate provider about it (using the unique ID they gave you) and they handle giving credit back to the affiliate.

I hope that all make sense, and hopefully sheds some light / gets you started in the right direction. Like I said, a marginally difficult first project for a novice, but certainly not impossible. Good luck.

like image 127
Jim Rubenstein Avatar answered Dec 30 '22 09:12

Jim Rubenstein


When an affiliated link comes in, store that affiliate in a session variable. Any common header code that you have could easily deal with an affiliated link coming through onto any page in the site and store it appropriately.

The session will stay with the user as they move from page to page and whenever they find their way to your registration form (or any other place you need to know what affiliate they came through) just look in the session (and also the GET variables just to be safe).

Using the session won't require any URL changes or messy trickery where every link would need to have the affiliate ID appended to it, and also doesn't slow the browser down by sending extra data with every request or have as many security issues as using a cookie.

like image 29
cdeszaq Avatar answered Dec 30 '22 11:12

cdeszaq