@@ -135,6 +135,26 @@ export class AnalyticsEvent {
135135 }
136136}
137137
138+ /**
139+ * @hidden
140+ */
141+ function isValidUserProperty ( property : unknown ) : property is { value : unknown } {
142+ if ( property == null || typeof property !== "object" || ! ( "value" in property ) ) {
143+ return false ;
144+ }
145+
146+ const { value } = property ;
147+ if ( value == null ) {
148+ return false ;
149+ }
150+
151+ if ( typeof value === "object" && Object . keys ( value ) . length === 0 ) {
152+ return false ;
153+ }
154+
155+ return true ;
156+ }
157+
138158/**
139159 * Interface representing the user who triggered the events.
140160 */
@@ -181,18 +201,7 @@ export class UserDimensions {
181201 this . userProperties = { } ; // With no entries in the wire format, present an empty (as opposed to absent) map.
182202 copyField ( wireFormat , this , "userProperties" , ( r : unknown ) => {
183203 const entries = Object . entries ( r as Record < string , unknown > )
184- . filter ( ( [ , v ] ) => {
185- // Property must be an object and have a 'value' field.
186- if ( v == null || typeof v !== "object" || ! ( "value" in v ) ) {
187- return false ;
188- }
189-
190- // The 'value' field must not be null, undefined, or an empty object.
191- const value = ( v as { value : unknown } ) . value ;
192- const isEmptyObject =
193- typeof value === "object" && value !== null && Object . keys ( value ) . length === 0 ;
194- return value != null && ! isEmptyObject ;
195- } )
204+ . filter ( ( [ , v ] ) => isValidUserProperty ( v ) )
196205 . map ( ( [ k , v ] ) => [ k , new UserPropertyValue ( v ) ] ) ;
197206 return Object . fromEntries ( entries ) ;
198207 } ) ;
0 commit comments