WC_Tracks
in package
WC_Tracks class.
Table of Contents
- PREFIX = 'wcadmin_'
- Tracks event name prefix.
- get_blog_details() : array<string|int, mixed>
- Gather blog related properties.
- get_products_count() : int
- Get total product counts.
- get_properties() : array<string|int, mixed>
- Get all properties for the event including filtered and identity properties.
- get_role_details() : array<string|int, mixed>
- Get role-related details.
- get_server_details() : array<string|int, mixed>
- Gather details from the request to the server.
- record_event() : bool|WP_Error
- Record an event in Tracks - this is the preferred way to record events from PHP.
- track_woocommerce_allow_tracking_toggled() : mixed
- Track when the user attempts to toggle woocommerce_allow_tracking option.
Constants
PREFIX
Tracks event name prefix.
public
mixed
PREFIX
= 'wcadmin_'
Methods
get_blog_details()
Gather blog related properties.
public
static get_blog_details(int $user_id) : array<string|int, mixed>
Parameters
- $user_id : int
-
User id.
Return values
array<string|int, mixed> — Blog details.get_products_count()
Get total product counts.
public
static get_products_count() : int
Return values
int — Number of products.get_properties()
Get all properties for the event including filtered and identity properties.
public
static get_properties(string $event_name, array<string|int, mixed> $event_properties) : array<string|int, mixed>
Parameters
- $event_name : string
-
Event name.
- $event_properties : array<string|int, mixed>
-
Event specific properties.
Return values
array<string|int, mixed> —get_role_details()
Get role-related details.
public
static get_role_details(WP_User $user) : array<string|int, mixed>
Parameters
- $user : WP_User
-
The user object.
Return values
array<string|int, mixed> — The role details.get_server_details()
Gather details from the request to the server.
public
static get_server_details() : array<string|int, mixed>
Return values
array<string|int, mixed> — Server details.record_event()
Record an event in Tracks - this is the preferred way to record events from PHP.
public
static record_event(string $event_name[, array<string|int, mixed> $event_properties = array() ]) : bool|WP_Error
Note: the event request won't be made if $properties has a member called error.
Array values in event properties are automatically converted to prevent invalid property names:
- Indexed arrays (e.g., ['a', 'b', 'c']) become comma-separated strings: 'a,b,c'
- Associative arrays (e.g., ['key' => 'val']) become JSON strings: '{"key":"val"}'
- Empty arrays become empty strings
Examples: // Indexed array - becomes comma-separated string WC_Tracks::record_event( 'checkout_viewed', array( 'blocks' => array( 'woocommerce/cart-items', 'woocommerce/checkout-totals' ) ) ); // Results in: blocks=woocommerce%2Fcart-items%2Cwoocommerce%2Fcheckout-totals
// Associative array - becomes JSON string
WC_Tracks::record_event( 'settings_changed', array(
'options' => array( 'enabled' => true, 'count' => 5 )
) );
// Results in: options=%7B%22enabled%22%3Atrue%2C%22count%22%3A5%7D
For complex structures, consider explicitly JSON-encoding before passing to record_event().
Parameters
- $event_name : string
-
The name of the event.
- $event_properties : array<string|int, mixed> = array()
-
Custom properties to send with the event.
Return values
bool|WP_Error — True for success or WP_Error if the event pixel could not be fired.track_woocommerce_allow_tracking_toggled()
Track when the user attempts to toggle woocommerce_allow_tracking option.
public
static track_woocommerce_allow_tracking_toggled(string $prev_value, string $new_value[, string $context = 'settings' ]) : mixed
Parameters
- $prev_value : string
-
The previous value for the setting. 'yes' or 'no'.
- $new_value : string
-
The new value for the setting. 'yes' or 'no'.
- $context : string = 'settings'
-
Which avenue the user utilized to toggle.
