UNPKG

@churchapps/apphelper

Version:

Library of helper functions for React and NextJS ChurchApps

30 lines 1.16 kB
var _a; import ReactGA from "react-ga4"; import { CommonEnvironmentHelper, UserHelper } from "@churchapps/helpers"; export class AnalyticsHelper { } _a = AnalyticsHelper; AnalyticsHelper.init = () => { if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof (window) !== "undefined") { ReactGA.initialize([{ trackingId: CommonEnvironmentHelper.GoogleAnalyticsTag }]); _a.logPageView(); } }; AnalyticsHelper.logPageView = () => { if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof (window) !== "undefined") { _a.setChurchKey(); ReactGA.send({ hitType: "pageview", page: window.location.pathname + window.location.search }); } }; AnalyticsHelper.logEvent = (category, action, label) => { if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof (window) !== "undefined") { _a.setChurchKey(); ReactGA.event({ category, action, label }); } }; AnalyticsHelper.setChurchKey = () => { const churchKey = UserHelper?.currentUserChurch?.church?.subDomain; if (churchKey) ReactGA.set({ church_key: churchKey }); }; //# sourceMappingURL=AnalyticsHelper.js.map