How to track visitor in PHP

CWC
3 Min Read

From last one week one of my friend working on PHP site where he wanted to track partner pages and track from which partner page visitor comes and complete the transaction so that the partner get’s commission of transaction.

Track from same domain using cookies

The partner pages can set a cookie in the fact that the partner pages are on the same site is key. When the purchase occurs, the cookie will tell whether or which partner provided the referral. You will want to consider how to give credit when a purchaser has visited more than one of the partner pages and then makes a purchase, but that’s a business decision, not a technical one.

Here’s what you need to know:
http://php.net/manual/en/features.cookies.php

It can also tracked by using the $_SESSION variable.

Track from different domains by URL parameter

If there is any chance that the partner pages are not on the same site, then the correct design is to give every partner referral link a separate URL on your site. This will have a similar effect to adding a URL parameter, but it might be a little easier to follow in Google webmaster tools.

When a user clicks a link to an outside domain/website that link should include a referer. For example, if the referrer domain is xyz.com and your url is yourdomain.com/sales then the referer should program their link like so.

Click here

On your site you should parse out the arguments and look for the referer.

$referer = $_GET['referer'];

Then you will know where they came from. That is an easy way of doing it. There are other ways as well. PHP has a $_SERVER['HTTP_REFERER']

This is typically set in the request headers. They are sometimes empty though like if someone directly comes to your site by typing in the url then these will be empty. Also if someone accesses your site programmatically (cURL) they may be empty.

The easiest way is to ask your referrers to add the referer=xyz.com to the link.

TAGGED:
Share This Article
1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version