-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adiciona banner de consentimento de cookies e implementa lógica de ac…
…eitação no Google Analytics
- Loading branch information
1 parent
26f10d3
commit be6b37d
Showing
5 changed files
with
147 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,45 @@ | ||
// Google Analytics | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { dataLayer.push(arguments); } | ||
gtag('js', new Date()); | ||
gtag('config', 'G-CMLZKJVKKY'); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const consentAccepted = localStorage.getItem('consentAccepted'); | ||
console.log('Consent accepted:', consentAccepted); | ||
|
||
if (!consentAccepted) { | ||
console.log('Displaying cookie consent banner'); | ||
document.getElementById('cookieConsentBanner').style.display = 'block'; | ||
} | ||
|
||
document.getElementById('acceptConsent').addEventListener('click', () => { | ||
console.log('Accept button clicked'); | ||
localStorage.setItem('consentAccepted', 'true'); | ||
loadGoogleAnalytics(); | ||
document.getElementById('cookieConsentBanner').style.display = 'none'; | ||
document.getElementById('cookieConsentBanner').setAttribute('style', 'display: none !important'); | ||
console.log('Banner hidden after accept'); | ||
}); | ||
|
||
document.getElementById('declineConsent').addEventListener('click', () => { | ||
console.log('Decline button clicked'); | ||
document.getElementById('cookieConsentBanner').style.display = 'none'; | ||
document.getElementById('cookieConsentBanner').setAttribute('style', 'display: none !important'); | ||
console.log('Banner hidden after decline'); | ||
}); | ||
|
||
function loadGoogleAnalytics() { | ||
console.log('Loading Google Analytics'); | ||
const script = document.createElement('script'); | ||
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-CMLZKJVKKY'; | ||
script.async = true; | ||
document.head.appendChild(script); | ||
|
||
script.onload = () => { | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { dataLayer.push(arguments); } | ||
gtag('js', new Date()); | ||
gtag('config', 'G-CMLZKJVKKY'); | ||
console.log('Google Analytics loaded'); | ||
}; | ||
} | ||
|
||
if (consentAccepted) { | ||
loadGoogleAnalytics(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters