From f2158ce1aa2dd8b56fb1ea0e074803cbbac84353 Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:44:04 +0100 Subject: [PATCH] Added env variable to enable/disable matomo tracking --- .env.sample | 1 + docker-compose.yml | 1 + lib/util/analytics-tracker.js | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index efe994b0..ae55d297 100644 --- a/.env.sample +++ b/.env.sample @@ -53,5 +53,6 @@ DISTRICT_TO_SNAPSHOT= # Comma separated list of district to snapshot (used only MATOMO_URL= MATOMO_SITE_ID= MATOMO_TOKEN_AUTH= +TRACKING_ENABLED=1 # Set to 0 to disable, 1 to enable IS_GENERATE_BANID_ON_ASSEMBLY= # Set to true to generate banId on assembly diff --git a/docker-compose.yml b/docker-compose.yml index cc96ac2d..cd3b0ead 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,6 +79,7 @@ services: - FORCE_DOWNLOAD_DATASETS= - IS_GENERATE_BANID_ON_ASSEMBLY=${IS_GENERATE_BANID_ON_ASSEMBLY} - MIGRATION_DATA_FOLDER_PATH=${MIGRATION_DATA_FOLDER_PATH} + - TRACKING_ENABLED=${TRACKING_ENABLED} ports: - "${PORT:-5000}:5000" volumes: diff --git a/lib/util/analytics-tracker.js b/lib/util/analytics-tracker.js index f3f3df8f..0a22a87b 100644 --- a/lib/util/analytics-tracker.js +++ b/lib/util/analytics-tracker.js @@ -10,10 +10,13 @@ const { MATOMO_URL, MATOMO_SITE_ID, MATOMO_TOKEN_AUTH, - NODE_ENV + NODE_ENV, + TRACKING_ENABLED, } = process.env const isDevMode = NODE_ENV !== 'production' +const trackingActivated = Number.parseInt(TRACKING_ENABLED, 10) === 1 + const logMatomoError = err => { console.log('error tracking request:', err) } @@ -32,6 +35,10 @@ export const getTrackEvent = ({category, action, name, value = 1}) => ({ }) export const sendToTracker = async (params = {}) => { + if (!trackingActivated) { + return + } + const {url, ua, download, trackEvent, ...otherParams} = params const requiredParams = { idsite: MATOMO_SITE_ID,