|
 |
|
|
|
|
|
Ok I am posting my 2 day project here in the hope that it can be of some help to someone. This little bit of code could easily be adapted to do a variety of diff things. Enjoy everyone...
| CODE | <? //+******************************************************************+ // .:]Affiliate or Pay Per Click Marketing Cookie Tracker[:. | // Copyright 2004 Shannon Prue | // Use of this script is restricted Non-Commercial / Learning | // Only, If you would like to use this commercially mail me @ | // Inspiration AT gmail.com for permission. | // __________________________________________________________ | // This script in a nutshell will drop 3 cookies on a users | // computer when they arrive at your website, One to count | // number of visits the user has been to your website, | // One to specify how they found your site, and One to show | // what keywords were used to find your site. This info | // can later be extracted say during an order process to | // track marketing campaignes or track affiliate sales. | // I have added a debug mode to test the cookie proccess, as- | // well as added comments for easy adaptation. | // an example a url that would drop all 3 cookies is as | // follows: example.php?src=ov&kw=my+search+term | //+******************************************************************+ $visitcount = $HTTP_COOKIE_VARS["visits"]; $url = $HTTP_REFERER; $debug = 'true'; //debugger.... Leave blank to turn off debug mode // check if referrer is from inside site (so that it only drops the cookie once) if (preg_match("/yoursite.com/i", $url)) { $ignore = 'yes'; } else { $ignore = 'no'; } // end referrer check. // Decompile url variables to be placed into cookie if ($url == '') $url = 'Bookmark'; //if no referrer than must be direct or bookmarked. if($src == 'ov' & $ignore != 'yes') $url = 'Overture'; // edit to what you want to track if($src == 'google' & $ignore != 'yes') $url = 'Google'; // edit to what you want to track if($src == '' & $ignore != 'yes') $url = 'Natural Listing'; // edit to what you want to track // set Cookies & Count if not linked from internally if ($ignore != 'yes') { if( $visitcount == "") $visitcount = 1; // Start Counter (if cookie doesn't exist start at 1) else $visitcount++; // End Counter setcookie("visits",$visitcount,time()+60*60*24*365,'/','www.yoursite.com'); //Never Expires setcookie("referer",$url,time()+60*60*24*365,'/','www.yoursite.com'); //Never Expires setcookie("keywords",$kw,time()+60*60*24*365,'/','www.yoursite.com'); //Never Expires }// End set cookies // Start Debugger if ($debug == 'true') { if (isset($HTTP_COOKIE_VARS["visits"])) print "Visit Cookie Written<br>"; // Check Cookie else print "Visit Cookie Not Written<br>"; if (isset($HTTP_COOKIE_VARS["referer"])) print "Referer Cookie Written<br>"; // Check Cookie else print "Referer Cookie Not Written<br>"; if (isset($HTTP_COOKIE_VARS["keywords"])) print "Keywords Cookie Written<br>"; // Check Cookie else print "Keywords Cookie Not Written<br>"; print "This is visit number " . $visitcount; print "<br> You Come from: " . $url; print "<br> Linked from internal page? (Local Src) " . $ignore; // Testing Links.... for best results put these links on an external site print "<br><a href='cookie.php?src=ov&kw=testing+keywords'>link to test source and keywords</a><br>"; print "<a href='cookie.php?src=ov'>link to test source</a><br>"; print "<a href='cookie.php'>link to test no src & no keywords</a><br>"; }//End Debugger
?> |
|
|
|
|