From 6954e3263b8f7cdb4cc0309b4e27bafab375c5f1 Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:21:40 +0530 Subject: [PATCH 1/5] Create README.md --- .../README.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Client-Side Components/Track How Long a User Spends on a Form/README.md 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..2a95579f04 --- /dev/null +++ b/Client-Side Components/Track How Long a User Spends on a Form/README.md @@ -0,0 +1,21 @@ +# 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 + - `onSubmit`: Calculates and stores time + +## 🤝 Contributing + +Ideas for improvement: +- Track time per section/tab +- Send data to analytics dashboard +- Visualize average time per user/form From 7fff0d831bbff24b009592e0fb25033bb0db2fa1 Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:26:44 +0530 Subject: [PATCH 2/5] Create displayBR.js --- .../Track How Long a User Spends on a Form/displayBR.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Track How Long a User Spends on a Form/displayBR.js 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 From a094b377bdf06a54908728aa2b75957c179ce1cf Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:28:32 +0530 Subject: [PATCH 3/5] Create onLoad.js --- .../Track How Long a User Spends on a Form/onLoad.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Track How Long a User Spends on a Form/onLoad.js 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 From 60ef1cc984b90bdf2a07173744a75be2628b6403 Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:31:53 +0530 Subject: [PATCH 4/5] Create onSubmit.js --- .../Track How Long a User Spends on a Form/onSubmit.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Client-Side Components/Track How Long a User Spends on a Form/onSubmit.js 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; From 06bd29ec23c982b0158ecc6eb8a313797d24144e Mon Sep 17 00:00:00 2001 From: Lucifer <108731648+shivamvish160@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:33:17 +0530 Subject: [PATCH 5/5] Update README.md --- .../Track How Long a User Spends on a Form/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 index 2a95579f04..8c511c7815 100644 --- 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 @@ -11,7 +11,9 @@ Track how long users spend on a form before submitting it. Useful for UX analysi 1. Add one Display BR and a Client Scripts: - `displayBR`: Starts timer - - `onSubmit`: Calculates and stores time + - 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