Skip to content

Commit

Permalink
Added custom cookie consent
Browse files Browse the repository at this point in the history
  • Loading branch information
manishtiwari25 committed Jan 18, 2025
1 parent 3ff56e9 commit 3904e77
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
6 changes: 0 additions & 6 deletions _includes/cookie-bot.html

This file was deleted.

71 changes: 71 additions & 0 deletions _includes/cookie-consent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<style>
#cookie-notice {
padding: 0.5rem 1rem;
display: none;
text-align: center;
position: fixed;
bottom: 0;
width: calc(100% - 2rem);
background: #222;
color: rgba(255, 255, 255, 0.8);
}
#cookie-notice a {
display: inline-block;
cursor: pointer;
margin-left: 0.5rem;
}
@media (max-width: 767px) {
#cookie-notice span {
display: block;
padding-top: 3px;
margin-bottom: 1rem;
}
#cookie-notice a {
position: relative;
bottom: 4px;
}
}
</style>
<div id="cookie-notice">
<span
>We would like to use third party cookies and scripts to improve the
functionality of this website.</span
><a id="cookie-notice-accept" class="btn btn-primary btn-sm">Approve</a
><a href="/privacy" class="btn btn-primary btn-sm">More info</a>
</div>
<script>
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}

if(readCookie('cookie-notice-dismissed')=='true') {
{% if site.google_analytics.id != empty and site.google_analytics.id %} {%
include google-analytics.html %} {% endif %}
} else {
document.getElementById('cookie-notice').style.display = 'block';
}
document.getElementById('cookie-notice-accept').addEventListener("click",function() {
createCookie('cookie-notice-dismissed','true',31);
document.getElementById('cookie-notice').style.display = 'none';
location.reload();
});
</script>
7 changes: 3 additions & 4 deletions _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
{% else %}
<script defer src="{{ '/unregister.js' | relative_url }}"></script>
{% endif %}

{% endif %}
<!-- GA -->
{% if site.google_analytics.id != empty and site.google_analytics.id %} {%
include google-analytics.html %} {% endif %} {% endif %} {% include
ad-recovery.html %} {% include cookie-bot.html %}
{% include ad-recovery.html %}{% include
cookie-consent.html %}

0 comments on commit 3904e77

Please sign in to comment.