-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.ejs
43 lines (42 loc) · 1.72 KB
/
index.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<html>
<head>
<title>DEMO</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!-- CookieConsent must be loaded before user related scripts -->
<%= htmlWebpackPlugin.tags.bodyTags %>
<script>
const CookieConsent = window.CookieConsent
const cc = new CookieConsent({
title: "We use cookies 🍪",
})
</script>
<script>
function updateAnalytics() {
const MEASURMENT_ID = "YOURSHERE"
if (window.CookieConsent.acceptedCategories?.includes("analytics")) {
window['ga-disable-' + MEASURMENT_ID] = undefined
;(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga')
ga('create', MEASURMENT_ID, { cookieFlags: 'SameSite=None; Secure' })
ga('set', 'anonymizeIp', true)
ga('send', 'pageview')
} else {
window['ga-disable-' + MEASURMENT_ID] = true
}
}
// Here, you can use either the class CookieConsent or the instance
// you created (cc in our case). Both will emit the same events.
// First argument will give you the instance if it is not in your
// current scope, you can also use the class indifferently.
CookieConsent.on("change", (cc) => {
console.log("change in cookie settings", cc.acceptedCategories)
updateAnalytics()
})
updateAnalytics() // to make sure it is loaded once.
</script>
</body>
</html>