-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2519 from IntersectMBO/feat/integrate-matomo
feat: integrate matomo analytics
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ changes. | |
|
||
### Added | ||
|
||
- | ||
- Integrate matomo analytics | ||
|
||
### Fixed | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); | ||
}, []); | ||
}; |