diff --git a/projects/packages/woocommerce-analytics/changelog/fix-wa-event-prop-invalid b/projects/packages/woocommerce-analytics/changelog/fix-wa-event-prop-invalid new file mode 100644 index 0000000000000..cc7daa49902f7 --- /dev/null +++ b/projects/packages/woocommerce-analytics/changelog/fix-wa-event-prop-invalid @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix improved data handling due to invalid prop name diff --git a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php index a5836c9fefa16..7b9fb91688db5 100644 --- a/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php +++ b/projects/packages/woocommerce-analytics/src/class-wc-analytics-tracking.php @@ -228,7 +228,31 @@ public static function get_properties( $event_name, $event_properties ) { ) : array(); - return array_merge( $properties, $required_properties ); + $all_properties = array_merge( $properties, $required_properties ); + + // Convert array values to a comma-separated string and URL-encode them to ensure compatibility with JavaScript's encodeURIComponent() for pixel URL transmission. + foreach ( $all_properties as $key => $value ) { + if ( ! is_array( $value ) ) { + continue; + } + + if ( empty( $value ) ) { + $all_properties[ $key ] = ''; + continue; + } + + $is_indexed_array = array_keys( $value ) === range( 0, count( $value ) - 1 ); + if ( $is_indexed_array ) { + $value_string = implode( ',', $value ); + $all_properties[ $key ] = rawurlencode( $value_string ); + continue; + } + + // Serialize non-indexed arrays to JSON strings. + $all_properties[ $key ] = wp_json_encode( $value ); + } + + return $all_properties; } /**