Capturing time on site for single-page visits
The length of a visit (in terms of time) is one of the most unsatisfactory web analytics statistics no matter what analytics product you use.
One obvious reason is that you can’t really correlate the length of time with actual visitor attention, even if you do have good numbers about how long the site was on the screen. The less obvious reason is that the numbers just aren’t very good to begin with. Because “time on a page” requires knowing the time the page was requested AND the time the next page was requested, there is no way to know the viewing time for pages that didn’t have a next page - i.e. single page visits or the final page in a visit.
WebTrends calculates the Average Visit Length by adding all the known page view times and dividing by the number of visits. The result is a rather funky number, especially if you have a lot of single page visits because their lengths will be O and they’ll drag the average down. If you want to get something a little more realistic, calculate the average yourself but in the denominator first subtract the number of single page visits from the “total visits.” To be even more accurate, instead make an estimate of how long people spent on the average last page of the average visit, and add that number of seconds to the average visit time.
But if you really want to know how long people spent on a page for a single page visit, you might want to look at the following “pulse” code (lifted from an entry by Josh A and a comment by GB on the WebTrends User Forum). In this example, the code fires the SDC tag every 10 seconds up to 3 times. The result is logs containing hits that look like this:
/page.asp
/page.asp?elapsedtime=10
/page.asp?elapsedtime=20
/page.asp?elapsedtime=30
Here’s the code.
var interval = 10;
var maxcount = 3;
var pgtimer = 0;
function pgtimer() {
pgtimer+=interval;
if (typeof(window["dcsMultiTrack"])=="function"){
if (window.location.search)
dcsMultiTrack('DCS.dcsqry',window.location.search+"&elapsedtime="+pgtimer);
else
dcsMultiTrack('DCS.dcsqry',"?elapsedtime="+pgtimer);
if (pgtimer<(maxcount*interval) setTimeout("pgtimer()",interval*1000);
}
}
if((typeof(pgtimer)=="function")&&(document.referrer.indexOf(window.location.host)<0) setTimeout("pgtimer()",interval*1000);
The javascript code will continue to “pulse” until the maxcount is hit as long as the page is still open in a browser. The code is pretty basic. It can be enhanced, for example, to only execute on the first page view of a visit.
Note that the code requires the dcsMultiTrack function to also be available on the page.
You could also code something similar even if you’re using log files.
You *don’t* want to put this on every page on your site because it will fluff up your log files to an extreme degree.
Placing it on a critical entry page, and possibly setting it to execute only one time after a decent interval, might be all you really need.
For example, here’s a Cool Custom Report that shows how many single page visits to your home page lasted less than 10 seconds. Add the script to your home page and set the interval to 10 and maxcount to 1. Any home page view shorter than 10 seconds won’t have the elapsedtime parameter, while views longer than 10 seconds will have the parameter. You’ll have to create two custom report visit-type filters:
- a custom report visit-type filter with two match criteria (must match “all”): visits of length 1 page, and entry at home page
- another custom report visit-type filter that excludes visits where the entry page contains the “elapsedtime” parameter
The dimension for this report can be anything you want, and the measure should be “visits.”






1 comment
Cool post. Quite useful.
Maybe you know the answer to this question (I’ve nver gotten WebTrends to respond) : I heard that 0 duration visits were NOT calculated in the average (since they had no duration), but were in the median (which could explain why it is always much lower than the average; I mean, look at the 0-1 minute visits %, 1-2 %, etc., and the much fewer longer visits should bring the average that high??). Is this true?
Leave a Comment