Compare commits

...

4 Commits

Author SHA1 Message Date
386ae49027 feat: add consent banner 2025-10-23 20:37:02 +05:30
d534cc2f05 feat: add consent banner of analystics 2025-10-23 20:17:48 +05:30
b0793486eb feat: google analytics 2025-10-23 19:33:48 +05:30
2bae3b820c feat: makefile 2025-10-23 19:33:36 +05:30
3 changed files with 106 additions and 0 deletions

12
Makefile Normal file
View File

@@ -0,0 +1,12 @@
BUILD_DIR := public
.PHONEY: serve build clean
serve:
hugo server -D
build:
hugo --minify
clean:
rm -r $(BUILD_DIR)

40
assets/css/consent.css Normal file
View File

@@ -0,0 +1,40 @@
/* Banner container - default (desktop) */
#cookie-consent-banner {
display: none;
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #333;
padding: 1rem;
text-align: center;
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
gap: 1rem;
}
.cookie-buttons {
margin-top: 0.75rem;
}
/* Mobile styles */
@media screen and (max-width: 768px) {
#cookie-consent-banner {
flex-direction: column;
align-items: flex-start;
text-align: left;
padding: 0.75px;
gap: 1rem;
}
#cookie-consent-banner .cookie-text {
max-width: 70%;
}
.cookie-buttons {
margin-top: 0.5rem;
}
}

View File

@@ -0,0 +1,54 @@
<!-- Cookie Consent Banner -->
<div id="cookie-consent-banner" style="display:none;">
<div class="cookie-text">
We use cookies and analytics to improve your experience.
</div>
<div class="cookie-buttons">
<button id="accept-cookies">Accept</button>
<button id="reject-cookies">Reject</button>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const banner = document.getElementById('cookie-consent-banner');
const accepted = localStorage.getItem('cookies-accepted');
// Show banner if no decision yet
if (!accepted) {
banner.style.display = 'block';
} else if (accepted === 'true') {
loadGoogleAnalytics();
}
// Accept cookies
document.getElementById('accept-cookies').addEventListener('click', function() {
localStorage.setItem('cookies-accepted', 'true');
banner.style.display = 'none';
loadGoogleAnalytics();
});
// Reject cookies
document.getElementById('reject-cookies').addEventListener('click', function() {
localStorage.setItem('cookies-accepted', 'false');
banner.style.display = 'none';
});
});
// Function to load GA after consent
function loadGoogleAnalytics() {
if (!document.getElementById('ga-script')) {
const script = document.createElement('script');
script.id = 'ga-script';
script.async = true;
script.src = "https://www.googletagmanager.com/gtag/js?id=G-JFCYXHXCN1";
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-JFCYXHXCN1');
}
}
</script>