471,354 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

how can I count the number of seconds a page is viewed?

I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two timestamps?

Thanks for your help and/or links to articles on the subject!
Jul 17 '05 #1
14 3725
NotGiven wrote:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two
timestamps?

Thanks for your help and/or links to articles on the subject!


holy moly dude.
have a javascript variable that hold the datetime stamp when the page is
opened. Then when the page is closed, you need to tell the browser the
following...

1. variable Var_pageViewSeconds = Var_pageStartTime - datetime(now).
2. post/send request to your server (onclose - or whatever it is) and send
it that variable (Var_pageViewSeconds)

* wont work for non javascript browsers.
* wont work for me (i dont like it when page builders put the 'onclose'
thing in the page).

hope this helps.
Jul 17 '05 #2

"NotGiven" <no****@nonegiven.net> wrote in message
news:c8*******************@bignews5.bellsouth.net. ..
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two timestamps?

Thanks for your help and/or links to articles on the subject!


just get a time stamp on each page.
on a *nix box, you could do something like the following.

declare a session variable $sessTime
set $sessTime = microtime()
on the next page, $newTime = microtime()
$elapsedTime = $newTime - $sessTime
now set $sessTimer = $newTime
and so on.........

Jul 17 '05 #3
NotGiven wrote:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two
timestamps?

Thanks for your help and/or links to articles on the subject!


Curious myself. Would the PHP functions: session_start () and session_id ()
be a possible route to go without resorting to Javascript using on_close ()
perhaps ? Just a shot in the dark really.
Preferrably I would also get info on the next page a visitor visits. I know
it HAS been used by some to study people's internet behaviour.

Time calculating is not hard, store time () in a variable at start, and
subtract that from time () again when done. Time () is in seconds since UNIX
epoch (1-1-1970).

best
jan
Jul 17 '05 #4
On Wed, 14 Jan 2004 18:09:07 +0100, "Jan Soldaat"
<x3****@westerterp.com> wrote:
NotGiven wrote:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two
timestamps?

Thanks for your help and/or links to articles on the subject!
Curious myself. Would the PHP functions: session_start () and session_id ()
be a possible route to go without resorting to Javascript using on_close ()
perhaps ? Just a shot in the dark really.


Sessions wouldn't work if I just closed my browser, or typed a new
address into the address bar, or selected one of my bookmarks, or
pressed the back button.

What would happen if I opened the link in a new window?

If the session relied on a cookie and that cookie's expiry time was
thirty minutes and I left the page open for > 30 minutes (when I went
to lunch, or I left my machine on overnight), your script would only
report 30 minutes (I think).
Preferrably I would also get info on the next page a visitor visits. I know
it HAS been used by some to study people's internet behaviour.


In short, it can't really be done reliably.

--
David ( @priz.co.uk )
Jul 17 '05 #5
In message <c8*******************@bignews5.bellsouth.net>, NotGiven
<no****@nonegiven.net> writes
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two timestamps?

Thanks for your help and/or links to articles on the subject!


What would it tell you if you could do it? How long it took the viewer
to get a cup or tea, or go to the loo? You *may* be able to count the
time before something else is displayed, but that won't necessarily mean
anything at all.

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #6
(I've removed a.p.s as my server doesn't carry it, and it should
never've been there in the first place; Korepela's 42nd law should
dissuade me from following-up, but I just gotta...)

[Following-up on the question "[H]ow can I count the number of
seconds a page is viewed?",]

David Mackenzie wrote:
In short, it can't really be done reliably.


I agree. Put differently: it'd be a fruitless exercise -- except for
perhaps keeping your programming mastership tip-top. I'm not even
sure what the real point of discussion was meant to be.

--
Jock
Jul 17 '05 #7

"David Mackenzie" <me@privacy.net> wrote in message
news:ic********************************@4ax.com...
On Wed, 14 Jan 2004 18:09:07 +0100, "Jan Soldaat"
<x3****@westerterp.com> wrote:
NotGiven wrote:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two
timestamps?

Thanks for your help and/or links to articles on the subject!


Curious myself. Would the PHP functions: session_start () and session_id ()be a possible route to go without resorting to Javascript using on_close ()perhaps ? Just a shot in the dark really.


Sessions wouldn't work if I just closed my browser, or typed a new
address into the address bar, or selected one of my bookmarks, or
pressed the back button.

What would happen if I opened the link in a new window?

If the session relied on a cookie and that cookie's expiry time was
thirty minutes and I left the page open for > 30 minutes (when I went
to lunch, or I left my machine on overnight), your script would only
report 30 minutes (I think).
Preferrably I would also get info on the next page a visitor visits. I knowit HAS been used by some to study people's internet behaviour.


In short, it can't really be done reliably.

--
David ( @priz.co.uk )


Sure, it can be done reliably.
I dont see what the problem is with sessions.
Since HTTP is a stateless protocol, you have to keep a time stamp somewhere
and wait for a subsequent request.
The only page that wont get calculated is the very last page visited before
the user leaves.
This is exactly how web usage report tools work - an IP address and a
timestamp.

Also, IMO, stay away from the window onclose() method.
That could get kind of screwy -
Not to mention it is the most abused method on the Internet.

If the page happens to be the last one visited before they leave .... so
what.
You have a record of it being the last page, does it really matter how long
they physically viewed it ?

Jul 17 '05 #8
On Wed, 14 Jan 2004 14:28:37 -0500, xyzzy wrote:
Sure, it can be done reliably.
I dont see what the problem is with sessions.
Since HTTP is a stateless protocol, you have to keep a time stamp somewhere
and wait for a subsequent request.


Define "reliably".

The time a page is viewed cannot be calculated reliably, period. It can
be calculated UNreliably, though, and that may be good enough. The very
reason it can't be calculated reliably is in your post: "Since HTTP is a
stateless protocol."

Web log analysis tools are actually quite unreliable. They may be "good
enough", however, for many situations.
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #9

"Jeffrey Silverman" <je*****@jhu.edu> wrote in message
news:pa****************************@jhu.edu...
On Wed, 14 Jan 2004 14:28:37 -0500, xyzzy wrote:
Sure, it can be done reliably.
I dont see what the problem is with sessions.
Since HTTP is a stateless protocol, you have to keep a time stamp somewhere and wait for a subsequent request.


Define "reliably".

The time a page is viewed cannot be calculated reliably, period. It can
be calculated UNreliably, though, and that may be good enough. The very
reason it can't be calculated reliably is in your post: "Since HTTP is a
stateless protocol."

Web log analysis tools are actually quite unreliable. They may be "good
enough", however, for many situations.
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/


Without arguing over *reliability* , I think you and I are on the same page.
Of course there is no exact measurement for viewing time.
Just talking about practical usage here.
Everyday patterns and trends....


Jul 17 '05 #10
"how can I count the number of seconds a page is viewed?"

You can't: HTTP is a stateless protocol.

Even if you were able to concoct a script which could *estimate* the
time between the page loading and unloading, you *still* haven't
measured anything worthwhile -- there is no way to determine whether the
screen is viewed by a human (rather than a search engine or a robot), or
even whether the page is viewed at all (rather than merely being on a
screen somewhere, unwatched while the owner is making a sandwich).

The entire exercise is pointless: it's a waste of time and effort --
effort that should instead be devoted to opposing the Evil of obnoxious
Flash-based web sites which appear as blank pages in standard web
browsers (such as the Paramount site).

Just Say No to Flash.

bblackmoor
2004-01-14

Jul 17 '05 #11
In message <bu************@ID-97660.news.uni-berlin.de>, Brandon
Blackmoor <bb********@spamcop.net> writes
"how can I count the number of seconds a page is viewed?"

You can't: HTTP is a stateless protocol.

Even if you were able to concoct a script which could *estimate* the
time between the page loading and unloading, you *still* haven't
measured anything worthwhile -- there is no way to determine whether
the screen is viewed by a human (rather than a search engine or a
robot), or even whether the page is viewed at all (rather than merely
being on a screen somewhere, unwatched while the owner is making a
sandwich).
Indeed.

The entire exercise is pointless: it's a waste of time and effort --
effort that should instead be devoted to opposing the Evil of obnoxious
Flash-based web sites which appear as blank pages in standard web
browsers (such as the Paramount site).
Not that I've ever visited the paramount site, but yes - Flash is one of
the evils of modern web sites!

Just Say No to Flash.

bblackmoor
2004-01-14


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #12
On Thu, 15 Jan 2004 09:10:17 +0000, Five Cats wrote:
The entire exercise is pointless: it's a waste of time and effort --
effort that should instead be devoted to opposing the Evil of obnoxious
Flash-based web sites which appear as blank pages in standard web
browsers (such as the Paramount site).


Not that I've ever visited the paramount site, but yes - Flash is one of
the evils of modern web sites!


What do you have against Flash? More specifics, please, not just personal
preference.

Also, although HTTP is stateless and you can't reliably track users
viewing web pages and all that, you *can* get some reliable info about how
web pages are being used, and you can also get some UNreliable info on how
long pages are viewed and other stuff that really isn't possible to get.

But, from the point of view of marketing droids and/or managers, this
unreliable info is very useful. I personally have used said unreliable
information to get things done the way I want them to be done. What was
that quote, "lies, damn lies, and statistics"? The stats derived from
http traffic monitoring *can* be used effectively, in many circumstances.
Just understand that they may not be accurate.

I hope I made some kind of point here. I also know that some people will
be pissed off that I recognized the fact that you can lie with statistics,
but thems the breaks.

later...

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #13
On Wed, 14 Jan 2004 14:28:37 -0500, <xyzzy> wrote:

"David Mackenzie" <me@privacy.net> wrote in message
news:ic********************************@4ax.com.. .

In short, it can't really be done reliably.
Sure, it can be done reliably.
I dont see what the problem is with sessions.
Since HTTP is a stateless protocol, you have to keep a time stamp somewhere
and wait for a subsequent request.
The only page that wont get calculated is the very last page visited before
the user leaves.
This is exactly how web usage report tools work - an IP address and a
timestamp.


If I view page A and then click on a link to view page B in a new
window, am I still viewing page A? What if I refresh page A? Should
the time I spend looking at page B be added to page A even though I'm
not actually looking at it? What if I open them side-by-side? What if
I right-click the link to page B and select "Save Target As..."? etc
etc

These grey areas are the reason I said it cannot be done reliably.

These questions can only be answered if we have a clear idea of how
this information is to be used.

--
David ( @priz.co.uk )
Jul 17 '05 #14
Maybe you instead of posting it to the server right away, you can storing
the calculated duration in a cookie, and retrieve it the next time the user
visit the site? At least that gets rid of the mystery popup window syndrome.

Uzytkownik "Disco Octopus" <di****************@yahoo.com> napisal w
wiadomosci news:PR**************@news.optus.net.au...
NotGiven wrote:
I am guessing I would hold a variable of when it's opened, then in the
script that runs when the page is offloaded, I coudl calcualte it.

How do you store a time variable?

How do you calculate the amount of time (seconds) based on two
timestamps?

Thanks for your help and/or links to articles on the subject!


holy moly dude.
have a javascript variable that hold the datetime stamp when the page is
opened. Then when the page is closed, you need to tell the browser the
following...

1. variable Var_pageViewSeconds = Var_pageStartTime - datetime(now).
2. post/send request to your server (onclose - or whatever it is) and send
it that variable (Var_pageViewSeconds)

* wont work for non javascript browsers.
* wont work for me (i dont like it when page builders put the 'onclose'
thing in the page).

hope this helps.

Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matthew Groch | last post: by
7 posts views Thread by matvdl | last post: by
32 posts views Thread by Ciaran | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.