1

I am working on a spring application in which I want to track the users time spent on each page. I am planning to do it via Spring filters. Is there a spring filter that intercepts each and every page request?

Or if you know any better ways of doing or an API that already does this which I can plug-in into my application - please suggest.

Abhishek
  • 6,862
  • 22
  • 62
  • 79
  • If the reason for this is "internet marketing" then you should do it via Google Analytics (or something similar). – cherouvim Dec 21 '11 at 07:07
  • Any server-side filter won't help you since you want to measure how much time a user spent on a page, not how much it took to load it/render it. See @cherouvim comment above. – Tomasz Nurkiewicz Dec 21 '11 at 07:12
  • @TomaszNurkiewicz: Well it's probably doable on the server as well by linking a pageview to a previous pageview (by also associating user by a cookie) and possibly losing the view time of the last clicked page. But this would be hard to get right especially if the reason for this is analytics. – cherouvim Dec 21 '11 at 07:18
  • @cherouvim No this is not for internet marketing, it is an internal application. The purpose is track the time spent by each user on different pages during the session(from log-in to log-out). – Abhishek Dec 21 '11 at 07:20
  • OK but note that you can still use analytics for internal applications. – cherouvim Dec 21 '11 at 07:36

1 Answers1

0

There is the Spring org.springframework.web.servlet.HandlerInterceptor interface. It is a normal bean with an special interface.

Read the Spring reference chapter 15.4.1 Intercepting requests - the HandlerInterceptor interface

The other (spring independend) way would be implmenting a servelt filter, but there you do not have spring support for example for easy access to other beans.

Ralph
  • 118,862
  • 56
  • 287
  • 383