Skip to content

Commit

Permalink
feat: integrate matomo analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Dec 13, 2024
1 parent 32a3f8b commit 1bd00c6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ changes.

### Added

-
- Integrate matomo analytics

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import {
import { PublicRoute } from "./pages/PublicRoute";
import { TopBanners } from "./components/organisms/TopBanners";
import { DashboardHome } from "./pages/DashboardHome";
import { useMatomo } from "./hooks/useMatomo";

export default () => {
useMatomo();
const { isProposalDiscussionForumEnabled } = useFeatureFlag();
const { enable, isEnabled } = useCardano();
const navigate = useNavigate();
Expand Down
30 changes: 30 additions & 0 deletions govtool/frontend/src/hooks/useMatomo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable func-names */
/* eslint-disable no-multi-assign */
/* eslint-disable prefer-template */
/* eslint-disable no-underscore-dangle */
/* eslint-disable wrap-iife */
import { useEffect } from "react";

export const useMatomo = () => {
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const _paq = (window._paq = window._pag || []);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {
const u = "//analytics.gov.tools/";
_paq.push(["setTrackerUrl", u + "matomo.php"]);
_paq.push([
"setSiteId",
import.meta.env.VITE_APP_ENV === "production" ? "1" : "2",
]);
const d = document;
const g = d.createElement("script");
const s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = u + "matomo.js";
s.parentNode?.insertBefore(g, s);
})();
}, []);
};

0 comments on commit 1bd00c6

Please sign in to comment.