I have this in place on every page to track where users found us from:

PHP Code:
$web_referal $_SERVER['HTTP_REFERER']; 
$web_referal parse_url($web_referal);
$web_referal['host'] != 'www.kranichs.com'){
$_SESSION['referal'] = $web_referal['scheme'].'://'.$web_referal['host'].$web_referal['path'].'?'.$web_referal['query'];
$_SESSION['tracking'] = $_GET['tracking'];
$_SESSION['tracking'] = 'none';

it works except if the first page the user hits on our site is a 301-re-route it gets lost

for instance:
if they go from google strait to page A and page A has a 301-re-route to page B....then the referal information gets lost.

I believe because page A is refered from google but never gets a change to run the code and gets directly re-routed to page B and then when page B runs the code it wasnt refered from google it was adjusted in the server...

Does anyone know how I can fix this?