I am a looking for a sever side ASP solution!
Main Topics
Browse All TopicsHi Experts
I am working on an application that counts the time a user spends on a website. What I believe is that this can be done by logging in to a site and then browsing the web through that site. If you have any ideas, just let me know.
Regards,
Fahd Murtaza
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can check this site which has got lot of ASP Based SITE STATISTICS which can be used...
http://www.aspin.com/home/
can you give me an idea on how to do this. Here is my idea. I will present a user with a login for my site. After he logs in, his/her session is stored in a variable and he/she is redirected to a framed page. Top frame contains links for the bottom frame. Now this frameset is a part of my site and the bottom frame is an external link. What I want to do is, onchange of the bottom frame, a script in the top frame calculates the time spent on that link and logs it down.
Something like.
http://b3u.net/
Regards,
Fahd Murtaza
@Fahdmurtaza
Use javascript on the client .. this is cool. you could use a div or layer to display the time if you wish.
What you can do is make the textbox hidden on everypage. As soon as the user reaches a new page record the current time and when the user leaves the page and goes to the next page record the time there and CALCULATE the total time spent by doing DATEDIFF()
<HTML>
<HEAD>
<TITLE> Date and Time </TITLE>
</HEAD>
<head>
<script>
// Global variables for timer.
var timerID = null;
var timerRunning = false;
var timevalue;
function startclock ()
{
// Make sure the clock is stopped
stopclock();
time();
}
function stopclock ()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function time ()
{
var now = new Date();
var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
var hours = now.getHours();
hours = ((hours > 12) ? hours - 12 : hours);
var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
timevalue =(" " + hours + minutes + seconds + " " + ampm);
// displays the current time.
document.forms[0].local.va
timerid = setTimeout("time()",1000);
timerrunning = true;
}
document.write(timevalue);
</script>
</head>
<body onload="startclock ()">
</center>
<script>
var now = new Date()
var sec = now.getSeconds()
function MakeArray(n) {
this.length = n;
for (var i = 1; i <= n; i++) {
this[i] = 0 }
return this
}
// end script -->
</script>
<form>
<table width=180><tr>
<td>
<input type="text" name="local" size=12 value=""></td><td align=left>
</td></tr></table><p>
</form>
<LAYER id=timelayer>
</LAYER>
</body>
</html>
</BODY>
</HTML>
You can also use this code.....grabbed it from one of the sites, not my code....It gives you the number of seconds a person has been on that page....should be helpful to you....
<HTML>
<HEAD><TITLE>JavaScript Timer</TITLE>
<SCRIPT>
<!--//hide from old browsers
var counter = 0;
// call Update function in 1 second afte
// r first load
ID=window.setTimeout("Upda
function Update() {
counter ++;
//Optional alert after 10 seconds
//if (counter==10) (alert("Ten seconds i
// s long enough!!!!"))
//Display time in status window
window.status="Elapsed time = " + counter + " seconds";
//Display time in text box
document.form1.input1.valu
// set another timeout for the next coun
// t
ID=window.setTimeout("Upda
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR=aqua>
<FONT FACE=ARIAL COLOR=navy><CENTER><H1>Jav
JavaScript can measure time.<P>
The text value below and the status line are being updated every second.<BR>
Press the RESET button to restart the count, or the STOP button to stop it.
<HR></FONT>
<CENTER>
<FORM NAME="form1">
<INPUT TYPE="text" NAME="input1" SIZE="40" Value="Welcome!"><BR>
<INPUT TYPE="button" VALUE="RESET" onClick="counter = 0;">*
<INPUT TYPE="button" VALUE="STOP" onClick="window.clearTimeo
</CENTER>
<HR>
</BODY></HTML>
To have it completely in VB SCRIPT/ASP i would suggest the best option is to work with sessions in combination with an database.
In the global.asa you can specify on which time the visitor entered the site (i.e. session on start) and you can also specify the time the user left the site (session on end). At the session on end event you can insert the data form the user in an database or a textfile. But working with an database is the best solution.
You can record the unique session_ID and IP
BUGS
In the global.asa file you put something like:
Public Sub Session_OnStart()
Session("timestart") = Now
End Sub
Public Sub Session_OnEnd()
Application.Lock
Application("totaltime") = dateDiff("s", "Session("timestart"), Now)
Application.UnLock
End Sub
now for time spent on each page can be recorded as below....this way you'll get the time spent in minutes shown..
<%=(Datediff("n",session("
use h for hours or s for seconds instead of n for minutes..
Check http://www.w3schools.com/a
Also check the code below....
<script language=vbscript runat=server>
Sub Session_OnEnd
set conn = Server.CreateObject("ADODB
conn.Open "DSN=....."
query = "YOUR SQL QUERY TO UPDATE"
conn.Execute(query)
conn.Close
set conn = Nothing
End Sub
</script>
Business Accounts
Answer for Membership
by: bugsPosted on 2007-07-28 at 07:50:41ID: 19584887
Try using below code....here for your purpose i am alerting the time spent, you can document.write to display it on the webpage.
("timeHere ()", 100)' onunload="sayTime()"></bod y>
<html>
<title>BUGS</title>
<script language="javascript">
var time=1;
function timeHere() {
time = time + 1;
finalTime = time / 10;
/* Remove the "//" below to display in the title bar
the amount of time the visitor has been on the site.
Be aware though, that it does tend to be a bit distracting. */
// document.title = finalTime+" seconds you been here for!";
}
function sayTime() {
finalTime = time / 10;
alert("Thank you for coming to my site! \n You have been here " + finalTime + " seconds!");
}
</script>
</head>
<body onload='window.setInterval
</html>