-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96ef7fe
commit 1f05568
Showing
4 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
<!-- Only add all this in production, why would I analyse myself when writing the post anyway. --> | ||
|
||
<!-- Add cookie consent css & js --> | ||
<link rel="stylesheet" | ||
type="text/css" | ||
href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css"/> | ||
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" | ||
data-cfasync="false"></script> | ||
|
||
<!-- Add google analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-RK79VSHG84"></script> | ||
|
||
<script> | ||
// Reads the value of a cookie by name or returns empty string | ||
function getCookie(name) { | ||
var b = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)'); | ||
return b ? b.pop() : ''; | ||
} | ||
|
||
// Actually starting analytics up | ||
function addAnalytics() { | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
|
||
gtag('config', 'G-RK79VSHG84'); | ||
} | ||
|
||
// Waiting for the load event | ||
window.addEventListener("load", function () { | ||
// Reading "cookieconsent_status" cookie | ||
const cookieConsent = getCookie('cookieconsent_status'); | ||
|
||
// Start analytics if user consented or did not deny | ||
if (cookieConsent === 'allow' || cookieConsent === '') { | ||
addAnalytics(); | ||
} | ||
|
||
// Initialise cookie consent banner | ||
window.cookieconsent.initialise({ | ||
"palette": { | ||
"popup": { | ||
"background": "#efefef", | ||
"text": "#404040" | ||
}, | ||
"button": { | ||
"background": "#8ec760", | ||
"text": "#ffffff" | ||
} | ||
}, | ||
"type": "opt-out", | ||
"content": { | ||
"allow": "Approve", | ||
"dismiss": "Approve", | ||
"deny": "Reject" | ||
}, | ||
// Reload the page on user choice to make sure cookie is set | ||
onStatusChange: function (status, chosenBefore) { | ||
location.reload(); | ||
} | ||
}) | ||
}); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters