views:

48

answers:

3

I need to implement a very popular feature : displaying the number of views for a profile page.

For instance, my profile page in StackOverflow will display how many persons have viewed my profile (just under my reputation score).

I suppose that the algorithm is based on some cookies and/or visitor IP addresses. Is there a simple way (a plugin or some code source) to implement it in Grails running on tomcat/apache?

A: 

Why don't you use Google Analytics?

Júlio Santos
This is info to be displayed in real time in the website itself. Google analytics is 24h delayed AND how do you get statistics directly displayed and formatted on your own website?
fabien7474
Users won't really care if it's slightly delayed will they? (I think it's actually only a few hours). Analytics has a pretty good API: http://code.google.com/apis/analytics/docs/
leebutts
Actually. It seems a rather good idea. However Google Analytics API seems quite complicated. I'll give it a try
fabien7474
A: 

I have no idea about grail but general pattern is :

maintain a map in application scope when page hits increment appropriate field in it. make sure the concurrency issues should not be there.

org.life.java
How do you get the info that a page is 'hit'? Also, you do not store anything in persistent DB?
fabien7474
@fabien , I have no idea about your structure //arch. but you can conf a filter for the same. and yes ,you can schedule a job to persist that count.
org.life.java
+1  A: 

Check out the Clickstream plugin: http://grails.org/plugin/clickstream

I haven't used it directly but it's based on a library that I've used outside of Grails. We considered using the plugin for a project and I reviewed the implementation and it looked solid, but I ended up leaving the project.

This doesn't directly address your request but you could query the table that it creates, or borrow the logic that it uses to do a specialized implementation for tracking individual pages.

Burt Beckwith
I'll do it and let you know the results. Thx
fabien7474
BTW, I have already integrated ClickStream into my grails project but it appears to do some problems during production for URL mapping. We didn't have time to investigate the bug so we removed clickStream from the project
fabien7474