ClassesBigCommerceAnalyticsEventsView Product

View_Product

Class View_Product

Adds analytics events to product permalink and buttons for tracking.

This class is responsible for attaching analytics tracking attributes to the product’s view buttons and permalink. It tracks events such as product views by adding the necessary data attributes to the HTML elements. The tracking includes product information like product ID, name, and SKU if enabled in the settings.

  • Full name: \BigCommerce\Analytics\Events\View_Product

Methods

add_tracking_attributes_to_button

Adds tracking attributes to the product view button.

public add_tracking_attributes_to_button(array $options = [], string $template = ''): array

This function embeds tracking data into the attributes of the product view button. The tracking attributes include product details like product ID, post ID, and product name. It triggers the ‘view_product’ event when the button is clicked.

Parameters:

ParameterTypeDescription
$optionsarrayOptions for the button.
$templatestringThe template name for the button.

Return Value:

Modified options with added tracking attributes.


Adds tracking attributes to the product permalink.

public add_tracking_attributes_to_permalink(array $options, string $template): array

This function attaches tracking data to the product permalink’s attributes. The tracking includes product details such as product ID, post ID, and product name. The ‘view_product’ event is triggered when the permalink is clicked.

Parameters:

ParameterTypeDescription
$optionsarrayOptions for the permalink.
$templatestringThe template name for the permalink.

Return Value:

Modified options with added tracking attributes.


change_track_data

Updates tracking data to include SKU information if enabled in Analytics settings.

public change_track_data(array $track_data): array

If SKU tracking is enabled in the Analytics options, this function appends the SKU to the tracking data for the product. If a variant ID is provided, the variant’s SKU is also included. If the product cannot be loaded, the original tracking data is returned.

Parameters:

ParameterTypeDescription
$track_dataarrayThe existing tracking data.

Return Value:

The updated tracking data, potentially including SKU information.



Automatically generated on 2025-01-21