posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Fix: Improve handling of flattened and nested encoded parameters

Open apsinghhhh1 opened this issue 1 month ago • 2 comments

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 changeset to generate a changeset file
  • [x] Added the release label to publish new versions of affected packages

apsinghhhh1 avatar Dec 05 '25 14:12 apsinghhhh1

@apsinghhhh1 is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 05 '25 14:12 vercel[bot]

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.

posthog-bot avatar Dec 15 '25 09:12 posthog-bot