WordPress at Your Fingertips
function is not described

WC_Products_Tracking::track_products_view() public WC 1.0

Send a Tracks event when the Products page is viewed.

{} It's a method of the class: WC_Products_Tracking{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Products_Tracking = new WC_Products_Tracking();
$WC_Products_Tracking->track_products_view();

Code of WC_Products_Tracking::track_products_view() WC 5.8.0

public function track_products_view() {
	// We only record Tracks event when no `_wp_http_referer` query arg is set, since
	// when searching, the request gets sent from the browser twice,
	// once with the `_wp_http_referer` and once without it.
	//
	// Otherwise, we would double-record the view and search events.

	// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification
	if (
		isset( $_GET['post_type'] )
		&& 'product' === wp_unslash( $_GET['post_type'] )
		&& ! isset( $_GET['_wp_http_referer'] )
	) {
		// phpcs:enable

		WC_Tracks::record_event( 'products_view' );

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