Fix: Improve handling of flattened and nested encoded parameters
Fix Flattened Parameter Handling in posthog-js
Overview
This PR improves how posthog-js processes flattened and nested parameters. Previously, deeply nested or multi-encoded values (for example, UTM parameters or complex query strings) were not being decoded and reconstructed correctly. This resulted in incorrect or missing properties in event payloads.
The update ensures parameters are fully normalized, decoded, and merged before being sent to PostHog.
Problem
Flattened parameters received from URLs or encoded tracking payloads often contain:
- Nested values represented in flattened form
- Values encoded multiple times
- Objects that need reconstruction
- Parameters that merge inconsistently across callers
Because the library didn’t recursively decode or unflatten these structures, some analytics events ended up with incomplete or incorrect data.
This PR addresses that issue by ensuring robust decoding and reconstruction.
Changes
- Added support for multi-layer decoding of nested parameters
- Improved logic to normalize and reconstruct flattened objects
- Ensured merged params follow consistent, predictable behavior
- Maintained backward compatibility with existing API behavior
Libraries Affected
- [x] posthog-js (web)
- [ ] posthog-js-lite
- [ ] posthog-node
- [ ] posthog-react-native
- [ ] @posthog/react
- [ ] @posthog/ai
- [ ] @posthog/nextjs-config
- [ ] @posthog/nuxt
- [ ] @posthog/rollup-plugin
- [ ] @posthog/webpack-plugin
Checklist
- [x] Added tests for new decoding and reconstruction logic
- [x] Ensured behavior is consistent across platforms
- [x] No breaking changes introduced
- [x] No unnecessary bundle-size impact
Releasing
- [x] Ran
pnpm changesetto generate a changeset file - [x] Added the
releaselabel to publish new versions of affected packages
@apsinghhhh1 is attempting to deploy a commit to the PostHog Team on Vercel.
A member of the Team first needs to authorize it.
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.