Skip to content

Commit

Permalink
Merge pull request #2519 from IntersectMBO/feat/integrate-matomo
Browse files Browse the repository at this point in the history
feat: integrate matomo analytics
  • Loading branch information
MSzalowski authored Dec 13, 2024
2 parents 91c3725 + b805536 commit 44d2ca0
Show file tree
Hide file tree
Showing 3 changed files with 34 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
31 changes: 31 additions & 0 deletions govtool/frontend/src/hooks/useMatomo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* 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(() => {
const env = import.meta.env.VITE_APP_ENV;
if (env !== "prodction" || env !== "staging") {
return;
}
// 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", 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 44d2ca0

Please sign in to comment.