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 '';
    }
    
    
    
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson