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.


Tuesday, January 6, 2009

ActivEdit WYSIWYG editor -- "Must Be Contained in Form" Error

ActivEdit is now an open source WYSIWYG editor. I had used this editor long time back while working on Coldfusion 4.5.

ActivEdit was Closed source sometime back, recently it's source code is made available(also ActivMail, a JAVA based CFX tag is also open source now). I like this editor as it is pretty simple and works, but is not as advanced with features as FCKEditor or TinyMCE.

The Latest version of ActivEdit, if your DOM structure is not proper(As below) then you will get an error "ActivEdit Must be contained in a form" and also you will NOT BE able to save any changes you make.

For AcitvEdit to work properly, you should have the following structure


The above issue will occur with Firefox 3, Safari and Google Chrome.

Monday, January 5, 2009

Design Patterns -- Coldfusion

Sometime back while working on a project we came up with a system for reporting, at that time I got to learn and use some of the design patterns. I am describing them below

1. Facade(Structural Pattern) -- While creating a system, we come across an issue that the subsytem grows and it becomes complex with large number of smaller objects. As a solution of this, what needs to be done is, Introduce a single component that provides a simple API to the set of components within the subsystems. Applying this pattern we actually reduce coupling of the subsystems and the subsytem are managed as different pieces by their own components.

2. Front Controller(J2EE Presentation Tier) -- The second problem that we came across was to have every request follow the same logic(security, layout etc), well the solution is simple, just have all the request go through a common single file which decides how to process the request. So now we have centralized controller and this moves the logic from individual pages to the controller.

3. Data Access Object (J2EE Integration Tier) -- This helps you separate your data access from any business Logic. Basically DAO will have 4 methods a) Inserting Data b) updating data c) deleting data d) selecting data. Now you have to make minimal changes if you database changes from MySQL to Oracle or XML or anything else.

4. Factory (Creational Pattern) -- Just like factories in real life which creates things, the factory pattern job is to create other objects. So you can say it is an INTERFACE for creating an object. Then after creating an object, have the subclasses decide which class to call.

5. Dependency Injection -- In conventional method, if an object needs to gain access of a particular service, then either it holds a reference to the location of the service or has access to some service locator. In contrast, in DI, when an object is created a reference to an implementation of that type of service will automatically be injected. Why DI? - because it allows you to create alternative implementation of a given service type.

Then we also used security in the system by having all the files beginning with _(underscore) and adding small piece of code in Application.cfc file which did not allow to access files that begin with underscore. One of the other things used in the project was ERROR COLLECTION classes and a page which showed the errors.

References for above article a) b) c)