From 69bbb12ecec5d494436eae593fd843c6335b2109 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Tue, 8 Jul 2025 19:25:42 +0100 Subject: [PATCH] Survey change to reduce prompts to users (#3913) # Description of Changes --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Dario Ghunney Ware --- .../src/main/resources/static/js/downloader.js | 12 ++++++++++++ .../resources/static/js/multitool/PdfContainer.js | 5 +++++ .../src/main/resources/static/js/pages/home.js | 15 ++++++--------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/stirling-pdf/src/main/resources/static/js/downloader.js b/stirling-pdf/src/main/resources/static/js/downloader.js index 301b0411b..42ba0c357 100644 --- a/stirling-pdf/src/main/resources/static/js/downloader.js +++ b/stirling-pdf/src/main/resources/static/js/downloader.js @@ -2,6 +2,13 @@ if (window.isDownloadScriptInitialized) return; // Prevent re-execution window.isDownloadScriptInitialized = true; + // Global PDF processing count tracking for survey system + window.incrementPdfProcessingCount = function() { + let pdfProcessingCount = parseInt(localStorage.getItem('pdfProcessingCount') || '0'); + pdfProcessingCount++; + localStorage.setItem('pdfProcessingCount', pdfProcessingCount.toString()); + }; + const { pdfPasswordPrompt, multipleInputsForSingleRequest, @@ -312,6 +319,11 @@ pdf_pages: pageCount, }); } + + // Increment PDF processing count for survey tracking + if (success && typeof window.incrementPdfProcessingCount === 'function') { + window.incrementPdfProcessingCount(); + } } } diff --git a/stirling-pdf/src/main/resources/static/js/multitool/PdfContainer.js b/stirling-pdf/src/main/resources/static/js/multitool/PdfContainer.js index 90d130b2f..125801a0a 100644 --- a/stirling-pdf/src/main/resources/static/js/multitool/PdfContainer.js +++ b/stirling-pdf/src/main/resources/static/js/multitool/PdfContainer.js @@ -271,6 +271,11 @@ class PdfContainer { pdf_pages: pageCount, }); } + + // Increment PDF processing count for survey tracking + if (success && typeof window.incrementPdfProcessingCount === 'function') { + window.incrementPdfProcessingCount(); + } } catch { } } diff --git a/stirling-pdf/src/main/resources/static/js/pages/home.js b/stirling-pdf/src/main/resources/static/js/pages/home.js index bb1e1ad4a..a2673ef6c 100644 --- a/stirling-pdf/src/main/resources/static/js/pages/home.js +++ b/stirling-pdf/src/main/resources/static/js/pages/home.js @@ -66,19 +66,16 @@ document.addEventListener('DOMContentLoaded', function () { const dontShowAgain = document.getElementById('dontShowAgain'); const takeSurveyButton = document.getElementById('takeSurvey'); - const viewThresholds = [5, 10, 15, 22, 30, 50, 75, 100, 150, 200]; + const pdfProcessingThresholds = [8, 15, 22, 35, 50, 75, 100, 150]; - // Check if survey version changed and reset page views if it did + // Check if survey version changed and reset PDF processing count if it did const storedVersion = localStorage.getItem('surveyVersion'); if (storedVersion && storedVersion !== surveyVersion) { - localStorage.setItem('pageViews', '0'); + localStorage.setItem('pdfProcessingCount', '0'); localStorage.setItem('surveyVersion', surveyVersion); } - let pageViews = parseInt(localStorage.getItem('pageViews') || '0'); - - pageViews++; - localStorage.setItem('pageViews', pageViews.toString()); + let pdfProcessingCount = parseInt(localStorage.getItem('pdfProcessingCount') || '0'); function shouldShowSurvey() { if(!window.showSurvey) { @@ -90,11 +87,11 @@ document.addEventListener('DOMContentLoaded', function () { } // If survey version changed and we hit a threshold, show the survey - if (localStorage.getItem('surveyVersion') !== surveyVersion && viewThresholds.includes(pageViews)) { + if (localStorage.getItem('surveyVersion') !== surveyVersion && pdfProcessingThresholds.includes(pdfProcessingCount)) { return true; } - return viewThresholds.includes(pageViews); + return pdfProcessingThresholds.includes(pdfProcessingCount); } if (shouldShowSurvey()) {