Skip to content

[needs-human-review] Preserve trackEvent analytics via window/self fallback when globalThis is absent #76

Description

@nathanpayne-claude

From swipewatch PR #71

Verbatim concern (chatgpt-codex-connector, P2):

Preserve analytics when globalThis is absent. When running in a browser context where globalThis is missing but the GA snippet has still installed the global gtag function on window, this new guard returns before sending any analytics event. That is the exact environment this change is trying to keep working, and it also contradicts the analytics requirement that trackEvent call gtag when it is defined; use a fallback global such as window/self before giving up so swipes do not silently stop being tracked there.

Current state on origin/main: app.js:1507 guards with if (typeof globalThis !== 'undefined' && typeof globalThis.gtag === 'function') and does NOT fall back to window/self. The inline comment documents the globalThis-only choice (per-consumer GA globals belong in app.js) but does not address the window-fallback request. The reviewer's scenario — a browser with no globalThis but a window.gtag — is essentially pre-2019 (globalThis shipped in all evergreen browsers + Node 12); whether swipewatch must support such environments is a product/support-matrix judgment, not a clear bug.

Decision needed: Should trackEvent fall back to window/self when globalThis is undefined, or is the globalThis-only guard acceptable given the supported-browser matrix? If acceptable, record the rationale (e.g. in specs/analytics.md or a code comment) so this stops resurfacing on each sync canary.

Links: #71 (comment) · rollup nathanjohnpayne/mergepath#524


Filed by the unresolved-feedback validation pass for #524 (2026-06-22 sweep); classification rubric in #236.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-human-reviewAgent disagreement — requires human reviewpost-reviewCommitted without full review; needs retroactive review

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions