Skip to content

Sanitize analytics payloads to prevent circular JSON errors#7

Draft
gansxx wants to merge 1 commit into
mainfrom
codex/fix-typeerror-circular-structure-in-json
Draft

Sanitize analytics payloads to prevent circular JSON errors#7
gansxx wants to merge 1 commit into
mainfrom
codex/fix-typeerror-circular-structure-in-json

Conversation

@gansxx

@gansxx gansxx commented May 17, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Third-party analytics (GTM/PostHog/Zaraz) received raw event payloads that could contain DOM nodes, browser Events or React internals, causing TypeError: Converting circular structure to JSON when JSON.stringify is attempted.
  • The change prevents sending non-serializable or excessively large data to analytics providers and avoids runtime exceptions in the browser.
  • Also fixed a nested-anchor markup issue in the app store card that could create invalid DOM structure.

Description

  • Add lib/analytics-sanitize.ts which converts Event and HTMLElement values into JSON-safe metadata, strips React internal keys, guards against circular references, enforces max depth, array length and string length limits, and normalizes keys.
  • Sanitize payloads pushed to the GTM dataLayer in lib/gtm/utils.ts by calling sanitizeAnalyticsProperties and pushing only the sanitized object.
  • Sanitize parameters passed to GA (gtag) and PostHog: update lib/analytics.ts to use sanitized safeParams, and lib/posthog.ts to forward sanitized properties to posthog.capture.
  • Fix components/AppStoreCard.tsx to avoid nested <a> elements by moving the icon/name outside the anchor and linking the download Button directly to the external href.

Testing

  • pnpm build completed successfully (Next.js production build and static generation succeeded). ✅
  • pnpm exec tsc --noEmit still reports unrelated pre-existing type errors in other parts of the repo (e.g. OrdersTable, subscription-error-alert, subscription-api) and therefore did not fully pass here. ⚠️
  • pnpm lint (next lint) is interactive in this repo and could not complete automatically in CI; it did not run to completion. ⚠️
  • Manual verification: build output shows app compiles and static pages generated; core change prevents circular structures from being forwarded to analytics providers and fixes the nested anchor issue. ✅

Codex Task

@vercel

vercel Bot commented May 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vpn_web Ready Ready Preview, Comment, Open in v0 May 17, 2026 4:52am

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant