diff --git a/frontend/tet/youth/src/components/cookieConsent/CookieConsent.tsx b/frontend/tet/youth/src/components/cookieConsent/CookieConsent.tsx index 4205af42ca..a8376998f3 100644 --- a/frontend/tet/youth/src/components/cookieConsent/CookieConsent.tsx +++ b/frontend/tet/youth/src/components/cookieConsent/CookieConsent.tsx @@ -63,10 +63,14 @@ const CookieConsent: React.FC<{ asPage?: boolean }> = ({ asPage = false }) => { window._paq.push(['requireConsent']); // eslint-disable-next-line no-underscore-dangle, unicorn/no-array-push-push window._paq.push(['requireCookieConsent']); + // eslint-disable-next-line sonarjs/no-collapsible-if } else if (consents.matomo === false) { // tell matomo to forget conset - // eslint-disable-next-line no-underscore-dangle, unicorn/no-array-push-push - window._paq.push(['forgetConsentGiven']); + // eslint-disable-next-line no-underscore-dangle, unicorn/no-lonely-if + if (window && window._paq) { + // eslint-disable-next-line no-underscore-dangle, unicorn/no-array-push-push + window._paq.push(['forgetConsentGiven']); + } } }, focusTargetSelector: '#main_content',