Buyer Referral Logger

Summary

This script was the solution to a problem posed to me. The goal was to keep track of how buying customers originally found the site. If a customer clicks on a banner ad one day and buys something two days later after clicking on a search engine listing, the script should remember and log the URL of the banner ad, the original referring source. The script should behave the same no matter what page the customer lands on. This script does not log the referring URLs of non-buying customers. It is only concerned with buying customers.

Demo

Instructions: I have created some dummy pages that act as a banner ad, a pay-per-click ad, and a search engine listing. When you click on one of the links on those pages, it will bring you to my Widgets Inc. page. Once you take that initial action, my script should remember that referring URL, even if you close your browser or click on one of the other referral sources. Eventually, you should click on Products and buy something. Once you do this, the original referring URL should be logged. You can click on the Referral Log to verify that the correct URL is logged.

Note: After you purchase something, you must delete the appropriate cookies and session variables if you want to test a different referring URL.

START DEMO HERE

Source Code

check_session.php - This file is included on ever page on the website. It checks to see if a session or a cookie has already been established. If not, it stores the referring URL in a cookie and a session variable.

log_purchase.php - This code is called once a customer purchases an item. It logs the referring URL that is stored in the cookie.

Future Development Possibilities