/****************************************************
     Author: Brian J Clifton
     Url: http://www.advanced-web-metrics.com/scripts
     This script is free to use as long as this info is left in
     
     DESCRIPTION: The script appends the first campaign/referral keyword to the last one stored
     i.e. last_referred_keyword, first_referred_keyword [***for urchin.js***]
     
     All scripts presented have been tested and validated by the author and are believed to be correct
     as of the date of publication or posting. The Google Analytics software on which they depend is 
     subject to change, however; and therefore no warranty is expressed or implied that they will
     work as described in the future. Always check the most current Google Analytics documentation.

Last update Sep-2009

****************************************************/
     
function checkFirst(){
	// check if this is a first time visitor, if so set flag
	newVisitor = 0;
	var myCookie = " " + document.cookie + ";";
	var searchName = "__utma=";
	var startOfCookie = myCookie.indexOf(searchName)
	
	if (startOfCookie == -1) {		// i.e. this is a first time visitor
		newVisitor = 1;
	}
}


function grabReferrer(){
	// if first visit, grab utmz cookie values and put in utmv
	if (newVisitor) {
		var z = _uGC(document.cookie, "__utmz=", ";");
		urchin_source = _uGC(z,"utmcsr=", "|");
		urchin_medium = _uGC(z,"utmcmd=", "|");
		urchin_term = _uGC(z,"utmctr=", "|");
		urchin_content = _uGC(z,"utmcct=", "|");
		gclid = _uGC(z,"utmgclid=", "|");
		if (gclid) {			urchin_source = "google";			urchin_medium = "cpc";		}		if (urchin_term != "-"){
			//var url = urchin_term.replace(/[^0-9|a-z|A-Z]/g, "_"); 
			term = urchin_term.replace(/%27/g, "'"); 
			term = urchin_term.replace(/%22/g, "'"); 
			term = urchin_term.replace(/\+/g, " "); 
			__utmSetVar(term);
		}
	}
}






































































