Pablo Varando's ColdFusion Blog

Tracking user clicks.... one way....

A few days ago a user on Easy asked a question about tracking users click through your site, like a breadcrumbs.... now naturally my suggestion was to insert a value to the database and then (based on the user's IP address) return back the data for display. This is still my favorite solution as it is quick and painless; the user however asked me to provide a solution that did not involve the database... so here goes nothing.... (disclaimer, use the database it's better and allows you to get data long term, but for a short timespan type thing this might help you... so I thought I'd post it.


Put this in your application.cfm or application.cfc
(onRequestStart).

<!--- create an application structure to track all
users --->

<cfparam name="application.clickStream"
default="#structNew()#" />

<!--- create an array in the structure for this user
(by ip) --->

<cfparam
name="application.clickStream['user_'&cgi.REMOTE_ADDR]"
default="#arrayNew(1)#" />


<!--- now insert this current page for this user --->
<cfset application.clickStream['user_'&cgi.REMOTE_ADDR][val(ar
rayLen(application.clickStream['user_'&cgi.REMOTE_ADDR]
)+1)] = cgi.SCRIPT_NAME /
>



<!--- THIS you can use to see the actual dump of all
users... --->


<cfdump var="#application.clickStream#" />

As mentioned before, the database is the best route; but this is one route you could go.

Comments
Robert Zehnder's Gravatar WhosOnCFC (http://whosoncfc.riaforge.org) does pretty much the same thing, it keeps track of all the sessions in server RAM. It is pretty easy to set up and offers some visualization for the data.
# Posted By Robert Zehnder | 3/15/10 8:55 AM
Mike's Gravatar Thanks for the advice. I'll bear it in mind while proceeding to my next project. Well, I've found some information about WhosOnCFC at rapidshare SE http://rapidpedia.com . Well, it is really worth considering.
# Posted By Mike | 5/4/10 7:34 AM
coach bags outlet's Gravatar I really like your article, I support your point of view
# Posted By coach bags outlet | 6/17/10 10:24 PM
myriaman's Gravatar Nice information, thank you very much to the author.
# Posted By myriaman | 7/14/10 11:55 PM
hulugo's Gravatar I really like your article, I support your point of view.
# Posted By hulugo | 7/15/10 11:15 PM