Skip to content

Commit

Permalink
Merge pull request #132 from DEFRA/cookies
Browse files Browse the repository at this point in the history
Cookies
  • Loading branch information
Sruthi-Sunder authored Oct 19, 2024
2 parents 77be1ac + a779ed6 commit b8e6edf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/client/assets/javascripts/cookie-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function deleteCookie(name) {
// If a cookie was set with a specified domain, it needs to be specified when deleted
// If a cookie wasn't set with the domain attribute, it shouldn't be there when deleted
// You can't tell if a cookie was set with a domain attribute or not, so try both options

document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;domain=${window.location.hostname};path=/`
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;domain=.${window.location.hostname};path=/`
Expand Down
38 changes: 18 additions & 20 deletions src/client/assets/javascripts/cookies-page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getConsentCookie,
setConsentCookie,
Cookie
} from './cookie-functions.js'
import { getConsentCookie, setConsentCookie } from './cookie-functions.js'

/**
* Website cookies page
Expand Down Expand Up @@ -76,7 +72,6 @@ class CookiesPage {
savePreferences(event) {
// Stop default form submission behaviour
event.preventDefault()
let item
const preferences = {}

this.$cookieFormFieldsets.forEach(($cookieFormFieldset) => {
Expand All @@ -89,25 +84,28 @@ class CookiesPage {
`input[name="cookies[${cookieType}]"]:checked`
)

item = $selectedItem.value
if ($selectedItem instanceof HTMLInputElement) {
preferences[cookieType] = $selectedItem.value === 'yes'
}
})
if (item === 'yes') {
// Save preferences to cookie and show success notification
setConsentCookie(preferences)
} else {
for (const UACookie of [
'_ga_HVF94VF4NZ',
'_gid',
'_ga',
'phi_cookies_analytics'
]) {
Cookie(UACookie, null)
}
}

// Save preferences to cookie and show success notification
setConsentCookie(preferences)

// for (const UACookie of [
// '_ga_HVF94VF4NZ',
// '_gid',
// '_ga',
// 'phi_cookies_analytics'
// ]) {
// Cookie(UACookie, null)
// }

this.showSuccessNotification()
const cookieBanner = document.querySelector(
"[data-module='govuk-cookie-banner']"
)
cookieBanner.setAttribute('hidden', 'true')
}

/**
Expand Down

0 comments on commit b8e6edf

Please sign in to comment.