Skip to content

Commit

Permalink
Merge pull request #156 from chrisrhymes/fix/google-analytics-default…
Browse files Browse the repository at this point in the history
…-consent

Set default consent as granted if cookies accepted
  • Loading branch information
chrisrhymes committed May 14, 2024
2 parents b1f1b69 + f41a443 commit a764aec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 0 additions & 4 deletions _includes/cookie-banner.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<div class="">
<script
src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"
></script>

<div class="container py-6 px-4" id="cookieBanner">
<div class="columns">
<div class="column is-fullwidth ">
Expand Down
25 changes: 17 additions & 8 deletions _includes/google-analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
dataLayer.push(arguments);
}

// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
});
// Set default consent to 'denied' as a placeholder unless already accepted
var cookiesAccepted = Cookies.get('cookiesAccepted');
if (cookiesAccepted === 'true') {
gtag('consent', 'default', {
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
analytics_storage: 'granted',
});
} else {
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
});
}
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
Expand Down
3 changes: 3 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{% endif %}
>
<script defer src="https://unpkg.com/alpinejs@3.9.0/dist/cdn.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js"
></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css">
{% unless site.hide_share_buttons %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma-social@1/bin/bulma-social.min.css">
Expand Down
2 changes: 1 addition & 1 deletion bulma-clean-theme.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "bulma-clean-theme"
spec.version = "1.0.1"
spec.version = "1.0.2"
spec.authors = ["chrisrhymes"]
spec.email = ["csrhymes@gmail.com"]

Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.2
* Update Google Analytics to set default as 'granted' when cookies are already accepted

# 1.0.1
* Fix auto dark mode and allow forcing a theme

Expand Down

0 comments on commit a764aec

Please sign in to comment.