Skip to content

fix: error on a missing or invalid id - #218

Merged
yeskunall merged 3 commits into
mainfrom
fix-missing-id-error
Nov 19, 2026
Merged

yeskunall merged 3 commits into
mainfrom
fix-missing-id-error

Conversation

@yeskunall

@yeskunall yeskunall commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Problem

id is required by the option type, but a JavaScript Astro config can omit it. The integration currently emits script.setAttribute("data-website-id", "undefined"), so the tracker loads with no website ID and silently records nothing.

Change

Validate id at config setup, before any URL parsing:

  • astro build throws The id option is required.
  • astro dev logs the same message through Astro's integration logger and injects a small script that throws it in the browser console, so the failure is visible without reading the terminal.
  • Empty, whitespace-only, and non-string id values are rejected too, since a JavaScript config bypasses the type.

TypeScript already enforces id: string; this is the runtime guard for JavaScript configs.

Tests

playground/tests/default/index.spec.ts drives the real astro:config:setup hook:

  • astro build rejects with the message
  • empty and non-string id values reject with the message
  • development returns a script that throws and contains no tracker

Checks

  • pnpm build — passed
  • pnpm lint — passed
  • pnpm test in playground — 19/19 passed (17 in default, plus auto-pageview and enabled-in-development)

Summary by CodeRabbit

  • Bug Fixes
    • Missing, empty, whitespace-only, and non-string analytics IDs now produce a clear required-ID error during production builds. In development, the generated script throws the error when run in the browser and omits the invalid tracking ID, preventing it from being included in analytics requests.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The integration validates that id is a non-blank string. Production setup throws an error for invalid values. Development logs the error and returns an inline script that throws when executed. Tests cover missing, empty, whitespace-only, and non-string values.

Changes: Missing ID handling

Layer / File(s) Summary
Missing ID validation and tests
packages/astro-umami/src/index.ts, playground/tests/default/index.spec.ts
The helper validates id and receives Astro’s logger from the setup hook. Production throws for invalid values. Development logs the error and returns a throwing script. Tests cover invalid values in both modes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • yeskunall/astro-umami#217: Implements similar missing-ID handling for JavaScript Astro configs, including a build-time error and a development script that throws.
Merge Risk: Minimal · up to d7524

This change adds a clear error for a missing or invalid Umami id option. Valid configurations behave as before, and I found no remaining merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: error on a missing or invalid id" matches the main change. The PR adds runtime validation of the id option in the astro-umami integration. A missing, empty, whitespace-only, or non…
Full details: Title check

Explanation

The title "fix: error on a missing or invalid id" matches the main change. The PR adds runtime validation of the id option in the astro-umami integration. A missing, empty, whitespace-only, or non-string id now produces an error in build mode, and in development mode it logs the error and injects a script that throws in the browser. The title is specific and concise, and it follows a conventional commit prefix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the ID at dawn
A blank one gets a clear error drawn
In dev, the script waits to run
Then throws its message, neat and done
The tests hop through each case in turn
And show which paths will fail or learn

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2dfb1d4c-b495-453f-8f17-d63938a04554
Commits

Reviewing files that changed from the base of the PR and between 8321091 and d75244e.

Files selected for processing: 2

  • packages/astro-umami/src/index.ts
  • playground/tests/default/index.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 4

  • GitHub Check: CodeRabbit
  • GitHub Check: Greptile Review
  • GitHub Check: Node.js 24 / auto-pageview
  • GitHub Check: pullfrog
Additional comments: 6

packages/astro-umami/src/index.ts: 4

1-1: LGTM!

102-102: LGTM!

Also applies to: 106-106

128-129: LGTM!

Also applies to: 135-135, 139-139

214-216: LGTM!

playground/tests/default/index.spec.ts: 2

25-25: LGTM!

179-183: LGTM!

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

The integration now reports missing or invalid website IDs before loading the tracker.

  • Astro stops tracker setup when the website ID is missing or invalid.

Reviews (5) · Last reviewed commit: "fix: reject non-string `id` and use the ..." · Reviewed by Greptile

@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

pullfrog[bot]

This comment was marked as outdated.

Validate the required `id` at config setup. `astro build` throws a clear
message; `astro dev` logs the error in the terminal and injects a script
that throws in the browser console.

Cover both paths with a dedicated playground spec.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1d37d-ff80-71b2-b5de-db8491ba7eb4
@yeskunall
yeskunall force-pushed the fix-missing-id-error branch from d81d81a to 76ffd02 Compare November 15, 2026 05:19
pullfrog[bot]

This comment was marked as outdated.

@yeskunall yeskunall added type/bug Existing behavior is broken or does not work as intended. area/core Affects the primary product, library, or application code. area/testing Affects tests, fixtures, test infrastructure, or quality tooling. labels Nov 15, 2026
yeskunall

This comment was marked as resolved.

@pull-request-size pull-request-size Bot added size/S and removed size/M labels Nov 15, 2026
@yeskunall

This comment was marked as resolved.

pullfrog[bot]

This comment was marked as outdated.

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Nov 19, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound — the guard now rejects non-string and blank id values and reports through Astro's integration logger in development, so the failure carries the integration name without hand-rolled prefixes.

Reviewed changes — the delta since the prior pullfrog review (8321091..d75244e) tightens the id guard and moves the development report onto Astro's logger.

  • Changed the guard to reject blank and non-string id — typeof id !== "string" || id.trim() === "" replaces !id, so "", " ", and 123 now fail the same way as a missing id.
  • Routed the development error through Astro's logger — getInjectableWebAnalyticsContent now takes the hook's logger and calls logger.error, dropping the manual [astro-umami] prefix from the production throw while keeping it in the browser script.
  • Added coverage for empty and non-string id — a new test loops over "", " ", and 123, and the fake hook context supplies logger.error.

Verified on d75244e: pnpm build and pnpm lint pass, and playwright test tests/default/index.spec.ts --grep 'missing \id`|empty or non-string'passes 3/3.AstroIntegrationLoggeris exported fromastroandloggeris on theastro:config:setup` context in Astro 3.0.0, the oldest supported peer.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 | 𝕏

@yeskunall yeskunall changed the title fix: error on a missing id fix: error on a missing or invalid id Nov 19, 2026
@yeskunall
yeskunall merged commit b65ae4e into main Nov 19, 2026
17 checks passed
@yeskunall
yeskunall deleted the fix-missing-id-error branch November 19, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Affects the primary product, library, or application code. area/testing Affects tests, fixtures, test infrastructure, or quality tooling. size/M type/bug Existing behavior is broken or does not work as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant