Home » Resources » Programming » PHP » Code Ascetic – SEO Tracking in 4 Lines of Code

Code Ascetic – SEO Tracking in 4 Lines of Code

No Comments PHP

I am going to save you all a bunch of headaches and time staring into the sky for the SEO God’s to grant you an effective way to track the conversion from traffic to lead. It is as simple as a few lines of PHP code. I am sure there are equivalents in the other server side scripting languages that someone can kindly post in a reply.

Here is the Snippet.

if (is_null($_COOKIE['referer']))
setcookie(“referer”, $_SERVER['HTTP_REFERER']);

if (is_null($_COOKIE['entrance']))
setcookie(“entrance”, $_SERVER['PHP_SELF']);

What does this do? It checks if there is a current cookie for both the website passed Referer value and if there is a landing page value. If not, it grabs the referer from the last website the person has been too (including organic google search) and the page that they landed on, for instance, index.htm or /affordable-health-insurance/ becomes the value of $_COOKIE['entrance']

An easy way to check how your cookies are being set is through this simple PHP Script.

You can save a file as test.php and include only the following code:

print_r($_COOKIE);

This prints the cookies you have set in order. Note: Most Dynamic CMS will already have a bunch of Cookies set that you can take advantage of once you figure out their name value through that smalls cript.

The key to web programming is being able to do the most actions with the least amount of code and processing cycles / memory usage. This is similar to being an code ascetic, the more you can go without will bring you to a state of efficiency not many can achieve.  Keep this method for your records! Keep this ideology in your coding!

Funny, I reduced this from 6 lines to 4 when i redid this Website and copied content over ;)

About the author

geilt has written 33 articles for Esotech Inc.

Archives
February 2012
M T W T F S S
« Jan    
 12345
6789101112
13141516171819
20212223242526
272829  
Latest Tweets