Skip to content

Conversation

@pedroccastro
Copy link
Contributor

What does this PR do?

Adds input validation to analytics app integration schemas. Tracking IDs and URLs now conform to their expected formats, preventing malformed data from being stored and rendered.

Changes

Layer File(s) Change
Schema gtm/zod.ts Validate GTM-XXXXXX format
Schema ga4/zod.ts Validate G-XXXXXXXXXX format
Schema metapixel/zod.ts Validate numeric pixel IDs
Schema posthog/zod.ts Validate alphanumeric keys + http/https URLs
Schema fathom/zod.ts Validate alphanumeric site IDs
Schema plausible/zod.ts Validate domain format + http/https URLs
Schema matomo/zod.ts Validate http/https URLs + numeric site IDs
Schema umami/zod.ts Validate UUID/numeric IDs + http/https URLs
Schema twipla/zod.ts Validate alphanumeric/UUID site IDs
Schema insihts/zod.ts Validate alphanumeric site IDs + http/https URLs
Schema databuddy/zod.ts Validate alphanumeric client IDs + http/https URLs
Tests analytics-apps.test.ts Unit tests for all schemas

Technical Details

  • URL fields use new URL() for validation + protocol check (http/https only)
  • Tracking IDs use format-specific regex based on each provider's documentation
  • Empty strings remain valid for optional fields (backwards compatible)

How should this be tested?

  1. Configure any analytics app on an event type with valid ID → should save
  2. Try saving with invalid format (e.g., letters in Meta Pixel ID) → should show validation error
  3. Leave optional fields empty → should save successfully
  4. Run unit tests: yarn vitest run packages/app-store/analytics-apps.test.ts

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code.
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Add strict input validation for tracking IDs and URLs in analytics
app integrations to ensure data conforms to expected formats
Remove .optional() and .default("") from schemas with transform/refine
chains to preserve correct TypeScript type inference
@github-actions
Copy link
Contributor

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants