Skip to content

Commit

Permalink
Change default cookie age to session
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jul 30, 2024
1 parent cafd835 commit d66446b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Allow search field to be smaller than the browser default
- Reduced space between paragraphs in hero captions
- Default cookie age changed from `31536000` (1 year) to `null` (session cookie)

### Deprecated
### Removed
Expand Down
6 changes: 3 additions & 3 deletions src/nationalarchives/analytics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class GA4 extends EventTracker {
window.dataLayer = window.dataLayer || [];
if (!this.cookies.isPolicyAccepted("usage")) {
window[this.ga4Disable] = true;
this.cookies.set(this.ga4Disable, "true");
this.cookies.set(this.ga4Disable, "true", { maxAge: 31536000 });
}
this.start(initAll);
}
Expand Down Expand Up @@ -302,7 +302,7 @@ class GA4 extends EventTracker {
enableTracking() {
if (!this.trackingEnabled) {
window[this.ga4Disable] = false;
this.cookies.set(this.ga4Disable, "false");
this.cookies.set(this.ga4Disable, "false", { maxAge: 31536000 });
if (!this.trackingCodeAdded && this.addTrackingCode) {
if (!this.gTagId) {
throw Error("ID was not specified");
Expand Down Expand Up @@ -334,7 +334,7 @@ class GA4 extends EventTracker {
disableTracking() {
if (this.trackingEnabled) {
window[this.ga4Disable] = true;
this.cookies.set(this.ga4Disable, "true");
this.cookies.set(this.ga4Disable, "true", { maxAge: 31536000 });
Object.keys(this.cookies.all).forEach((key) => {
if (key.startsWith("_ga")) {
this.cookies.delete(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class CookieBanner {
}

complete() {
this.cookies.set(this.cookiePreferencesSet, true);
this.cookies.set(this.cookiePreferencesSet, true, { maxAge: 31536000 });
this.$closeButtons.forEach(($closeButton) => {
$closeButton.addEventListener("click", () => this.close());
});
Expand Down
2 changes: 1 addition & 1 deletion src/nationalarchives/components/footer/footer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Footer {
} else {
return;
}
this.cookies.set("theme", theme);
this.cookies.set("theme", theme, { maxAge: 31536000 });
}

selectThemeSelectorButton($selectedButton) {
Expand Down
6 changes: 3 additions & 3 deletions src/nationalarchives/lib/cookies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class Cookies {
* @param {String} key - The cookie name.
* @param {String|Number|Boolean} value - The cookie value.
* @param {Object} options
* @param {Number} [options.maxAge=31536000] - The maximum age of the cookie in seconds.
* @param {Number|null} [options.maxAge=null] - The maximum age of the cookie in seconds.
* @param {String} [options.path=/] - The path to register the cookie for.
* @param {String} [options.sameSite=Lax] - The sameSite attribute.
* @param {String} [options.domain=this.domain] - The domain to register the cookie with.
Expand All @@ -184,7 +184,7 @@ export default class Cookies {
*/
set(key, value, options = {}) {
const {
maxAge = 60 * 60 * 24 * 365,
maxAge = null,
sameSite = "Lax",
domain = this.domain,
path = this.path,
Expand All @@ -195,7 +195,7 @@ export default class Cookies {
}
const cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)};${
domain ? ` domain=${domain}; ` : ""
} samesite=${sameSite}; path=${path}; max-age=${maxAge}${
} samesite=${sameSite}; path=${path};${maxAge !== null ? ` max-age=${maxAge}` : ""}${
secure ? "; secure" : ""
}`;
document.cookie = cookie;
Expand Down

0 comments on commit d66446b

Please sign in to comment.