Forum Moderators: open

Message Too Old, No Replies

Record Page View Time with ASP

         

TheSeoGuy

5:55 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



Is there a way to record the amount of time that a visitor is on a specific page with asp?

Thanks in advance.

mrMister

10:31 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use some client side javascript. Use the unload event in Javascript to trigger an ASP script.

TheSeoGuy

2:30 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Thanks for the reply mrMister.

But isn't ASP parsed before any events are fired? I can't use a client side Javascript event to trigger server side asp to run, can I?

Thanks.

Peb0

5:31 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



1)While prerendering the page in asp, set a hidden "time" field with NOW on every page you want to time.
2)In every other page, build a "catcher" that looks for the timestamp and compares it with the current time.
3)Record the difference in time and apply it to whichever pages exists 1 step back in the history.

There's probably a better way, but for sure some variant of this would work.

PebĪ

TheSeoGuy

6:32 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Thank Peb0.

I thought of something similar to this, but we run into the problem because the client does not want to record the amount of time on every page, only specific pages.

Also, there doesn't seem to be a way to capture the time on a page if the user closes his or her browser or leaves the site correct?

TheNige

11:29 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



If this is just for reporting purposes, just read your web server logs to see when a session is created, the time they opened a page and then moved on to the next.

carguy84

8:28 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use AJAX to ping back to the server every 5 seconds or whatever interval you're comfortable with. when the pinging stops, the user no longer has the page open.

aspdaddy

12:33 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the IIS logs as suggested above, query with M$ Log Parser, Order the results By Session ID, and then by DateTime

carguy84

8:52 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IIS logs will only track when you loaded the page. It will be able to track your pageview time if you load another page, otherwise it will be tracked by however long you set your session to be.

BradleyT

5:55 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



Right now I have 6 IE windows open, so any of the pages using your ajax script would obviously produce inaccurate results (as would logfile parsing).

carguy84

7:34 pm on Jan 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how so?

aspdaddy

3:20 pm on Jan 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because there is no *guaranteed* accurate way to record the amount of time that a visitor is on a specific page.

mrMister

8:55 am on Jan 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But isn't ASP parsed before any events are fired? I can't use a client side Javascript event to trigger server side asp to run, can I?

You can use Javascript to make a web request. Make it request an ASP page.

TheSeoGuy

2:40 pm on Jan 27, 2006 (gmt 0)

10+ Year Member



mrMister,

You are exactly right! That will allow me to apply it to only the pages I need to track too. The only event this would not account for then is if someone closed their browser while looking at a page I'm tracking... correct?

Thanks to everyone for all the great replies! Your time and thoughts are much appreciated.

TheSeoGuy

4:24 pm on Jan 27, 2006 (gmt 0)

10+ Year Member



Well...

I am able to get the onUnload event to call an asp page in which I capture the end time for my previous page view. This works great. My question now is, how do I know why the user left the page so that I may redirect them appropriately?

I have done some research on this, but cannot seem to find a way to capture the event that occurred. If they clicked a link, what link did they click? If they typed in a new url, what url did they type in?

Currently, when they leave the page for any reason, they get sent to my asp page that records the endTime, but then they just sit there... (I don't know where to redirect them)

Thanks.

coffeebean

2:24 am on Jan 30, 2006 (gmt 0)

10+ Year Member



Currently, when they leave the page for any reason, they get sent to my asp page that records the endTime, but then they just sit there... (I don't know where to redirect them)

Instead of actually sending the user to your asp page, couldn't you have the onunload function call your endTime recorder page in the background, either by loading it as an image, or with a background http (ajax) call to that page. Not sure if it would work but worth a try.

mrMister

10:01 am on Jan 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A common way of doing it is to open a pop-up window which points to your end time tracking script which outputs a window.close()

However an XMLHttpRequest request would be a much better way of doing it.

This is pretty much what coffeebean says, although it's not really AJAX.