Skip to content

Draft: Add an environment variable for controlling inclusion of analytics scripts

Sarah German requested to merge analytics-off-switch into main

What does this MR do and why?

Adds a method to turn off analytics without making code changes or an MR.

This would've allowed us to resolve problems with the Docs site during the analytics incident more quickly.

Screenshots

Build with analytics Build without analytics
image image
  • Build with: NANOC_ENV="production" CI_DEFAULT_BRANCH="main" CI_COMMIT_REF_NAME="main" GITLAB_DOCS_ANALYTICS_ENABLED="true" make view
  • Build without: NANOC_ENV="production" CI_DEFAULT_BRANCH="main" CI_COMMIT_REF_NAME="main" make view
  • Build without: NANOC_ENV="production" CI_DEFAULT_BRANCH="main" CI_COMMIT_REF_NAME="main" GITLAB_DOCS_ANALYTICS_DISABLED="hotdog" make view

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Configure a local GitLab Docs environment: https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/setup.md.
  2. Clear out any previous builds: make clean
  3. Run a build with analytics: NANOC_ENV="production" CI_DEFAULT_BRANCH="main" CI_COMMIT_REF_NAME="main" GITLAB_DOCS_ANALYTICS_ENABLED="true" make view
  4. View the HTML source of the homepage, the search page, the 404, and a standard interior page (our 4 templates). No analytics scripts or OneTrust should be present.
  5. Stop the preview env and clear out the build: make clean
  6. Run a build without analytics: NANOC_ENV="production" CI_DEFAULT_BRANCH="main" CI_COMMIT_REF_NAME="main" make view
  7. Check the same pages as step 4. Pages should not include analytics scripts or OneTrust.

Note that to really test this, we'll need to run a build with the new variable after we merge this. 😄

Check for analytics scripts by searching the HTML source for things like: bizible googletagmanager linkedin_analytics geolocation.onetrust.com

Merge request acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Achilleas Pipinellis

Merge request reports

Loading