Browse code

Initial commit

Benjamin Roth authored on16/03/2023 20:22:35
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+<?php
2
+// To use this script, please fill in your Google Analytics ID below
3
+$GoogleAnalyticsId = 'UA-XXXXX-X';
4
+// DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!
5
+if ('UA-XXXXX-X' != $GoogleAnalyticsId && !BE_USER_LOGGED_IN && !$this->hasAuthenticatedBackendUser()) : ?>
6
+	<script>
7
+		function initGoogleAnalytics() {
8
+			(function(i, s, o, g, r, a, m) {
9
+				i['GoogleAnalyticsObject'] = r;
10
+				i[r] = i[r] || function() {
11
+					(i[r].q = i[r].q || []).push(arguments)
12
+				}, i[r].l = 1 * new Date();
13
+				a = s.createElement(o), m = s.getElementsByTagName(o)[0];
14
+				a.async = 1;
15
+				a.src = g;
16
+				m.parentNode.insertBefore(a, m)
17
+			})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
18
+			ga('create', '<?= $GoogleAnalyticsId ?>', 'auto');
19
+			ga('set', 'anonymizeIp', true);
20
+			ga('send', 'pageview');
21
+		}
22
+		cookieName = 'FZ_COOKIECONSENT'
23
+		for (let level = 3; level <= 3; level++) {
24
+			if (localStorage.getItem(cookieName + '_' + level) && localStorage.getItem(cookieName + '_' + level) > Math.round(Date.now() / 1000)) {
25
+				initGoogleAnalytics();
26
+				console.log('google analytics init')
27
+				break;
28
+			}
29
+		}
30
+		jQuery(document).on('user_privacy_changed', function(event, params) {
31
+			if (params.level >= 3) {
32
+				initGoogleAnalytics();
33
+				console.log('google analytics init via event');
34
+			}
35
+		});
36
+	</script>
37
+<?php endif; ?>
0 38
\ No newline at end of file