Source
<?php
/**
* Send Tracks events on behalf of a user using pixel images in page footer.
*
* @package WooCommerce\Tracks
*/
defined( 'ABSPATH' ) || exit;
/**
* WC_Tracks_Footer_Pixel class.
*/
class WC_Tracks_Footer_Pixel {
/**
* Singleton instance.
*
* @var WC_Tracks_Footer_Pixel
*/
protected static $instance = null;
/**
* Events to send to Tracks.
*
* @var array
*/
protected $events = array();
/**
* Instantiate the singleton.
*
* @return WC_Tracks_Footer_Pixel
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new WC_Tracks_Footer_Pixel();
}
return self::$instance;
}
/**
* Constructor - attach hooks to the singleton instance.
*/
public function __construct() {
add_action( 'admin_footer', array( $this, 'render_tracking_pixels' ) );
add_action( 'shutdown', array( $this, 'send_tracks_requests' ) );
}
/**
* Record a Tracks event
*
* @param array $event Array of event properties.
* @return bool|WP_Error True on success, WP_Error on failure.
*/
public static function record_event( $event ) {
if ( ! $event instanceof WC_Tracks_Event ) {
$event = new WC_Tracks_Event( $event );
}
if ( is_wp_error( $event ) ) {
return $event;
}