From 8bb6dea70a7aca941ee5a3f3c1dc7c4be982f1bd Mon Sep 17 00:00:00 2001 From: Reece Browne <74901996+reecebrowne@users.noreply.github.com> Date: Sat, 10 May 2025 13:25:21 +0100 Subject: [PATCH] =?UTF-8?q?accept/decline=20cookies=20based=20on=20analyti?= =?UTF-8?q?cs=20and=20hide=20cookie=20banner=20when=E2=80=A6=20(#3505)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … analytics modal open Close cookies banner when analytics modal is open Accept/decline cookies based on analytics response. Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(3403) --- ## Checklist ### General - [x ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ x] I have performed a self-review of my own code - [ x] 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/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/DeveloperGuide.md#6-testing) for more details. --- src/main/resources/static/js/pages/home.js | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/js/pages/home.js b/src/main/resources/static/js/pages/home.js index 6c48fe81d..bb1e1ad4a 100644 --- a/src/main/resources/static/js/pages/home.js +++ b/src/main/resources/static/js/pages/home.js @@ -4,10 +4,21 @@ document.addEventListener('DOMContentLoaded', function () { if (window.analyticsPromptBoolean) { const analyticsModal = new bootstrap.Modal(document.getElementById('analyticsModal')); analyticsModal.show(); + + let retryCount = 0; +function hideCookieBanner() { + const cookieBanner = document.querySelector('#cc-main'); + if (cookieBanner && cookieBanner.offsetHeight > 0) { + cookieBanner.style.display = "none"; + } else if (retryCount < 20) { + retryCount++; + setTimeout(hideCookieBanner, 100); + } +} +hideCookieBanner(); } }); -/*]]>*/ -function setAnalytics(enabled) { +/*]]>*/function setAnalytics(enabled) { fetchWithCsrf('api/v1/settings/update-enable-analytics', { method: 'POST', headers: { @@ -19,6 +30,15 @@ function setAnalytics(enabled) { if (response.status === 200) { console.log('Analytics setting updated successfully'); bootstrap.Modal.getInstance(document.getElementById('analyticsModal')).hide(); + + if (typeof CookieConsent !== "undefined") { + if (enabled) { + CookieConsent.acceptCategory(['analytics']); + } else { + CookieConsent.acceptCategory([]); + } + } + } else if (response.status === 208) { console.log('Analytics setting has already been set. Please edit /config/settings.yml to change it.', response); alert('Analytics setting has already been set. Please edit /config/settings.yml to change it.');