This topic is locked

time calculate

4/18/2007 12:54:43 PM
ASPRunnerPro General questions
R
rokita author

hi all

i need to calculate time passed- elapsed on a specific page and have a feedback on the database.
is it possible with asprunner?
thanks

Sonia -Italy

Sergey Kornilov admin 4/18/2007

Sonia,
what is the "time passed- elapsed on a specific page"?

R
rokita author 4/19/2007

sorry i'm italian language
i mean this:
a visitor enter on webpage, example: www.mysite.com/page.asp
i wish calculate time between when visitor enter on that page and when he leave that page and send report to a database
start time to enter on webpage-----------end time.......example: 2 minutes-------->send this elapsed time on a db.
hope this is clearer
thanks Sonia

V
Vladimir 4/19/2007

Sonia,
unfortunately it is impossible. there isn't reliable method to lock time when visitor leaves page. User may simply close browser window.

R
rokita author 4/19/2007

hi i found this code:

Javascript can be used for lots of things. I got this idea some minutes ago and thought that I write it down for more people to use. The reason I thought about this, is that I wondered how long time I spent reading an other tutorial :-)
I don't know if the function in it self is useful on a serious website, but I think that you can use the function to build special things for your needs.
Ok,now lets get to the magic... This is separated in two parts. On part that is activated when you visit the page, and one part that is activated when you leave the page.
<script language="Javascript">

pageOpen = new Date();
// This function is called when the person closes the window or navigate away.

function leavingPage()

{

pageClose = new Date();
hours = (pageClose.getHours() - pageOpen.getHours());

minutes = (pageClose.getMinutes() - pageOpen.getMinutes());

seconds = (pageClose.getSeconds() - pageOpen.getSeconds());

time = (seconds + (minutes 60) + (hours 60 * 60);
time = (time + " second(s)");
if(time <= 60)

{

alert('You have visited this site ' + time + '. Next time I think you should stay longer than one minute...');

}

else

{

alert('You have visitied this site ' + time + '. Thanks a lot, you are a valued visitor...');

}

}

</script>
<body onUnload="leavingPage()">
This part is made up of three parts.

Create a date object with the time when the page is generated (when the page is visited)

When you leave the last part is triggered with the onUnload event, which calls our function "leavingPage()". This function calculate and show the visitor the number of seconds spent on the site.
leavingPage-function

A simple explanation of what the function does.

First we create a date object, just like we did when we started the page. But this object will hold information about the time when the visitor leave the site.
i just wish to know how send result to db...
thanks Sonia

Sergey Kornilov admin 4/19/2007

Sonia,
you understand all this right however you cannot write anything to the database using Javascript (until you use some fancy AJAX-based functionality).

R
rokita author 4/19/2007

ok understood this... just javascript wont works..
can this be helpfull?
function sendMessage(){

var user='<?php echo $user?>';

var message=document.getElementsByTagName('form')[0].elements

[0].value;

if(message.length>100){message=message.substring(0,100)};

// open socket connection

senderXMLHttpObj.open('POST','sendchatdata.php',true);

// set form http header

senderXMLHttpObj.setRequestHeader('Content-

Type','application/x-www-form-urlencoded');

senderXMLHttpObj.send('user='+user+'&message='+message);

senderXMLHttpObj.onreadystatechange=senderStatusChecker;

}
taken from ajax tutorial and asprunner can help?
thanks Sonia

R
rokita author 4/19/2007

with .aspx
"Have you ever been curious about how long it takes someone to fill out a form? What about how long they took to read a page? Well with a little bit of code we can easily determine this type of information.
Here's what we need. First when they get to the page that we are curious about we need to store the time at which they retrieved the page. Next, when they send in their next request, we need to get back that value and compare it to the stored time. The result is the time between their two page requests. It's not perfect, but basically we have a quick and easy instant timer.
Darn! You caught that thing about it not being perfect didn't you? Well here's what's wrong with it. First the actual time isn't that precise due to the fact that it's generated by the server, not by the client after they get the page. Next we have the problem that we don't always get the result back if they close their browser or type in a new URL, so we probably don't want to depend on the value too much. Last, but not least, someone could get your first page, go out to dinner, come back and then finish filling out your form. We can't tell what they were doing during the time they had the page open. If you can live with these conditions, this script makes a great little addition to your scripting library for use in those instances where you 'just want to get an idea' of how long people are spending on a specific page.
Like many of our samples, this one leaves a lot to be desired. It doesn't log its results anywhere. (See the database and text file samples for that type of code.) It could also store these values in a session variable so you'd have access to them if you wanted to use them for anything else. The implementaion of these ideas as well as any others are 'left as an exercise for the reader' as my calculus book used to say (at least about the things the authors couldn't figure out)."
studying on it now
thanks Sonia

Sergey Kornilov admin 4/20/2007

I think solution is really simple here:

  1. Use AddOnLoad event to insert a record into some table with UserID or IP address as ID and StartTime.
  2. Use BeforeAdd event to locate and update this record with EndTime.
    If you user didn't submit the form abd leaves page (closes browser window) EndTime field will be empty.

    I assume that if user didn't submit the form you don't actually care how many time they spent on that page.

R
rokita author 4/21/2007

thanks

can i do this with asprunner functions?
best regards Sonia

Sergey Kornilov admin 4/23/2007

Yes, I'm talking about using events in ASPRunnerPro.

A
agmoraojr 4/26/2007

admin & sonia,
can i Insert myself on this discussion?
I used the aftersuccessfullogin() event using the insert record

to display the username login time as well also the IP address, but the problem on my

field accesstime function as declared now() is that it shows a double display, let me show

the sample output as you distinguised the problem
username accesstime ip address

jong 14/04/2007 19:57:14 127.0.1.1

jong 14/04/2007 19:57:14 127.0.1.1
another, When I try to delete one record, it deletes all the entries, why is this happen, any clues?

thank you,