WC_Tracks_Client::record_event_batchedpublic staticWC 10.5.0

Record a Tracks event using batched requests for improved performance. Events are queued and sent together on the shutdown hook.

Method of the class: WC_Tracks_Client{}

No Hooks.

Returns

true|false|WP_Error. True on success, WP_Error on failure.

Usage

$result = WC_Tracks_Client::record_event_batched( $event );
$event(array) (required)
Array of event properties.

Changelog

Since 10.5.0 Introduced.

WC_Tracks_Client::record_event_batched() code WC 10.5.0

public static function record_event_batched( $event ) {
	if ( ! $event instanceof WC_Tracks_Event ) {
		$event = new WC_Tracks_Event( $event );
	}

	if ( isset( $event->error ) && is_wp_error( $event->error ) ) {
		return $event->error;
	}

	$pixel = $event->build_pixel_url();

	if ( ! $pixel ) {
		return new WP_Error( 'invalid_pixel', 'cannot generate tracks pixel for given input', 400 );
	}

	return self::record_pixel_batched( $pixel );
}