WooCommerce Code Reference

WC_Tracks_Event
in package

WC_Tracks_Event class.

Table of Contents

EVENT_NAME_REGEX  = '/^(([a-z0-9]+)_){1}([a-z0-9_]+)$/'
Event name regex.
PROP_NAME_REGEX  = '/^[a-z_][a-z0-9_]*$/'
Property name regex.
$error  : WP_Error|null
Error message as WP_Error.
__construct()  : mixed
WC_Tracks_Event constructor.
build_pixel_url()  : string
Build a pixel URL that will send a Tracks event when fired.
event_name_is_valid()  : false|int
Check if event name is valid.
prop_name_is_valid()  : false|int
Check if a property name is valid.
record()  : bool
Record Tracks event
scrutinize_event_names()  : mixed
Check event names
validate_and_sanitize()  : object|WP_Error
Annotate the event with all relevant info.
sanitize_property_values()  : object|array<string|int, mixed>
Sanitize property values to ensure they can be safely serialized.

Constants

Properties

Methods

__construct()

WC_Tracks_Event constructor.

public __construct(array<string|int, mixed> $event) : mixed
Parameters
$event : array<string|int, mixed>

Event properties.

Return values
mixed

build_pixel_url()

Build a pixel URL that will send a Tracks event when fired.

public build_pixel_url() : string

On error, returns an empty string ('').

Return values
stringA pixel URL or empty string ('') if there were invalid args.

event_name_is_valid()

Check if event name is valid.

public static event_name_is_valid(string $name) : false|int
Parameters
$name : string

Event name.

Return values
false|int

prop_name_is_valid()

Check if a property name is valid.

public static prop_name_is_valid(string $name) : false|int
Parameters
$name : string

Event property.

Return values
false|int

scrutinize_event_names()

Check event names

public static scrutinize_event_names(object $event) : mixed
Parameters
$event : object

An event object.

Return values
mixed

validate_and_sanitize()

Annotate the event with all relevant info.

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

Event arguments.

Return values
object|WP_ErrorEvent object on success, WP_Error on failure.

sanitize_property_values()

Sanitize property values to ensure they can be safely serialized.

private static sanitize_property_values(object|array<string|int, mixed> $properties) : object|array<string|int, mixed>

Converts array values to appropriate formats to prevent http_build_query() from creating bracket notation (e.g., prop[0], prop[1]) which violates the property name regex.

Parameters
$properties : object|array<string|int, mixed>

Event properties as object or array.

Return values
object|array<string|int, mixed>Sanitized properties in the same type as input.