Commit e8409074363 for woocommerce
commit e8409074363258daff3d66b02feaa75fa6894f72
Author: Darren Ethier <darren@roughsmootheng.in>
Date: Wed Sep 23 13:58:55 2026 -0400
Skip client-side Tracks events with a missing event name (#69009)
* Skip client Tracks events with a missing event name
window.wcTracks.recordEvent prefixed whatever it was given, so a caller
passing undefined produced a `wcadmin_undefined` event that the Tracks
pipeline rejects. Bail out early (logging outside production) when the
name is not a non-empty string.
diff --git a/plugins/woocommerce/changelog/wooplug-7771-guard-undefined-tracks-event-name b/plugins/woocommerce/changelog/wooplug-7771-guard-undefined-tracks-event-name
new file mode 100644
index 00000000000..e4b20c120e4
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-7771-guard-undefined-tracks-event-name
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Skip client-side Tracks events recorded without a valid event name instead of sending them as `wcadmin_undefined`.
diff --git a/plugins/woocommerce/includes/tracks/class-wc-site-tracking.php b/plugins/woocommerce/includes/tracks/class-wc-site-tracking.php
index 69462ae3f04..c33f2c600b2 100644
--- a/plugins/woocommerce/includes/tracks/class-wc-site-tracking.php
+++ b/plugins/woocommerce/includes/tracks/class-wc-site-tracking.php
@@ -119,6 +119,17 @@ class WC_Site_Tracking {
return;
}
+ // Without this, a missing name is prefixed into a bogus `wcadmin_undefined` event that Tracks rejects.
+ if ( typeof name !== 'string' || ! name ) {
+ if ( <?php echo 'production' !== $environment_type ? 'true' : 'false'; ?> ) {
+ /* eslint-disable no-console */
+ // Pass the value as its own argument: interpolating a Symbol (or null-prototype object) would throw.
+ console.error( 'A valid event name must be specified. Received invalid event name:', name );
+ /* eslint-enable no-console */
+ }
+ return;
+ }
+
const eventName = '<?php echo esc_attr( WC_Tracks::PREFIX ); ?>' + name;
let eventProperties = properties || {};
eventProperties = { ...eventProperties, ...<?php echo json_encode( $filtered_properties, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode ?> };