diff --git a/Client-Side Components/Track How Long a User Spends on a Form/README.md b/Client-Side Components/Track How Long a User Spends on a Form/README.md new file mode 100644 index 0000000000..8c511c7815 --- /dev/null +++ b/Client-Side Components/Track How Long a User Spends on a Form/README.md @@ -0,0 +1,23 @@ +# Form Timer – ServiceNow UX Tracker + +Track how long users spend on a form before submitting it. Useful for UX analysis, training feedback, or identifying complex forms. + +## 💡 Features + +- Tracks time spent on form in seconds +- Displays message on submission + +## 🛠 Setup + +1. Add one Display BR and a Client Scripts: + - `displayBR`: Starts timer + - onLoad client script: set the start time + - `onSubmit client script: Calculates and stores time +2. create a field u_spent_time to store the start time + +## 🤝 Contributing + +Ideas for improvement: +- Track time per section/tab +- Send data to analytics dashboard +- Visualize average time per user/form diff --git a/Client-Side Components/Track How Long a User Spends on a Form/displayBR.js b/Client-Side Components/Track How Long a User Spends on a Form/displayBR.js new file mode 100644 index 0000000000..497e30ab03 --- /dev/null +++ b/Client-Side Components/Track How Long a User Spends on a Form/displayBR.js @@ -0,0 +1 @@ +g_scratchpad.startTime= new GlideDateTime(); // store the start the time on Display BR using diff --git a/Client-Side Components/Track How Long a User Spends on a Form/onLoad.js b/Client-Side Components/Track How Long a User Spends on a Form/onLoad.js new file mode 100644 index 0000000000..a621a5b26b --- /dev/null +++ b/Client-Side Components/Track How Long a User Spends on a Form/onLoad.js @@ -0,0 +1 @@ +g_form.setValue('u_start_time',g_scratchpad.startTime); // set the hidden field value via onLoad client script by getting the value via scratchpad diff --git a/Client-Side Components/Track How Long a User Spends on a Form/onSubmit.js b/Client-Side Components/Track How Long a User Spends on a Form/onSubmit.js new file mode 100644 index 0000000000..f05f0e1f94 --- /dev/null +++ b/Client-Side Components/Track How Long a User Spends on a Form/onSubmit.js @@ -0,0 +1,8 @@ +// onSubmit Client Script + + var formEndTime = new Date().getTime(); //get the current time + var timeSpentMs = formEndTime - g_form.getValue('u_spent_time'); //get the duration of time spent + var timeSpentSec = Math.floor(timeSpentMs / 1000); + + g_form.addInfoMessage("You spent " + timeSpentSec + " seconds on this form."); // show the info or we can do multiple things related to reporting + return true;