Capture the time of the last click on a page | XM Community
Skip to main content

Hi everyone! I’m using a JavaScript code to capture and store the time of the last click on a page, which will later be used in the survey to determine the flow. However, when I compare the results with the variable that Qualtrics automatically creates when recording the survey (Q#_LastClick), I notice that in some cases the results are quite similar, but in others the don’t seem to match at all. Does anyone know why this isn’t working properly in all cases, and how I could fix it? 

 

Here's a bit more context: the page automatically advances after 160 seconds, but the 'Next' button remains accessible during this time. What I want to track is the time of the user's last click, excluding any click on the Next button in case the user decides to advance before the 160-second timer runs out.

 

This is the JavaScript code:

 

var pageLoadTime = Date.now(); // Stores the page load time var timeElapsed = 0; // Variable to store the elapsed time

// Function to calculate the elapsed time between the page load and the last click function updateTimeElapsed() {     var currentTime = Date.now();  // Current time in milliseconds     timeElapsed = (currentTime - pageLoadTime) / 1000;  // Converts milliseconds to seconds }

// Bind the function to the click event on the page document.body.addEventListener('click', updateTimeElapsed);


Qualtrics.SurveyEngine.addOnPageSubmit(function() {  Qualtrics.SurveyEngine.setEmbeddedData('timelastclick', timeElapsed);


});
 

Thank you so much! 

Be the first to reply!

Leave a Reply