Tracking updates#26
Merged
Merged
Conversation
… GA4, GTM, and GA measurement IDs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR generalizes the documentation site’s analytics integration by supporting multiple Google analytics entry points (GA4/gtag, GTM, and alternate GA4 tag IDs) and updating the cookie-consent banner to appear whenever any analytics integration is enabled.
Changes:
- Added
_env_id()inconf.pyto normalize analytics-related environment variables and exposeGA_MEASUREMENT_ID,GTM_CONTAINER_ID, andGA4_TAG_IDviahtml_context. - Refactored
_templates/layout.htmlto conditionally load gtag and/or GTM based on the provided IDs and to treat analytics as enabled when either is configured. - Updated the cookie consent banner condition so it displays for any enabled analytics integration (not just GA4 measurement ID).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
conf.py |
Normalizes analytics env vars and adds additional analytics IDs to html_context. |
_templates/layout.html |
Loads analytics scripts based on available IDs and broadens cookie banner enablement logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+19
| def _env_id(name): | ||
| """Return a normalized analytics ID from the environment. | ||
|
|
||
| Treats empty strings and literal 'none'/'null'/'undefined' as disabled. | ||
| """ | ||
| value = os.environ.get(name, "") | ||
| if value is None: | ||
| return "" | ||
|
|
||
| text = str(value).strip() | ||
| return "" if text.lower() in ("", "none", "null", "undefined") else text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances and generalizes analytics integration in the documentation site. It introduces flexible support for multiple analytics providers (GA4/gtag, Google Tag Manager, and GA4 tag IDs) via environment variables, and improves how analytics IDs are handled and normalized. The cookie consent banner is also updated to display when any analytics integration is enabled.
Analytics integration and configuration:
_env_idfunction inconf.pyto normalize analytics environment variables, treating empty strings and common "off" values as disabled.html_contextinconf.pyto supportGA_MEASUREMENT_ID,GTM_CONTAINER_ID, andGA4_TAG_IDenvironment variables, using the new normalization function.Template and loader improvements:
_templates/layout.htmlto support loading analytics scripts for GA4/gtag, GTM, and GA4 tag IDs, enabling them based on the provided environment variables. [1] [2]_templates/layout.htmlto display if any analytics integration is enabled, not just GA4.