From 7f2e0999b7523804cd20738ec956a5b295bd82b4 Mon Sep 17 00:00:00 2001 From: Rakov Roman Date: Wed, 1 Jun 2022 12:21:24 +0300 Subject: [PATCH] fix(matomo): fixed matomo scope for production --- src/config/matomo.tsx | 25 +++++++++++++++++++++++++ src/config/pages.tsx | 2 +- src/features/App/index.tsx | 9 ++------- src/features/GlobalStores/index.tsx | 4 +++- 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/config/matomo.tsx diff --git a/src/config/matomo.tsx b/src/config/matomo.tsx new file mode 100644 index 00000000..f235a0c0 --- /dev/null +++ b/src/config/matomo.tsx @@ -0,0 +1,25 @@ +import { createInstance } from '@jonkoops/matomo-tracker-react' +import { InstanceParams } from '@jonkoops/matomo-tracker-react/lib/types' + +import { PAGES } from 'config/pages' + +const getMatomoInstance = () => { + let matomoInstance: InstanceParams = { + siteId: 999, + urlBase: 'link.to.domain', + } + + switch (process.env.REACT_APP_CLIENT) { + case 'instat': + matomoInstance = { + ...matomoInstance, + siteId: 1, + urlBase: PAGES.matomoInstatBaseUrl, + } + break + } + + return createInstance(matomoInstance) +} + +export const matomoInstance = getMatomoInstance() diff --git a/src/config/pages.tsx b/src/config/pages.tsx index 12ffcfaa..0fe4b6c8 100644 --- a/src/config/pages.tsx +++ b/src/config/pages.tsx @@ -2,7 +2,7 @@ export const PAGES = { about_the_project: 'https://instatsport.com/InStatTV/ott_platform', home: '/', match: '/matches', - matomoBaseUrl: 'https://matomo.instat.tv/', + matomoInstatBaseUrl: 'https://matomo.instat.tv/', player: '/players', team: '/teams', tournament: '/tournaments', diff --git a/src/features/App/index.tsx b/src/features/App/index.tsx index 093fa7f6..2309a0ce 100644 --- a/src/features/App/index.tsx +++ b/src/features/App/index.tsx @@ -1,11 +1,11 @@ import { Suspense } from 'react' import { Router } from 'react-router-dom' -import { createInstance, MatomoProvider } from '@jonkoops/matomo-tracker-react' +import { MatomoProvider } from '@jonkoops/matomo-tracker-react' import { history } from 'config/history' import { client } from 'config/clients' -import { PAGES } from 'config/pages' +import { matomoInstance } from 'config/matomo' import { setClientTitleAndDescription } from 'helpers/setClientHeads' import { isMatchPage } from 'helpers/isMatchPage' @@ -21,11 +21,6 @@ import { AuthenticatedApp } from './AuthenticatedApp' setClientTitleAndDescription(client.title, client.description) -const matomoInstance = createInstance({ - siteId: 1, - urlBase: PAGES.matomoBaseUrl, -}) - const Main = () => { const { loadingUser, user } = useAuthStore() diff --git a/src/features/GlobalStores/index.tsx b/src/features/GlobalStores/index.tsx index 940222d2..80cb9c19 100644 --- a/src/features/GlobalStores/index.tsx +++ b/src/features/GlobalStores/index.tsx @@ -19,7 +19,9 @@ export const GlobalStores = ({ children }: Props) => { const { trackPageView } = useMatomo() useEffect(() => { - trackPageView() + const isProduction = process.env.REACT_APP_ENV === 'production' + + if (isProduction) trackPageView() }, [trackPageView, pathname, search]) return (