41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
/* Google Analytics 4 — G-1JR9P2WP0B (loads only after cookie consent) */
|
|
(function () {
|
|
"use strict";
|
|
|
|
var MEASUREMENT_ID = "G-1JR9P2WP0B";
|
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
window.gtag = function gtag() {
|
|
window.dataLayer.push(arguments);
|
|
};
|
|
|
|
function isLocalHost() {
|
|
var host = location.hostname;
|
|
return host === "localhost" || host === "127.0.0.1";
|
|
}
|
|
|
|
function loadGa() {
|
|
if (window.__zsGaLoaded || isLocalHost()) return;
|
|
|
|
var consent = "";
|
|
try {
|
|
consent = localStorage.getItem("zs-analytics") || "";
|
|
} catch (e) {
|
|
consent = "";
|
|
}
|
|
if (consent !== "granted") return;
|
|
|
|
window.__zsGaLoaded = true;
|
|
window.gtag("js", new Date());
|
|
window.gtag("config", MEASUREMENT_ID);
|
|
|
|
var script = document.createElement("script");
|
|
script.async = true;
|
|
script.src = "https://www.googletagmanager.com/gtag/js?id=" + encodeURIComponent(MEASUREMENT_ID);
|
|
document.head.appendChild(script);
|
|
}
|
|
|
|
window.zsLoadAnalytics = loadGa;
|
|
loadGa();
|
|
})();
|