@churchapps/apphelper
Version:
Library of helper functions for React and NextJS ChurchApps
45 lines • 1.57 kB
JavaScript
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") {
try {
ReactGA.initialize([{ trackingId: CommonEnvironmentHelper.GoogleAnalyticsTag }]);
_a.logPageView();
}
catch (error) {
console.warn("Analytics initialization failed:", error);
}
}
};
AnalyticsHelper.logPageView = () => {
if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof (window) !== "undefined") {
try {
_a.setChurchKey();
ReactGA.send({ hitType: "pageview", page: window.location.pathname + window.location.search });
}
catch (error) {
console.warn("Analytics page view logging failed:", error);
}
}
};
AnalyticsHelper.logEvent = (category, action, label) => {
if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof (window) !== "undefined") {
try {
_a.setChurchKey();
ReactGA.event({ category, action, label });
}
catch (error) {
console.warn("Analytics event logging failed:", error);
}
}
};
AnalyticsHelper.setChurchKey = () => {
const churchKey = UserHelper?.currentUserChurch?.church?.subDomain;
if (churchKey)
ReactGA.set({ church_key: churchKey });
};
//# sourceMappingURL=AnalyticsHelper.js.map