Skip to content

Conversation

cabljac
Copy link

@cabljac cabljac commented Sep 30, 2025

This draft PR is a proposed solution to resolve #1712

Problem

When an analytics event payload contains malformed user properties, the SDK throws a TypeError before the user's callback can execute:

// Problematic payloads:
userProperties: {
  "some_property": null,                    // Entirely null
  "another_property": { "value": null },    // Value field is null
  "empty_property": {}                      // Missing value field
}

Error:

TypeError: Cannot convert undefined or null to object
at Function.keys ()
at unwrapValueAsString (analytics.js:206)

Solution

  1. Made unwrapValueAsString defensive
  • Added null/undefined/empty object checks before calling Object.keys()
  • Returns empty string for invalid inputs instead of throwing
  • Improved type safety by changing parameter from any to unknown
  1. Filter invalid user properties
  • Added filter in UserDimensions constructor to skip properties that are:
    • null or undefined
    • Empty objects {}
    • Objects with value field that is null, undefined, or {}
  • Valid properties (including falsy values like "" and 0) are preserved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intermittent TypeError for app_remove events
1 participant