diff --git a/apps/ui/components/ExternalScripts.tsx b/apps/ui/components/ExternalScripts.tsx index e3fd19c89..94cda822e 100644 --- a/apps/ui/components/ExternalScripts.tsx +++ b/apps/ui/components/ExternalScripts.tsx @@ -2,6 +2,35 @@ import React from "react"; import Script from "next/script"; import { isBrowser } from "@/modules/const"; +const hosts = [ + "tilavaraus.hel.fi", + "tilavaraus.dev.hel.ninja", + "tilavaraus.test.hel.ninja", + "tilavaraus.stage.hel.ninja", +]; + +// Hack to make cookiehub not destroy our cookies +// temporary for a few weeks to fix critical production issue +const addCookieHubExceptions = ` + const cookies = ["csrftoken", "sessionid", "language"]; + for (let i = 0; i < cookies.length; i++) { + window.__cookiehub.cookies.push({ + category: (window.__cookiehub.categories.find((c) => c.implicit).id), + expiry: "365 {day}", + display_name: cookies[i], + hide: 0, + hosts: ${JSON.stringify(hosts)}, + http_only: 0, + id: 99990 + i, + name: cookies[i], + path: "/", + prefix: 0, + secure: 0, + third_party: 0, + type: 1 + }); + } +`; export function ExternalScripts({ cookiehubEnabled, matomoEnabled, @@ -25,7 +54,7 @@ export function ExternalScripts({ __html: ` var cpm = { cookie: { - domain: '' + domain: "", }, language: document.documentElement.lang !== null ? document.documentElement.lang.substr(0, 2) @@ -34,7 +63,10 @@ var cpm = { (function(h,u,b){ var d=h.getElementsByTagName("script")[0],e=h.createElement("script"); e.async=true;e.src='https://cookiehub.net/c2/c7e96adf.js'; -e.onload=function(){u.cookiehub.load(b);} +e.onload=function(){ + u.cookiehub.load(b); + ${addCookieHubExceptions}; +} d.parentNode.insertBefore(e,d); })(document,window,cpm); `,