synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
30 lines (29 loc) • 1.03 kB
JavaScript
import { useEffect as i } from "react";
import { useCookiePreferences as c } from "../hooks/useCookiePreferences.js";
let a = !1;
const g = (e = "GTM-KPW4KS62") => {
const [n] = c();
return i(() => {
if (r(
window.location.hostname,
n
) && !a) {
window.dataLayer = window.dataLayer || [], window.dataLayer.push({
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
event: "gtm.js"
});
const s = document.getElementsByTagName("script")[0], t = document.createElement("script"), o = "&l=dataLayer";
t.async = !0, t.src = "https://www.googletagmanager.com/gtm.js?id=" + e + o, s.parentNode?.insertBefore(t, s), a = !0;
}
}, [n, e]), a;
};
function r(e, n) {
const s = n.analyticsAllowed, t = e.endsWith(".synapse.org"), o = e.includes("localhost.") || e.includes("staging.") || e.includes("dev.");
return s && t && !o;
}
export {
g as default,
r as shouldEnableGoogleAnalytics,
g as useGoogleAnalytics
};
//# sourceMappingURL=useGoogleAnalytics.js.map