Question
Recording data from javascript
Hello,
We have a survey where we'd like to record how long people spend on the Qualtrics tab (how long it is active); we've got a video for people to watch, and would like to be able to verify how long they spend watching (vs. surfing).
I found some custom script (pasted below), and know that I need to add some embedded data to record from the script (also below)... but I'm not sure how to name the embedded value or where to put this in the script box, relative to the timing script. I'm also not sure where these codes should go - both in the "onload" part, or elsewhere?
Any help or comments would be much appreciated!
Thank you,
Sarah
:)
----> custom Javascript to track active tab:
{
var count = 0;
var myInterval;
// Active
window.addEventListener('focus', startTimer);
// Inactive
window.addEventListener('blur', stopTimer);
function timerHandler() {
count++;
document.getElementById("seconds").innerHTML = count;
}
// Start timer
function startTimer() {
console.log('focus');
myInterval = window.setInterval(timerHandler, 1000);
}
// Stop timer
function stopTimer() {
window.clearInterval(myInterval);
}
});
---> Embedded data
{
Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);
Qualtrics.SurveyEngine.getEmbeddedData('FIELD');
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
