Only log `products_search` event if search query is non-empty

This commit is contained in:
Matt Sherman 2020-05-08 11:20:28 -04:00
parent b1a32f4144
commit da1dd76a68
1 changed files with 11 additions and 3 deletions

View File

@ -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' );
}
}