WC_Tracks_Client::record_pixel_batchedpublic staticWC 10.5.0

Record a pixel using batched requests for improved performance. Pixels are queued and sent together on the shutdown hook.

Method of the class: WC_Tracks_Client{}

Hooks from the method

Returns

true|false. Always returns true.

Usage

$result = WC_Tracks_Client::record_pixel_batched( $pixel );
$pixel(string) (required)
pixel url and query string.

Changelog

Since 10.5.0 Introduced.

WC_Tracks_Client::record_pixel_batched() code WC 10.5.0

public static function record_pixel_batched( $pixel ) {
	// Check if batching is enabled and supported.
	$use_batching = self::can_use_batch_requests();

	/**
	 * Filters whether to use batch requests for tracking pixels.
	 *
	 * @since 10.5.0
	 *
	 * @param bool $use_batching Whether to use batch requests. Default true if supported.
	 */
	$use_batching = apply_filters( 'wc_tracks_use_batch_requests', $use_batching );

	if ( $use_batching ) {
		// Queue the pixel and send on shutdown.
		self::queue_pixel_for_batch( $pixel );
		return true;
	}

	// Fallback to immediate sending if batching is not supported or disabled.
	return self::record_pixel( $pixel );
}