Add new comment

Recording timestamps with questions using LimeSurvey

LimeSurvey 1.91+ includes a new feature to record the time spent on each question during a survey, but prior to release 1.91 this was not built-in. If you are stuck with an older installation however it is possible to record question timing with some modifications.

One thing that can be very useful when analysing results from a survey is timing data. How long did users look at this question? Are users pausing for a long time on this page?

Knowing this can be very helpful in determining the validity of your data, and in refining surveys to ensure people stay focussed and interested.

LimeSurvey allows you, in general survey setups, to record timings of a survey, and with this you can tell when a person starts a survey, and when they finish. But it doesn't - in versions earlier than 1.91 - allow you to record the times spent viewing individual pages.

This is a solution that allows you to record a timestamp when each page loads. The timestamp can then be used to work out how long it took someone to go from one page to the next. This solution uses a technique that can be very useful for all sorts of problem solving with LimeSurvey - using javascript to hide a question from the participants view, and to fill in some data into that hidden question. So lets go through some of the things you need prepare in order to be able to do to use this trick.

  • Turn off XSS filtering. You need to be able to enter javascript directly into your question (or help) text box. This requires one of the default settings to be modified and you can only do this as a LimeSurvey administrator. The setting is Global Settings, Security, Filter HTML for XSS and in order to be able to enter Javascript in question texts it must be set to No.
  • Set your survey display mode to Group by Group. This is done in your survey's general setup. Because this trick works by creating a question and then hiding it and filling it in automatically without the users knowledge, you cannot use it in question-by-question mode and it would be pointless in all-in-one mode. In question by question mode your users would be presented with an apparently empty page with no question.
  • Know about SGQA codes You can read up about them here: LimeSurvey SGQA identifiers. You'll need to be able to work this out for each question you create.

There are three steps to making this work.

  1. Create a new 'short text' type question
    You can put any text you like into your 'question' text since the participants won't ever see it, but for your own benefit this should probably include something that will identify the question or group of questions that will be displayed. Maybe call it 'group 1 timestamp' or something like that.
    When you are done, note down the SGQA identifier for this question. (Note that for questions that don't have multiple answers, there is no "A" in SGQA.. it's just an SGQ code)
  2. Add javascript to the help section that automatically adds the clients current timestamp as the answer to your question
    This needs to be placed into the help section, because most templates don't load the 'help' section until after the question and the element for the answer to be stored in are displayed. This little bit of javascript gets the time from the participants computer and then inserts it into the short text field for this question - and if the short text field hasn't been printed out yet, then a javascript error will occur. The javascript is as follows:

    <script type='text/javascript'> var d = new Date(); var t_date = d.getDate(); // Returns the day of the month var t_mon = d.getMonth(); // Returns the month as a digit var t_year = d.getFullYear(); // Returns 4 digit year var t_hour = d.getHours(); // Returns hours var t_min = d.getMinutes(); // Returns minutes var t_sec = d.getSeconds(); // Returns seconds var t_mil = d.getMilliseconds; // Returns Milliseconds document.getElementById('answerSGQA').value=t_hour+':'+t_min+’:’+t_sec; //This puts the page load time into the answer for this question </script>

    An alternative, and a simpler method for recording a different type of timestamp is to use the Unix Epoch rather than a stylised timestamp like the above. The unix epoch is the number of seconds passed since 1 Jan 1970 and it is unreadable in terms of establishing an actual time (quite a lot of seconds have passed since 1 Jan 1970). On the other hand, recording this integer number as a timestamp allows you to calculate the time difference between different questions - because you simply subtract a later timestamp from an earlier one and you get the seconds difference. To record a Unix Epoch timestamp, use the following code:

    <script type='text/javascript'> document.getElementById('answerSGQA').value=Math.round((new Date()).getTime() / 1000); </script>

    You'll need to replace 'answerSGQA' in the last line with the actual SGQA of your question. For example - 'answer99853X333X125'.

  3. Set the question's advanced setting (question attribute) 'Always hide this question' to 'Yes'
    Hide the question using a quick bit of javascript Doing this will make sure that your participants don't see the question. We're not really doing this to be sneaky, it's just that it'll look weird to them and they'll be tempted to change it.
    Insert the following javascript into your question help source to hide the question.

    <script type='text/javascript'> document.getElementById('questionQ').style.display='none'; </script>

Here, you replace the letter Q in "questionQ" with the question ID of your question (in the above example, 125 - so the text would be "question125") Once you've done all that your survey will include a question that stores the client time when that page (group) was loaded and first shown to the participant.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.