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
BROWSER_TYPE
Browser type.
public
mixed
BROWSER_TYPE
= 'php-agent'
PIXEL
Pixel URL.
public
mixed
PIXEL
= 'https://pixel.wp.com/t.gif'
USER_AGENT_SLUG
User agent.
public
mixed
USER_AGENT_SLUG
= 'tracks-client'
Properties
$pixel_batch_queue
Batch pixel queue for batched requests.
private
static array<string|int, mixed>
$pixel_batch_queue
= array()
$shutdown_hook_registered
Whether the shutdown hook has been registered.
private
static bool
$shutdown_hook_registered
= alse
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
string — Pixel 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
string — A 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
string — An anon id for the userget_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.init()
Initialize tracks client class
public
static init() : void
Return values
void —maybe_set_identity_cookie()
Check if identity cookie is set, if not set it.
public
static maybe_set_identity_cookie() : void
Return values
void —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_Error — True 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
Return values
bool|WP_Error — True 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
bool — Always 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
Return values
bool — Always 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
Return values
void —can_use_batch_requests()
Check if batch requests are supported.
private
static can_use_batch_requests() : bool
Tags
Return values
bool — Whether 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
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.
