Skip to content

Comments

fix(frontend): hardcode Simple Analytics for javachat.ai domain#23

Merged
WilliamAGH merged 3 commits intomainfrom
dev
Feb 11, 2026
Merged

fix(frontend): hardcode Simple Analytics for javachat.ai domain#23
WilliamAGH merged 3 commits intomainfrom
dev

Conversation

@WilliamAGH
Copy link
Owner

Simple Analytics traffic was being sent without an explicit production hostname, which can cause events to be attributed to the wrong site identity in the dashboard. This commit makes analytics wiring deterministic by hardcoding the canonical javachat.ai hostname in the injected script and noscript pixel.

It also switches to explicit HTML tag descriptors for the injection logic and keeps analytics disabled in development mode to avoid polluting production data during local testing.

  • Replace dynamic script filename logic with a fixed production script URL
  • Inject data-hostname="javachat.ai" on the analytics script tag
  • Add a hostname-qualified noscript pixel URL for non-JS tracking
  • Move analytics injection into a dedicated buildSimpleAnalyticsTags() helper
  • Use Vite HtmlTagDescriptor typing for safer transform output

Simple Analytics traffic was being sent without an explicit production hostname,
which can cause events to be attributed to the wrong site identity in the
dashboard. This commit makes analytics wiring deterministic by hardcoding the
canonical javachat.ai hostname in the injected script and noscript pixel.

It also switches to explicit HTML tag descriptors for the injection logic and
keeps analytics disabled in development mode to avoid polluting production data
during local testing.

- Replace dynamic script filename logic with a fixed production script URL
- Inject data-hostname="javachat.ai" on the analytics script tag
- Add a hostname-qualified noscript pixel URL for non-JS tracking
- Move analytics injection into a dedicated buildSimpleAnalyticsTags() helper
- Use Vite HtmlTagDescriptor typing for safer transform output
@WilliamAGH WilliamAGH self-assigned this Feb 11, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Centralized build-time analytics tag generation for production builds.
    • Analytics now load conditionally—only when the site is served from the configured production hostname.
    • Production-only fallback tracking added for environments without JavaScript.
    • Development/local builds omit analytics to simplify testing and avoid tracking during development.

Walkthrough

Extracts and centralizes Simple Analytics tag generation in frontend/vite.config.ts: adds typed HtmlTagDescriptor usage, constants for analytics configuration, and a buildSimpleAnalyticsTags(mode: string) helper that injects a runtime-guarded script and a noscript image into the HTML body for production only.

Changes

Cohort / File(s) Summary
Vite config — analytics builder
frontend/vite.config.ts
Added HtmlTagDescriptor import; introduced constants SIMPLE_ANALYTICS_QUEUE_ORIGIN, SIMPLE_ANALYTICS_HOSTNAME, SIMPLE_ANALYTICS_SCRIPT_URL, and a runtime guard script constant. Added buildSimpleAnalyticsTags(mode: string): HtmlTagDescriptor[] returning production-only script (runtime-guarded) and noscript image tags; transformIndexHtml now uses this builder and injects tags into the body.
Metadata / project files
manifest_file, package.json
Minor edits present (lines changed: +47/-13); likely metadata or dependency adjustments associated with the change set.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

✨🛠️ A tiny tracker moved with care,
From inline clutter to a builder's lair.
Guards check the host, prod gets the script,
Dev stays light — the build's well-equipped.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: hardcoding the Simple Analytics hostname for the javachat.ai domain, which is the core purpose of this PR.
Description check ✅ Passed The description clearly explains the problem (analytics without explicit hostname), the solution (hardcoding javachat.ai), and lists the specific changes made, all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73dfd9d57c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Prevent production analytics contamination from local preview, test, and staging usage by loading the Simple Analytics script only when the browser hostname is javachat.ai. Keep non-production mode builds analytics-free and remove hostname forcing from the noscript pixel so local/non-prod traffic cannot be attributed to production.

- Add runtime guard script that injects analytics only on javachat.ai

- Restrict build-time injection to mode=production only

- Remove hardcoded hostname override from noscript fallback URL
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/vite.config.ts`:
- Line 24: Update the noscript pixel URL to include the hostname query parameter
so attribution works when referrers are missing: change the construction of the
noScriptImageUrl (currently using SIMPLE_ANALYTICS_QUEUE_ORIGIN) to append
?hostname=... using SIMPLE_ANALYTICS_HOSTNAME so it matches the script's
data-hostname behavior; ensure encoding if needed and that noScriptImageUrl is
used in the noscript img src.

Ensure Simple Analytics noscript tracking can be reliably attributed even when browsers omit referrer metadata by including the explicit hostname query parameter in the noscript.gif URL. This aligns the noscript fallback with the script tag hostname configuration.

- Add hostname query parameter to noscript.gif URL

- Keep runtime guard and production-only injection behavior unchanged
@WilliamAGH WilliamAGH merged commit e89e077 into main Feb 11, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant