Skip to content

Commit 02cbea0

Browse files
committed
Fixed analytics errors
1 parent 2885b40 commit 02cbea0

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/ControlPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { Login } from "./Login";
88
import { Authenticated } from "./Authenticated";
99
import { Logout } from "./Logout";
1010
import { type ErrorLogInterface, type ErrrorAppDataInterface } from "@churchapps/helpers";
11-
import { AnalyticsHelper, UserHelper, ErrorHelper } from "@churchapps/apphelper";
11+
import { AnalyticsHelper } from "./helpers";
12+
import { UserHelper, ErrorHelper } from "@churchapps/apphelper";
1213
import { UI } from "./ui/Test";
1314
import { Pingback } from "./Pingback";
1415

src/Login.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const Login: React.FC = () => {
5151
handleRedirect={handleRedirect}
5252
defaultEmail={process.env.REACT_APP_STAGE === "demo" ? "demo@chums.org" : undefined}
5353
defaultPassword={process.env.REACT_APP_STAGE === "demo" ? "password" : undefined}
54+
showFooter={true}
5455
/>
5556
</div>
5657

src/helpers/AnalyticsHelper.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ReactGA4 from "react-ga4";
2+
import { CommonEnvironmentHelper, UserHelper } from "@churchapps/helpers";
3+
4+
export class AnalyticsHelper {
5+
6+
static init = () => {
7+
if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
8+
ReactGA4.initialize(CommonEnvironmentHelper.GoogleAnalyticsTag);
9+
AnalyticsHelper.logPageView();
10+
}
11+
}
12+
13+
static logPageView = () => {
14+
if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
15+
this.setChurchKey();
16+
ReactGA4.send({ hitType: "pageview", page: window.location.pathname + window.location.search });
17+
}
18+
}
19+
20+
static logEvent = (category: string, action: string, label?:string) => {
21+
if (CommonEnvironmentHelper.GoogleAnalyticsTag !== "" && typeof(window)!=="undefined") {
22+
this.setChurchKey();
23+
ReactGA4.event({ category, action, label });
24+
}
25+
}
26+
27+
private static setChurchKey = () => {
28+
const churchKey = UserHelper?.currentUserChurch?.church?.subDomain;
29+
if (churchKey) ReactGA4.set({church_key: churchKey });
30+
}
31+
32+
}

src/helpers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ export * from "./Interfaces";
22

33
// AppHelper imports (for person components)
44
export {
5-
ApiHelper, ArrayHelper, CurrencyHelper, DateHelper, PersonHelper, UniqueIdHelper, AnalyticsHelper, ErrorHelper, CommonEnvironmentHelper, Locale, UserHelper
5+
ApiHelper, ArrayHelper, CurrencyHelper, DateHelper, PersonHelper, UniqueIdHelper, ErrorHelper, CommonEnvironmentHelper, Locale, UserHelper
66
} from "@churchapps/apphelper";
77

88
// Donation helper from donations package
99
export { DonationHelper } from "@churchapps/apphelper-donations";
1010

1111
// Local helpers
12+
export { AnalyticsHelper } from "./AnalyticsHelper";
1213
export { ChumsPersonHelper } from "./ChumsPersonHelper";
1314
export { ConditionHelper } from "./ConditionHelper";
1415
export { EnvironmentHelper } from "./EnvironmentHelper";

0 commit comments

Comments
 (0)