-2

I need to capture the total elapsed time that a user spends on a page in ASP classic (.asp). This has NOTHING to do with needing to profile the page to get timing of how long the page logic takes to execute. I am only interested in capturing the amount of time each user spends on the site and specifically on a certain page. The elapsed time would also need to be captured if there was a unexpected disconnect on the client side.

I know there are 3rd party utilities and tools to do this in ASP.net - but am struggling to find something that will work in ASP classic. I read a suggestion about possibly using loop to constantly update the database with the latest time while the page is displayed - but that seems like it may be a bit read/write intensive?

Any suggestions?

Lana
  • 1
  • 1
  • Back in the day used to use [`Softwing.Profiler` component](https://www.4guysfromrolla.com/webtech/122700-1.shtml) heavily for page timings and even built a custom class that used it to time actions across a session. A very useful COM component. – user692942 May 13 '21 at 20:14
  • Example of usage [here](http://www.alphasierrapapa.com/IisDev/Components/Profiler/). – user692942 May 14 '21 at 17:48

1 Answers1

0

You can always use the Timer command and compare the times to get the "difference". The problem you have is that ASP classic is server side single directional, meaning it has no two way connection with the client. Data is only exchanged with the server when the page is loaded or refreshed. You could include some javascript options that would allow for some transactions to happen without the page needing to be reloaded. The method using the database to keep track of the time is going to be useful, because every time you reload the page, the Timer would be reset.

<% 'Variables
   dim StartTime, StopStop, HowLong
   'set the StartTime
   StartTime = Timer 
       'your function goes here
   'set the StopTime
   StopTime = Timer 'stops the timer
   'set HowLong to be equal to StopTime subtract Start Time
   HowLong = StopTime - StartTime
   'Display the results to screen
   Response.Write ("It took " & HowLong & " seconds to complete.")
%>

Now that script was just to show you how you can track how long time has passed. I think I explained the limitations of your problem with ASP Classic being only Server Side, so you would need to use a method like you were thinking about where you were constantly outputting that HowLong variable and comparing it to the database.

One last thing to consider, navigating away from the page or refreshing the page will retrigger the script, so you will want to put in some failsafe measures in place to avoid unwanted post backs or other complications since we don't know what your script does. If you give me some more information, I might be able to offer more advice, but without seeing what your code is doing, I hope this is enough to get you pointed in the right direction.

EDIT - One more thought is you can use the Session object to store data in between page loads. You could use this to compare the timer against the one in the database. Session objects are also secure and can not be modified manually by a user, so it would be a secure way to pass data between page loads. Here is some sample code on how to store into a Session variable and pull from it. Let's pretend we are using both scripts at the same time so that I can pass and store HowLong into a Session variable. Although you will require the database as it is not a long term storage, it will time out in a few minutes, and you can specify how long they should last if you want them to last a long time even while idle. Now to the code.

<%  
'store into a session variable
HowLong = Session("HowLong")
'read from a session variable
Session("HowLong") = HowLong
%>

Hope that edit added the extra bit you might of needed. I think I basically just explained the process of how to do what they were saying. If you include the Session method you could use that to store the data so you only have to write or read from the database every few minutes or so.

OHH EDIT - I forgot to mention Timer calculates in seconds, or how many seconds have passed since a date in the 80's. So although you can compare dates and timestamps to get time, if you are trying to see how long something started and stopped, Timer is the simplest method without having to worry about datatypes or anything like that. And one last thing about Session variables, if you close the browser, they go poof. I don't think that applies to tabs but curious to know. But if you use this timer, database, session method, it can track when it starts but getting it to detect the precise disconnect time without constant database checks would be the issue. It's just like, you are better off maybe using something in javascript or Asp.net to do it the non-convoluted way, but I know that isn't always possible, but with the information provided I tried to offer some guidance that hopefully has helped, but you see that the problem is with it not being able to update anything to the server without user input, and the only input is the user closing the window, and that isn't something ASP detects directly, but with the Session variable and constant DB checks, you could hash something together that just might work.

easleyfixed
  • 219
  • 1
  • 13
  • The problem with using `Timer` is the precision, that is why a COM component like `Softwing.Profiler` is a better fit and can handle more precise timing. – user692942 May 14 '21 at 07:53
  • Yeah, that is the issue with my answer, we don't know exactly what they are trying to do, we just know the problem they have. It might be that Timer will be fine for this, but good point user692942! – easleyfixed May 14 '21 at 23:50
  • Thanks for the great suggestions and details. I will look into the Timer functionality. That might do the trick. Basically, the user is watching a classroom video and the total time spent watching the video needs to be timed for credit hours. So.. if for some reason, they lose internet connectivity or get booted off for some other reason, the timer would need to stop at that point. I really appreciate the help! – Lana May 15 '21 at 03:47
  • @Lana I’m not sure how useful `Timer()` will be as the minimum you can capture is seconds when most action will be milliseconds which VBScript natively doesn't support, which is why I suggested the COM component in the first place. – user692942 May 15 '21 at 16:16
  • So, if i only need to quantify the elapsed time in seconds, would Timer be the right choice? Also, if the user suddenly loses internet connectivity and closes his browser without exiting gracefully from the page, will Timer still store the needed elapsed time? Thanks again for the help! – Lana May 16 '21 at 20:53
  • 1
    Just one more clarification... I am not trying to time any part of the logic execution. Only the duration of time that the user spends on a certain page. Thanks again for the help! – Lana May 17 '21 at 16:07
  • If you read what I mentioned in my answer, there is a limitation with ASP classic that it can't exactly detect any feedback from the user once the page is executed, unless you tie it in with javascript or maybe even some clever mysql procedures to do the counting for you, but how are you expecting your script to tell the database or code the user is done? I have an idea .. somewhere in the video it tells you a code you type into a box to submit when you are done watching the video? That way you get a "finished" time .. it might just work? But without randomization kids would post it fast. – easleyfixed May 19 '21 at 03:56
  • Lana, I have not replied further as I have explained the biggest issue with this whole process being the inability of a single directional scripting language to tell a script a user has navigated away. The only way for sure is you would maybe have a button they click when they are "done" or the method I explained above .. maybe cleverly embed parts of a "code" they must put together and submit when done watching to prove they watched the entire video, then add code to check if they did it too fast .. just skipped to the code parts .. something like that just might work, what do you think? – easleyfixed May 21 '21 at 00:35
  • I mean .. no one can prove they watched it .. they could of streamed it and walked away .. without some clever dual directional scripting tricks. So if its more about, logging here is when they clicked to start watching this, and here is when they clicked to stop watching it, that can be tracked, and MAYBE some session timeouts to prove they aren't afk could be checked, and MAYBE a close of the window would clear the session variable and you could check that .. but those are you best options. Or lastly a "test" they take .. but i know this more about proving hours logged. – easleyfixed May 21 '21 at 00:37