index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function loadGA() {
  2. if (window.olLoadGA) {
  3. window.olLoadGA()
  4. }
  5. }
  6. function setConsent(value) {
  7. document.querySelector('.cookie-banner').classList.add('hidden')
  8. const cookieDomain = window.ExposedSettings.cookieDomain
  9. const oneYearInSeconds = 60 * 60 * 24 * 365
  10. const cookieAttributes =
  11. '; domain=' +
  12. cookieDomain +
  13. '; max-age=' +
  14. oneYearInSeconds +
  15. '; SameSite=Lax; Secure'
  16. if (value === 'all') {
  17. document.cookie = 'oa=1' + cookieAttributes
  18. loadGA()
  19. } else {
  20. document.cookie = 'oa=0' + cookieAttributes
  21. }
  22. }
  23. if (window.ExposedSettings.gaToken || window.ExposedSettings.gaTokenV4) {
  24. document
  25. .querySelectorAll('[data-ol-cookie-banner-set-consent]')
  26. .forEach(el => {
  27. el.addEventListener('click', function (e) {
  28. e.preventDefault()
  29. const consentType = el.getAttribute('data-ol-cookie-banner-set-consent')
  30. setConsent(consentType)
  31. })
  32. })
  33. const oaCookie = document.cookie.split('; ').find(c => c.startsWith('oa='))
  34. if (!oaCookie) {
  35. const cookieBannerEl = document.querySelector('.cookie-banner')
  36. if (cookieBannerEl) {
  37. cookieBannerEl.classList.remove('hidden')
  38. }
  39. }
  40. }