index.js 1.2 KB

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