Repository navigation
feat(demo): inject GoatCounter tracker at runtime for public demo builds - #152
Merged
Merged
Conversation
The build-time approach (VITE_GC_COUNT baking the tracker into the frontend bundle) stopped working the moment the demo started running official release assets: CI builds do not set that env, so the tracker silently disappeared from the demo back in v2.9.23. The server now injects the snippet into the served index.html when DEMO=1 and GC_ORIGIN are set (computed once at startup), and the CSP gains the origin in script-src and connect-src only when GC_ORIGIN is defined. Regular installs define neither and never call home. Hits keep the /demo path prefix on the shared GoatCounter site. Closes #103
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.
Fixes #103 with a different approach than the original branch.
The build-time variant (VITE_GC_COUNT baking the snippet into the frontend bundle) has a flaw: the public demo runs official release assets built by CI without that env, so the tracker silently disappeared from the demo when it moved to official assets (v2.9.23). Confirmed today: the live demo serves no tracker at all.
This reworks it as runtime injection:
gcIndexOverride(main.go) computes the injected index.html once at startup, only whenDEMO=1andGC_ORIGINare set;spaHandlerserves that override for/,/index.htmland the SPA fallback.sw.jsand assets are untouched.security.cspValueadds the origin toscript-srcandconnect-srconly whenGC_ORIGINis defined (ported from the original branch)./demopath prefix on the shared GoatCounter site.Verification: unit tests for the injection (env gates, trailing slash, HTML without
</head>) and for the CSP gate; deployed the preview (2.9.99-103gc) to the public demo and verified end to end with a real browser:count.jsloads and the beacon goes out withp=%2Fdemo%2F.