Conversation
There was a problem hiding this comment.
Pull request overview
Adds Google Analytics (gtag.js) tracking to the per-distribution download page.
Changes:
- Injects the Google tag loader script for measurement ID
G-E3BVDYNVRP - Adds an inline GA initialization/config snippet on the download page
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <!-- Google tag (gtag.js) --> | ||
| <script | ||
| async src="https://www.googletagmanager.com/gtag/js?id=G-E3BVDYNVRP"></script> |
There was a problem hiding this comment.
These <script> tags are rendered before <BaseLayout>, but BaseLayout.astro outputs the document <!doctype html><html><head>... (src/layouts/BaseLayout.astro:35+). That means this page will emit scripts before the doctype/html element, producing invalid document structure (and potentially quirks mode / scripts not where expected). Move the GA (and the existing AdSense) tags into the layout <head> (e.g., add a named head slot in BaseLayout and pass them via the page) so they render inside <head>.
| <script> | ||
| window.dataLayer = window.dataLayer || []; | ||
| function gtag(){dataLayer.push(arguments);} | ||
| gtag('js', new Date()); | ||
|
|
||
| gtag('config', 'G-E3BVDYNVRP'); |
There was a problem hiding this comment.
In Astro, an inline <script> in a .astro template is processed/bundled as a module unless marked is:inline. In module scope, dataLayer is not a global binding, so dataLayer.push(...) will throw a ReferenceError when gtag() runs. Fix by making this script is:inline (classic script semantics) and/or by referencing window.dataLayer explicitly (e.g., assign a local const dataLayer = window.dataLayer = window.dataLayer || []) and attaching gtag to window if it needs to be globally callable.
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'G-E3BVDYNVRP'); | |
| <script is:inline> | |
| const dataLayer = window.dataLayer = window.dataLayer || []; | |
| window.gtag = window.gtag || function gtag(){dataLayer.push(arguments);} | |
| window.gtag('js', new Date()); | |
| window.gtag('config', 'G-E3BVDYNVRP'); |
| <script | ||
| async src="https://www.googletagmanager.com/gtag/js?id=G-E3BVDYNVRP"></script> | ||
| <script> | ||
| window.dataLayer = window.dataLayer || []; | ||
| function gtag(){dataLayer.push(arguments);} | ||
| gtag('js', new Date()); | ||
|
|
||
| gtag('config', 'G-E3BVDYNVRP'); |
There was a problem hiding this comment.
The GA measurement ID is hard-coded here. To make it easier to change per-environment (staging/prod) and keep tracking IDs centralized, consider reading it from config/env (similar to how src/config/site.ts uses import.meta.env.PUBLIC_*) and only rendering the tag when the ID is set.
Review timed out before producing output. Retry skipped due to frequent timeouts for this repo/author. |
Review Details
|
No description provided.