UNPKG

@caesar1030/react-analytics

Version:
33 lines (32 loc) 807 B
import { j as c } from "./react-analytics.es14.js"; import o, { useEffect as u, createContext as a, useContext as f } from "react"; import { GA4 as m } from "./react-analytics.es7.js"; const i = a(null), v = ({ measurementId: e, config: n, children: r }) => { const t = o.useMemo(() => new m(e), [e]); u(() => { t.initialize(n); }, [n, t]); const s = o.useMemo( () => ({ config: t.configInfo, ga4Event: t.event.bind(t), ga4Config: t.config.bind(t), ga4Consent: t.consent.bind(t), ga4Set: t.set.bind(t) }), [t] ); return /* @__PURE__ */ c.jsx(i.Provider, { value: s, children: r }); }, A = () => { const e = f(i); if (!e) throw new Error("useGA must be used within a GAProvider"); return e; }; export { v as GAProvider, A as useGA };