Record Time Spent On Page or Survey In Milliseconds

We have a a built-in feature for recording time spent on page in seconds within a Hidden Value. If you wish to be more precise by recording the time spent in milliseconds you can do so with a little bit of JavaScript and Custom Scripting.

Add a survey with these scripts to your account!

Step 1: Record Time (Milliseconds) Spent On Page

On the page you'd like to record, add a Hidden Value action and a JavaScript action. Leave the Hidden Value blank (no populated value). Copy and paste the below JavaScript in the JavaScript Action:


$(document).ready(function(){
  var start = new Date();
  $("#sg_FormFor2181434").submit(function(){  //change the survey ID in this line
    var elapsed = new Date() - start;
    $("#sgE-2181434-1-8-element").val(elapsed); //ID of your hidden value goes here
  });
});

Customizations

  • Change the survey ID in this line: the "sg_FormFor2181434" should read "sg_FormForYOURSIDHERE"
  • Change the ID of the hidden value to the one for your page. Learn how to find this ID or replace the numbers in the ID like this: "#sgE-SIDhere-PageIDhere-QIDhere-element"

You can use this on as many pages as you like; just have a separate JavaScript Action and Hidden Value on each page, and make sure to change the hidden value ID in each JavaScript Action. 

Step 2: Record Time (Milliseconds) Spent On Survey

Once you have a time in milliseconds recorded in a Hidden Value on each page, you can use a Custom Script Action to add them up and store a time spent on survey in another Hidden Value. You could even do some math to get a time spent in seconds with a few decimal places (SurveyGizmo rounds to the nearest second when using the built-in time spent on survey). Here's how!

For time spent on survey in milliseconds, we'll just need to add up all of the Hidden Values where we've stored time spent on page, and then store that sum in another Hidden Value. We suggest putting the Custom Script Action on the Thank You page, and the Hidden Value wherever you'd like it on the survey (after the last question is fine).

Just copy and paste this script in the Custom Script action making sure to change each of the IDs to correspond with the IDs in your survey.


page1 = getvalue(8) --hidden value ID, time spent on page 1
page2 = getvalue(10) --hidden value ID, time spent on page 2

surveyTime = 12 --ID of hidden value to store total survey time

sum = page1 + page2 --add the numbers together

setvalue(surveyTime,sum) --set hidden value with sum

If you'd like to record the time spent on survey in seconds with a decimal instead of raw milliseconds, copy and paste the below script into your Custom Script Action making sure to change each of the IDs to correspond with the IDs in your survey.


page1 = getvalue(8) --hidden value ID, time spent on page 1
page2 = getvalue(10) --hidden value ID, time spent on page 2


surveyTime = 12 -- ID of hidden value to store total survey time

sum = page1 + page2 --add the numbers together
seconds = sum / 1000 --divide milliseconds by 1,000 to get seconds

setvalue(surveyTime,seconds) --set hidden value with seconds

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your needs. Beyond this, check out our Professional Services; these folks have the scripting chops to help you to achieve what you are looking for!

Basic Standard Market Research HR Professional Full Access Reporting
Free Individual Team & Enterprise
Feature Included In