Skip to content

Commit 44d2ca0

Browse files
authored
Merge pull request #2519 from IntersectMBO/feat/integrate-matomo
feat: integrate matomo analytics
2 parents 91c3725 + b805536 commit 44d2ca0

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ changes.
1212

1313
### Added
1414

15-
-
15+
- Integrate matomo analytics
1616

1717
### Fixed
1818

govtool/frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ import {
3939
import { PublicRoute } from "./pages/PublicRoute";
4040
import { TopBanners } from "./components/organisms/TopBanners";
4141
import { DashboardHome } from "./pages/DashboardHome";
42+
import { useMatomo } from "./hooks/useMatomo";
4243

4344
export default () => {
45+
useMatomo();
4446
const { isProposalDiscussionForumEnabled } = useFeatureFlag();
4547
const { enable, isEnabled } = useCardano();
4648
const navigate = useNavigate();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable func-names */
2+
/* eslint-disable no-multi-assign */
3+
/* eslint-disable prefer-template */
4+
/* eslint-disable no-underscore-dangle */
5+
/* eslint-disable wrap-iife */
6+
import { useEffect } from "react";
7+
8+
export const useMatomo = () => {
9+
useEffect(() => {
10+
const env = import.meta.env.VITE_APP_ENV;
11+
if (env !== "prodction" || env !== "staging") {
12+
return;
13+
}
14+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
15+
// @ts-expect-error
16+
const _paq = (window._paq = window._pag || []);
17+
_paq.push(["trackPageView"]);
18+
_paq.push(["enableLinkTracking"]);
19+
(function () {
20+
const u = "//analytics.gov.tools/";
21+
_paq.push(["setTrackerUrl", u + "matomo.php"]);
22+
_paq.push(["setSiteId", env === "production" ? "1" : "2"]);
23+
const d = document;
24+
const g = d.createElement("script");
25+
const s = d.getElementsByTagName("script")[0];
26+
g.async = true;
27+
g.src = u + "matomo.js";
28+
s.parentNode?.insertBefore(g, s);
29+
})();
30+
}, []);
31+
};

0 commit comments

Comments
 (0)