Skip to content

Commit 447a83f

Browse files
Merge pull request #838 from FitzwilliamMuseum/hotfix/auto-setting-cookies-fix
creating updateConsent function to correctly set cookies on load
2 parents eeabdd6 + 1b71492 commit 447a83f

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

public/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/js/app.js": "/js/app.js?id=490bce15c2508c5b88061671cde8f380",
2+
"/js/app.js": "/js/app.js?id=fa3734e24a6affb5d47300f4bb8cee22",
33
"/js/image-gallery.js": "/js/image-gallery.js?id=d69a0e28c98ea4361c052ddbf98dd62d",
44
"/js/events-carousel.js": "/js/events-carousel.js?id=89e31d3ded01942246c364c48d936947",
55
"/css/app.css": "/css/app.css?id=880d35bb8b03cfe31ab3a81983fef778",

resources/js/config.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ function gtag() {
88
window.dataLayer.push(arguments);
99
}
1010

11+
function updateConsent(cookie) {
12+
if (cookie.categories.includes('analytics')) {
13+
gtag('consent', 'update', {'analytics_storage': 'granted'});
14+
} else {
15+
gtag('consent', 'update', {'analytics_storage': 'denied'});
16+
}
17+
18+
if (cookie.categories.includes('marketing')) {
19+
gtag('consent', 'update', {'ad_storage': 'granted', 'ad_personalization': 'granted', 'ad_user_data': 'granted'});
20+
} else {
21+
gtag('consent', 'update', {'ad_storage': 'denied', 'ad_personalization': 'denied', 'ad_user_data': 'denied'});
22+
}
23+
}
24+
1125
// run plugin with config object
1226
CookieConsent.run({
1327
disablePageInteraction: true,
28+
revision: 1, // Update this whenever cookies need to change
1429
cookie: {
1530
name: 'fitz-cookies',
1631
expiresAfterDays: 365,
@@ -188,21 +203,11 @@ CookieConsent.run({
188203
}
189204
},
190205

191-
onConsent: function (cookie) {
192-
gtag('consent', 'update', {'analytics_storage': 'granted', 'ad_storage': 'granted', 'ad_personalization': 'granted', 'ad_user_data': 'granted'});
206+
onConsent: function ({cookie}) {
207+
updateConsent(cookie);
193208
},
194209

195-
onChange: function (cookie, changed_preferences) {
196-
if (cookie.categories.includes('analytics')) {
197-
gtag('consent', 'update', {'analytics_storage': 'granted'});
198-
} else {
199-
gtag('consent', 'update', {'analytics_storage': 'denied'});
200-
}
201-
202-
if (cookie.categories.includes('marketing')) {
203-
gtag('consent', 'update', {'ad_storage': 'granted', 'ad_personalization': 'granted', 'ad_user_data': 'granted'});
204-
} else {
205-
gtag('consent', 'update', {'ad_storage': 'denied', 'ad_personalization': 'denied', 'ad_user_data': 'denied'});
206-
}
210+
onChange: function ({cookie}, changed_preferences) {
211+
updateConsent(cookie);
207212
}
208213
});

0 commit comments

Comments
 (0)