UNPKG

mui-extended

Version:

Extended UI Components built on Material UI

17 lines (16 loc) 1.24 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import Script from "next/script"; import { useStateWithLocalStorage } from "./utils"; /** * Adds Google Analytics to Webpage , if NEXT_PUBLIC_GOOGLE_ANALYTICS_ID is set */ export var GoogleAnalytics = function () { // eslint-disable-next-line var _a = useStateWithLocalStorage("cookie-preference", { performance: true }), cookiePreference = _a[0], setCookiePreference = _a[1], checked = _a[2]; if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID && checked && cookiePreference.performance) { return (_jsxs(_Fragment, { children: [_jsx(Script, { strategy: "lazyOnload", src: "https://www.googletagmanager.com/gtag/js?id=".concat(process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID) }), _jsx(Script, { strategy: "lazyOnload", id: "GoogleAnalytics", children: "\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '".concat(process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID, "', {\n page_path: window.location.pathname,\n });\n ") })] })); } return _jsx(_Fragment, {}); };