You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "Yilialinn (via GitHub)" <gi...@apache.org> on 2026/10/13 09:22:11 UTC
[PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Yilialinn opened a new pull request, #2136:
URL: https://github.com/apache/apisix-website/pull/2136
The production Astro layout omits the GA4 tag, leaving the existing APISIX measurement stream without visits from `apisix.apache.org`. Restore `G-WQLBQL6GY3` in the shared layout for both locales and documentation pages. Load it only on the exact production hostname, asynchronously, and scope cookies to the APISIX subdomain so local and Netlify preview visits do not contaminate production data.
Validation: seven analytics behavior tests pass; the Analytics and Base components compile with the lockfile's Astro compiler 3.0.1; whitespace checks and independent review pass. The behavior tests are included in CI. No full local site build was run; CI and post-deployment GA4 verification remain pending. This change cannot recover previously uncollected visits.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "kayx23 (via GitHub)" <gi...@apache.org>.
kayx23 commented on code in PR #2136:
URL: https://github.com/apache/apisix-website/pull/2136#discussion_r4259352032
##########
next/scripts/analytics.test.mjs:
##########
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import test from 'node:test';
+import vm from 'node:vm';
+
+const source = await readFile(new URL('../src/components/Analytics.astro', import.meta.url), 'utf8');
+const script = source.match(/<script is:inline>([\s\S]*?)<\/script>/)[1];
Review Comment:
No change needed for this finding: if the component loses or changes the inline block, the test fails immediately at this extraction line. An explicit assertion would only improve the diagnostic wording; it does not change the behavior under test or mask a passing result.
##########
next/src/components/Analytics.astro:
##########
@@ -0,0 +1,17 @@
+<!-- Keep production measurement independent of the build/preview environment. -->
+<script is:inline>
+ (() => {
+ if (window.location.hostname !== 'apisix.apache.org') return;
+
+ window.dataLayer = window.dataLayer || [];
+ window.gtag = window.gtag || function () { window.dataLayer.push(arguments); };
+ window.gtag('js', new Date());
+ // Scope cookies to this project rather than the shared apache.org domain.
+ window.gtag('config', 'G-WQLBQL6GY3', { cookie_domain: 'apisix.apache.org' });
+
+ const tag = document.createElement('script');
+ tag.async = true;
+ tag.src = 'https://www.googletagmanager.com/gtag/js?id=G-WQLBQL6GY3';
+ document.head.appendChild(tag);
Review Comment:
No change: the queued and calls are established before the dynamically created external script can execute. The async resource cannot run until it has been appended, so moving ahead of queue initialization would not improve determinism and would introduce a theoretical race instead.
##########
next/scripts/analytics.test.mjs:
##########
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import test from 'node:test';
+import vm from 'node:vm';
+
+const source = await readFile(new URL('../src/components/Analytics.astro', import.meta.url), 'utf8');
+const script = source.match(/<script is:inline>([\s\S]*?)<\/script>/)[1];
+
+function visit(hostname, existing = {}) {
+ const loaded = [];
+ const window = { location: { hostname }, ...existing };
+ const document = {
+ createElement: () => ({}),
Review Comment:
No change: this stub intentionally captures the created element, and the test already asserts the two script properties the implementation relies on ( and the exact ). Adding unused DOM methods such as would not catch a current behavior gap.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "Yilialinn (via GitHub)" <gi...@apache.org>.
Yilialinn commented on code in PR #2136:
URL: https://github.com/apache/apisix-website/pull/2136#discussion_r4266586591
##########
next/src/components/Analytics.astro:
##########
@@ -0,0 +1,17 @@
+<!-- Keep production measurement independent of the build/preview environment. -->
+<script is:inline>
+ (() => {
+ if (window.location.hostname !== 'apisix.apache.org') return;
+
+ window.dataLayer = window.dataLayer || [];
+ window.gtag = window.gtag || function () { window.dataLayer.push(arguments); };
+ window.gtag('js', new Date());
+ // Scope cookies to this project rather than the shared apache.org domain.
+ window.gtag('config', 'G-WQLBQL6GY3', { cookie_domain: 'apisix.apache.org' });
+
+ const tag = document.createElement('script');
+ tag.async = true;
+ tag.src = 'https://www.googletagmanager.com/gtag/js?id=G-WQLBQL6GY3';
+ document.head.appendChild(tag);
Review Comment:
Fixed in f8288c7ed3847eb718d2fab0771c7adf1bf71ed1. The Redis regression now requires exactly the intended inline Analytics bootstrap and continues to reject module scripts, Astro islands, and any additional executable scripts. Both English and Chinese Redis pages are checked. Added browser coverage that serves the generated HTML under simulated production and Netlify hostnames, verifies the exact async Google tag and scoped configuration only in production, and intercepts Google requests so the tests send no analytics traffic.
Validation: 7 analytics behavior tests, syntax/whitespace checks, and independent review pass. The four desktop/mobile production/preview browser cases also pass locally against a compiled Analytics HTML fixture; this is not a full-site build or a substitute for the complete Redis content regression. The new head has been pushed for both required CI workflows to validate the actual generated/overlaid site.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "Yilialinn (via GitHub)" <gi...@apache.org>.
Yilialinn closed pull request #2136: fix: restore production GA4 collection in Astro layout
URL: https://github.com/apache/apisix-website/pull/2136
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "kayx23 (via GitHub)" <gi...@apache.org>.
kayx23 commented on code in PR #2136:
URL: https://github.com/apache/apisix-website/pull/2136#discussion_r4259352362
##########
next/src/components/Analytics.astro:
##########
@@ -0,0 +1,17 @@
+<!-- Keep production measurement independent of the build/preview environment. -->
+<script is:inline>
+ (() => {
+ if (window.location.hostname !== 'apisix.apache.org') return;
+
+ window.dataLayer = window.dataLayer || [];
+ window.gtag = window.gtag || function () { window.dataLayer.push(arguments); };
+ window.gtag('js', new Date());
+ // Scope cookies to this project rather than the shared apache.org domain.
+ window.gtag('config', 'G-WQLBQL6GY3', { cookie_domain: 'apisix.apache.org' });
+
+ const tag = document.createElement('script');
+ tag.async = true;
+ tag.src = 'https://www.googletagmanager.com/gtag/js?id=G-WQLBQL6GY3';
+ document.head.appendChild(tag);
Review Comment:
No change: the queued initialization and configuration calls are established before the dynamically created external script can execute. The async resource cannot run until it has been appended, so moving the append operation ahead of queue initialization would not improve determinism and would introduce a theoretical race instead.
##########
next/scripts/analytics.test.mjs:
##########
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import test from 'node:test';
+import vm from 'node:vm';
+
+const source = await readFile(new URL('../src/components/Analytics.astro', import.meta.url), 'utf8');
+const script = source.match(/<script is:inline>([\s\S]*?)<\/script>/)[1];
+
+function visit(hostname, existing = {}) {
+ const loaded = [];
+ const window = { location: { hostname }, ...existing };
+ const document = {
+ createElement: () => ({}),
Review Comment:
No change: this stub intentionally captures the created element, and the test already asserts the two script properties the implementation relies on: the async flag and the exact source URL. Adding unused DOM methods would not catch a current behavior gap.
##########
next/src/components/Analytics.astro:
##########
@@ -0,0 +1,17 @@
+<!-- Keep production measurement independent of the build/preview environment. -->
+<script is:inline>
+ (() => {
+ if (window.location.hostname !== 'apisix.apache.org') return;
+
+ window.dataLayer = window.dataLayer || [];
+ window.gtag = window.gtag || function () { window.dataLayer.push(arguments); };
+ window.gtag('js', new Date());
+ // Scope cookies to this project rather than the shared apache.org domain.
+ window.gtag('config', 'G-WQLBQL6GY3', { cookie_domain: 'apisix.apache.org' });
+
+ const tag = document.createElement('script');
+ tag.async = true;
+ tag.src = 'https://www.googletagmanager.com/gtag/js?id=G-WQLBQL6GY3';
+ document.head.appendChild(tag);
Review Comment:
The new inline bootstrap is emitted on every page even when the hostname guard prevents GA from loading. Both `Astro main pages` and the full `build` now fail because `tests/e2e/ecosystem-pages.spec.mjs:166` still requires zero non-JSON-LD scripts on the Redis page (desktop and mobile). Please update that regression test to allow/assert this intentional hostname-gated analytics bootstrap, while preserving the no-framework-hydration boundary, so the PR does not merge with two failing required workflows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "Yilialinn (via GitHub)" <gi...@apache.org>.
Yilialinn commented on PR #2136:
URL: https://github.com/apache/apisix-website/pull/2136#issuecomment-6207083598
Closing this PR after checking the ASF website privacy policy. It restores Google Analytics 4 on `apisix.apache.org`, but ASF policy says Google Analytics cannot be used on ASF websites: https://privacy.apache.org/policies/website-policy.html. The production-only hostname check and cookie scoping do not change that restriction. If we need website analytics, the ASF Committers’ FAQ recommends requesting ASF-hosted Matomo instead: https://privacy.apache.org/faq/committers.html. Apologies for the churn.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: restore production GA4 collection in Astro layout [apisix-website]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2136:
URL: https://github.com/apache/apisix-website/pull/2136#discussion_r4257105276
##########
next/scripts/analytics.test.mjs:
##########
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import test from 'node:test';
+import vm from 'node:vm';
+
+const source = await readFile(new URL('../src/components/Analytics.astro', import.meta.url), 'utf8');
+const script = source.match(/<script is:inline>([\s\S]*?)<\/script>/)[1];
Review Comment:
If the `<script is:inline>` block is missing or the regex doesn't match, `source.match(...)` returns `null` and indexing `[1]` will throw a non-obvious TypeError. Make the failure explicit by asserting the match exists (or throwing a clear error) before accessing the capture group so test failures are diagnosable.
##########
next/src/components/Analytics.astro:
##########
@@ -0,0 +1,17 @@
+<!-- Keep production measurement independent of the build/preview environment. -->
+<script is:inline>
+ (() => {
+ if (window.location.hostname !== 'apisix.apache.org') return;
+
+ window.dataLayer = window.dataLayer || [];
+ window.gtag = window.gtag || function () { window.dataLayer.push(arguments); };
+ window.gtag('js', new Date());
+ // Scope cookies to this project rather than the shared apache.org domain.
+ window.gtag('config', 'G-WQLBQL6GY3', { cookie_domain: 'apisix.apache.org' });
+
+ const tag = document.createElement('script');
+ tag.async = true;
+ tag.src = 'https://www.googletagmanager.com/gtag/js?id=G-WQLBQL6GY3';
+ document.head.appendChild(tag);
Review Comment:
The GA4 loader appends the external gtag script *after* queueing `gtag('js'...)` and `gtag('config'...)`. While GA often tolerates this, the recommended pattern is to load the `gtag/js` script first (with `async`), then queue initialization/config so timing is deterministic (especially around consent/default settings and early pageview behavior). Consider inserting the script tag before the first `gtag(...)` calls, or at least appending the script before calling `gtag('config', ...)`.
##########
next/scripts/analytics.test.mjs:
##########
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import test from 'node:test';
+import vm from 'node:vm';
+
+const source = await readFile(new URL('../src/components/Analytics.astro', import.meta.url), 'utf8');
+const script = source.match(/<script is:inline>([\s\S]*?)<\/script>/)[1];
+
+function visit(hostname, existing = {}) {
+ const loaded = [];
+ const window = { location: { hostname }, ...existing };
+ const document = {
+ createElement: () => ({}),
Review Comment:
The test stub for `document.createElement` returns a plain object, which means the production code could start relying on common script element properties (`type`, `referrerPolicy`, `setAttribute`, etc.) and the test would not catch missing behavior. Consider returning a minimal \"script-like\" object (e.g., with `setAttribute` and `type` fields) or validating that the created element is specifically used as a script (e.g., by checking it contains the expected `src`/`async` after the script runs). This keeps the test robust if the analytics implementation evolves.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org