Tracking Users with a Serverlet -- Need help

OK, I really need help with this one. First, the problem: I need to be able to track where users go on our site, and depending upon the number of pages they visit before leaving, They will recieve one of three or four questionnaires.

Second problem: Obviously, the easiest way to do this would be by using a cookie, and having every page click a counter in the cookie. Unfortunately, most of our users are Organizations that do not accept cookies. Also, our site has over 1,100 public pages, and adding javascript to every page would be a pain.

I figured the best way would be to run a serverlet that opens a new thread whenever a user connects. At most there would be 100 threads open at any given time. While the user is connected, the thread would store every URL the user goes to in a Vector. If the URL does not begin with our domain name, then it will open one of the questionnaires, and close the Thread.

Please let me know if this is possible, and if so, how would I go about doing it.

Thanks

RC

[1041 byte] By [rchargel] at [2007-9-27 19:11:34]
# 1
Com'on people, I really need help on this one.
rchargel at 2007-7-6 21:36:35 > top of Java-index,Archived Forums,Java Programming...
# 2

I'm assuming you have some sort of authentication so that your users have to sign in, right? Otherwise, how are you going to know when they return?

Anyway, to do what you're trying to do, you could set a db with a table with 2 columns, user and pages. You pass the pages the user has been to by using a request variable, and then save the value with every new page request.

tjacobs01 at 2007-7-6 21:36:36 > top of Java-index,Archived Forums,Java Programming...
# 3
Unfortunately, we do not use logins. What we are trying to do is give them the survey before they leave our site, not when they return. Basically, I wanted to see if there was a way to see if the URL they are requesting is not ours, and if not, to throw up the survey and close the Thread
rchargel at 2007-7-6 21:36:36 > top of Java-index,Archived Forums,Java Programming...
# 4

Nothing you do on your server will help you tell when the user goes to some other URL. The browser won't tell you that because it's none of your business. You could perhaps use some Javascript on your page, but I can't guarantee that because I'm no Javascript expert.

Have you considered that this is a good way to annoy your users? Put yourself in their place: you have just been using somebody's site. You try to go to Hotmail to get your e-mail, but instead of going there you're sent somewhere else to fill in some stupid survey...

DrClap at 2007-7-6 21:36:36 > top of Java-index,Archived Forums,Java Programming...
# 5
I agree with you, but I am not the boss. In fact, I was hoping you would tell me it is impossible, that way I won't have to do it. :)
rchargel at 2007-7-6 21:36:36 > top of Java-index,Archived Forums,Java Programming...
# 6

The 1st thing you need is some sort of session tracking. This is problematic if the user does not accept cookies. The JSP/Servlet spec provides a method called URL re-writing. This is setup in the container. Basically what it does is create a session using information stored in the URL. You can then store a counter in the session object on each page. If you have static HTML files, they need to be converted to JSP files with some code to increment the counter at the top. This can be done via include where the include file contains the counter increment. The include file may also conditionally contain the Javascript code that does the redirection to the survey page. Another way to accomplish this is to alter all of the hyperlinks on you're site to route through a servlet which will increment the counter and redirect them to the page passed as a querystring parameter. This way you wouldn't need to change static HTML to JSP. If you had links to outside sites you could detect them in the servlet and respond with the survey page accordingly. The only hole would be if the user either closed their browser prematurely or keyed an address in the URL address bar. You may be able to trap for this via Javascript using the onUnload event to open a new window that checks the parent window's location. If the location of the parent is not within your site the new window could present the survey otherwise it could just close itself. This may not be a clean approach but it's an option.

Cliff

cliff76 at 2007-7-6 21:36:36 > top of Java-index,Archived Forums,Java Programming...