mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 16:05:09 +00:00
accept/decline cookies based on analytics and hide cookie banner when… (#3505)
… 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.
This commit is contained in:
parent
ff3fe19d98
commit
8bb6dea70a
@ -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.');
|
||||
|
Loading…
x
Reference in New Issue
Block a user