From e4dcb89e19840839ceed115992e8222527fbb6d6 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:27:51 +0100 Subject: [PATCH] Fetch the matomo properties from the config, not from the environment (#756) --- docker/docker-compose.yml | 1 - src/environments/environment.production.ts | 5 ----- src/environments/environment.ts | 5 ----- src/main.browser.ts | 26 +++++++++++++--------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 68e48ba1775..c6cc475a30c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -29,7 +29,6 @@ services: - ./config.prod.yml:/app/config/config.prod.yml # - ./aai.js:/app/dist/browser/aai.js # - ./dspace-ui.json:/app/docker/dspace-ui.json:rw - - ./matomo-settings.ts:/src/matomo/matomo-settings.ts build: context: .. dockerfile: Dockerfile diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index c09d6dfb9bc..36c62dfe58e 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -10,9 +10,4 @@ export const environment: Partial = { time: false, inlineCriticalCss: false, }, - - matomo: { - hostUrl: 'http://localhost:8135/', - siteId: '1', - } }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 94277b694ed..7b4848bbc79 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -26,11 +26,6 @@ export const environment: Partial = { }, signpostingEnabled: false, - - matomo: { - hostUrl: 'http://localhost:8135/', - siteId: '1', - } }; /* diff --git a/src/main.browser.ts b/src/main.browser.ts index a14d420974b..d17101d07a6 100644 --- a/src/main.browser.ts +++ b/src/main.browser.ts @@ -46,17 +46,23 @@ const main = () => { function addMatomoStatistics() { (window as any)._paq = (window as any)._paq || []; - // Push all configuration commands first - (window as any)._paq.push(['setTrackerUrl', environment.matomo.hostUrl + 'matomo.php']); - (window as any)._paq.push(['setSiteId', environment.matomo.siteId]); - (window as any)._paq.push(['enableLinkTracking']); + void fetch('assets/config.json') + .then((response) => response.json()) + .then((config) => { + const matomoConfig = config.matomo; - const g = document.createElement('script'); - g.type = 'text/javascript'; - g.async = true; - g.defer = true; - g.src = environment.matomo.hostUrl + 'matomo.js'; - document.getElementsByTagName('head')[0].appendChild(g); + // Push all configuration commands first + (window as any)._paq.push(['setTrackerUrl', matomoConfig.hostUrl + 'matomo.php']); + (window as any)._paq.push(['setSiteId', matomoConfig.siteId]); + (window as any)._paq.push(['enableLinkTracking']); + + const g = document.createElement('script'); + g.type = 'text/javascript'; + g.async = true; + g.defer = true; + g.src = matomoConfig.hostUrl + 'matomo.js'; + document.getElementsByTagName('head')[0].appendChild(g); + }); } // support async tag or hmr