Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Page time in milliseconds

I have a client who wants high fidelity data on page times (i.e., seconds and milliseconds). To my knowledge, the system variables don't get as granular as milliseconds. Any examples of code you can share which allows me to track this?

Thanks.
asked Apr 13 by WTW_cal Bronze (1,085 points)

2 Answers

+1 vote
So you could do this with javascript and freeformat hidden variables.

You could have javascript code that runs as soon as the page loads and sets the free format variable to the current time
SSI_SetValue('ff_hidden_var', JSON.stringify(new Date()))

Then set an event for the on submit to compute the difference between when the page loaded and when it was submitted and store it back to the hidden free format variable.

var a = new Date(JSON.parse(SSI_GetValue('ff_hidden_var')));
var b = new Date(); //now
var c = (b-a); //Difference is in milliseconds
SSI_SetValue('ff_hidden_var', c);
answered Apr 13 by Mike Lodder Gold (23,410 points)
0 votes
To add to Mike's solution, I would start by creating a free format question with a hidden, numeric variable called "_PageTime."  Set the free format's HTML to this:

<input name="[% QuestionName() %]_PageTime" id="[% QuestionName() %]_PageTime" type="hidden" value=""/>
<input id="pageTime" type="hidden" value=""/>
<input id="startMs" type="hidden" value=""/>

<script>
$(document).ready(function(){
    $('#pageTime').val($('#[% QuestionName() %]_PageTime').val());
    var now = new Date();
    $('#startMs').val(now.getTime());
})
</script>


Then give the free format this custom JavaScript verification to be ran before system verification:

var pageTime = Number($('#pageTime').val());
var startTime = Number($('#startMs').val());
var now = new Date();
$('#[% QuestionName() %]_PageTime').val(pageTime + now.getTime() - startTime);


Note that milliseconds are pushing the technical limits of how fine a computer can measure time, so this measurement won't be perfectly accurate.
answered Apr 13 by Zachary Platinum Sawtooth Software, Inc. (63,875 points)
...