WooCommerce Code Reference

WC_Tracks_Client
in package

WC_Tracks_Client class.

Table of Contents

BROWSER_TYPE  = 'php-agent'
Browser type.
PIXEL  = 'https://pixel.wp.com/t.gif'
Pixel URL.
USER_AGENT_SLUG  = 'tracks-client'
User agent.
$pixel_batch_queue  : array<string|int, mixed>
Batch pixel queue for batched requests.
$shutdown_hook_registered  : bool
Whether the shutdown hook has been registered.
add_request_timestamp_and_nocache()  : string
Add request timestamp and no cache parameter to pixel.
build_timestamp()  : string
Create a timestamp representing milliseconds since 1970-01-01
get_anon_id()  : string
Grabs the user's anon id from cookies, or generates and sets a new one
get_identity()  : array<string|int, mixed>
Get a user's identity to send to Tracks. If Jetpack exists, default to its implementation.
init()  : void
Initialize tracks client class
maybe_set_identity_cookie()  : void
Check if identity cookie is set, if not set it.
record_event()  : bool|WP_Error
Record a Tracks event
record_event_batched()  : bool|WP_Error
Record a Tracks event using batched requests for improved performance.
record_pixel()  : bool
Synchronously request the pixel.
record_pixel_batched()  : bool
Record a pixel using batched requests for improved performance.
send_batched_pixels()  : void
Send all queued pixels using batched non-blocking requests.
can_use_batch_requests()  : bool
Check if batch requests are supported.
queue_pixel_for_batch()  : void
Queue a pixel URL for batch sending.
send_with_requests_multiple()  : void
Send pixels using Requests::request_multiple() for parallel non-blocking execution.

Constants

Properties

Methods

add_request_timestamp_and_nocache()

Add request timestamp and no cache parameter to pixel.

public static add_request_timestamp_and_nocache(string $pixel) : string

Use this the latest possible before the HTTP request.

Parameters
$pixel : string

Pixel URL.

Return values
stringPixel URL with request timestamp and URL terminator.

build_timestamp()

Create a timestamp representing milliseconds since 1970-01-01

public static build_timestamp() : string
Return values
stringA string representing a timestamp.

get_anon_id()

Grabs the user's anon id from cookies, or generates and sets a new one

public static get_anon_id() : string
Return values
stringAn anon id for the user

get_identity()

Get a user's identity to send to Tracks. If Jetpack exists, default to its implementation.

public static get_identity(int $user_id) : array<string|int, mixed>
Parameters
$user_id : int

User id.

Return values
array<string|int, mixed>Identity properties.

record_event()

Record a Tracks event

public static record_event(array<string|int, mixed> $event) : bool|WP_Error
Parameters
$event : array<string|int, mixed>

Array of event properties.

Return values
bool|WP_ErrorTrue on success, WP_Error on failure.

record_event_batched()

Record a Tracks event using batched requests for improved performance.

public static record_event_batched(array<string|int, mixed> $event) : bool|WP_Error

Events are queued and sent together on the shutdown hook.

Parameters
$event : array<string|int, mixed>

Array of event properties.

Tags
since
10.5.0
Return values
bool|WP_ErrorTrue on success, WP_Error on failure.

record_pixel()

Synchronously request the pixel.

public static record_pixel(string $pixel) : bool
Parameters
$pixel : string

pixel url and query string.

Return values
boolAlways returns true.

record_pixel_batched()

Record a pixel using batched requests for improved performance.

public static record_pixel_batched(string $pixel) : bool

Pixels are queued and sent together on the shutdown hook.

Parameters
$pixel : string

pixel url and query string.

Tags
since
10.5.0
Return values
boolAlways returns true.

send_batched_pixels()

Send all queued pixels using batched non-blocking requests.

public static send_batched_pixels() : void

This runs on the shutdown hook to batch all requests together.

Uses Requests library's request_multiple() for true parallel batching via curl_multi.

Tags
since
10.5.0
Return values
void

can_use_batch_requests()

Check if batch requests are supported.

private static can_use_batch_requests() : bool
Tags
since
10.5.0
Return values
boolWhether batch requests are supported.

queue_pixel_for_batch()

Queue a pixel URL for batch sending.

private static queue_pixel_for_batch(string $pixel) : void
Parameters
$pixel : string

The pixel URL to queue.

Tags
since
10.5.0
Return values
void

send_with_requests_multiple()

Send pixels using Requests::request_multiple() for parallel non-blocking execution.

private static send_with_requests_multiple(array<string|int, mixed> $pixels) : void

Uses blocking => false for true non-blocking behavior via curl_multi.

Parameters
$pixels : array<string|int, mixed>

Array of pixel URLs to send.

Tags
since
10.5.0
Return values
void