From da1dd76a68e43652836fdb5a43f99d863e112a90 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Fri, 8 May 2020 11:20:28 -0400 Subject: [PATCH] Only log `products_search` event if search query is non-empty --- .../tracks/events/class-wc-products-tracking.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/tracks/events/class-wc-products-tracking.php b/includes/tracks/events/class-wc-products-tracking.php index b583dea13de..3a993b94063 100644 --- a/includes/tracks/events/class-wc-products-tracking.php +++ b/includes/tracks/events/class-wc-products-tracking.php @@ -35,14 +35,22 @@ class WC_Products_Tracking { // Otherwise, we would double-record the view and search events. // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification - if ( isset( $_GET['post_type'] ) + if ( + isset( $_GET['post_type'] ) && 'product' === wp_unslash( $_GET['post_type'] ) - && ! isset( $_GET['_wp_http_referer'] ) ) { + && ! isset( $_GET['_wp_http_referer'] ) + ) { // phpcs:enable WC_Tracks::record_event( 'products_view' ); - if ( isset( $_GET['s'] ) ) { + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification + if ( + isset( $_GET['s'] ) + && 0 < strlen( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) + ) { + // phpcs:enable + WC_Tracks::record_event( 'products_search' ); } }