Skip to content

Commit

Permalink
Merge pull request #499 from BaseAdresseNationale/antoineludeau/add-e…
Browse files Browse the repository at this point in the history
…nv-var-to-enable-disable-tracking

Added env variable to enable/disable matomo tracking
  • Loading branch information
antoineludeau authored Dec 10, 2024
2 parents 5d2fc2c + f2158ce commit 734c4a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion lib/util/analytics-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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,
Expand Down

0 comments on commit 734c4a3

Please sign in to comment.