Friday, January 23, 2009

Creating Analystics Tool using coldfusion

Analytics tool using Coldfusion, ideally you can add your website to Google Analytics and monitor it, but if you are a provider which gives custom tools to the customer, then you might need to have a reporting section which includes the Analysis of KEYWORDS and location where visitors came from.

When someone searches using a keyword on some search ENGINE, then you can get the keyword from CGI variable HTTP_REFERER. Well there is no standard that is followed while passing the keyword, Google, MSN, Live, Alexa  passes it as "q=" in the http_referer, Yahoo passes it as "p=" and AOL passes it as "query=", some engines pass it along the like if you search for something on, then you will have http_referrer as

The second CGI variable that you will need is REMOTE_ADDR which will give you the IP of the location from where the visitor came from.

So our first step will be to get the KEYWORD and the Search Engine name from the Http_Referer, this can be done using REGULAR expressions and using REFind and MID string functions. Basically depending on your search engine, you find the occurrence of "q=", "p=" or "query=" and then URLDECODE the string to get the keyword.

So now you have the IP, KEYWORD and The Search Engine name. The next thing is you need to get the location from where the IP came from, I did some google work and came across the post from, the post is self explanatory and even has all the required files for you to get the location based on the IP address, and it is pretty accurate. You can download all the required files and just use the code as it is, also everything given on his post is free for download.

The next is you need is to map everything on GOOGLE maps, again you can find a custom tag for it on, this is pretty simple to use and has lots of examples to choose the configurations you need.

That gives you everything you need, Location, IP, search engine, keyword and a MAP.

I will be adding more enhancements to it and if you need the code to get the KEYWORDS and search engine, then just send me an email and I will send it across to you, although it is pretty simple.


No comments: