CFLib.org – Common Function Library Project

GetGoogleKeywords(referer)

Last updated June 28, 2002

author

Matthew Fusfield

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This function will accept a http_referer and check to see if referer is from google.com. If so, it will return the keywords used for the search. If not, this function will return an empty string.

Return Values:
Returns a string.

Example:

<cfset ref1 = "http://www.google.com/search?hl=en&q=chinesezodiac&btnG=Google+Search">
<cfset ref2 = "http://www.google.com/search?hl=en&q=coldfusion+open+source">
<cfoutput>
Keywords from #ref1# = #GetGoogleKeywords(ref1)#<br>
Keywords from #ref2# = #GetGoogleKeywords(ref2)#<br>
</cfoutput>

Parameters:

Name Description Required
referer The referer string to check. Yes

Full UDF Source:

/**
 * Pass it a http_referer value and this fuction will parse out the keywords used to find it if referred from Google.
 * 
 * @param referer 	 The referer string to check. (Required)
 * @return Returns a string. 
 * @author Matthew Fusfield (matt@fus.net) 
 * @version 1, June 28, 2002 
 */
function getGoogleKeywords(referer) {
	
	var Keywords='';
	var StartPos=0;
	var EndString='';
	
	if (referer contains 'google.com') {
		StartPos=ReFindNoCase('q=.',referer);
	
		if (StartPos GT 0) {
			EndString=mid(referer,StartPos+2,Len(referer));
			Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
			Keywords=URLDecode(Keywords);
			}
		
		return Keywords;
	}
	else {
		return '';
	}
	
	
	
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson