Skip to content

Commit a764aec

Browse files
authored
Merge pull request #156 from chrisrhymes/fix/google-analytics-default-consent
Set default consent as granted if cookies accepted
2 parents b1f1b69 + f41a443 commit a764aec

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

_includes/cookie-banner.html

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<div class="">
2-
<script
3-
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js"
4-
></script>
5-
62
<div class="container py-6 px-4" id="cookieBanner">
73
<div class="columns">
84
<div class="column is-fullwidth ">

_includes/google-analytics.html

+17-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55
dataLayer.push(arguments);
66
}
77

8-
// Set default consent to 'denied' as a placeholder
9-
// Determine actual values based on your own requirements
10-
gtag('consent', 'default', {
11-
ad_storage: 'denied',
12-
ad_user_data: 'denied',
13-
ad_personalization: 'denied',
14-
analytics_storage: 'denied',
15-
});
8+
// Set default consent to 'denied' as a placeholder unless already accepted
9+
var cookiesAccepted = Cookies.get('cookiesAccepted');
10+
if (cookiesAccepted === 'true') {
11+
gtag('consent', 'default', {
12+
ad_storage: 'granted',
13+
ad_user_data: 'granted',
14+
ad_personalization: 'granted',
15+
analytics_storage: 'granted',
16+
});
17+
} else {
18+
gtag('consent', 'default', {
19+
ad_storage: 'denied',
20+
ad_user_data: 'denied',
21+
ad_personalization: 'denied',
22+
analytics_storage: 'denied',
23+
});
24+
}
1625
</script>
1726
<!-- Google tag (gtag.js) -->
1827
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>

_includes/head.html

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{% endif %}
1414
>
1515
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
16+
<script
17+
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js"
18+
></script>
1619
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css">
1720
{% unless site.hide_share_buttons %}
1821
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma-social@1/bin/bulma-social.min.css">

bulma-clean-theme.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "bulma-clean-theme"
5-
spec.version = "1.0.1"
5+
spec.version = "1.0.2"
66
spec.authors = ["chrisrhymes"]
77
spec.email = ["[email protected]"]
88

changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.0.2
2+
* Update Google Analytics to set default as 'granted' when cookies are already accepted
3+
14
# 1.0.1
25
* Fix auto dark mode and allow forcing a theme
36

0 commit comments

Comments
 (0)