Add consent tracking to cookie functions

Taken from GOVUK components:

https://github.com/alphagov/govuk_publishing_components/blob/master/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js

Also includes:
- make new cookie functions handle notify domains
- addition of hasConsentFor function to allow easy
  checking of consent for categories of cookie
This commit is contained in:
Tom Byers
2019-12-15 19:36:29 +00:00
parent 0954435afb
commit 8fd9686c3d
2 changed files with 144 additions and 28 deletions

View File

@@ -0,0 +1,15 @@
(function (window) {
"use strict";
function hasConsentFor (cookieCategory) {
const consentCookie = window.GOVUK.getConsentCookie();
if (consentCookie === null) { return false; }
if (!(cookieCategory in consentCookie)) { return false; }
return consentCookie[cookieCategory];
}
window.GOVUK.hasConsentFor = hasConsentFor;
})(window);