Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added env variable to enable/disable matomo tracking #499

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading