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

Summary

No summary available.

Parameters

$options

(array) (Required)

$template

(string) (Required)


Return

(array)


Source

File: src/BigCommerce/Analytics/Events/View_Product.php

	public function add_tracking_attributes_to_permalink( $options, $template ) {
		if ( empty( $options[ Product_Title::USE_PERMALINK ] ) || empty( $options[ Product_Title::PRODUCT ] ) ) {
			return $options;
		}

		if ( empty( $options[ View_Product_Button::ATTRIBUTES ] ) ) {
			$options[ View_Product_Button::ATTRIBUTES ] = [];
		}

		$product = $options[ Product_Title::PRODUCT ];

		$options[ Product_Title::LINK_ATTRIBUTES ] = array_merge( $options[ Product_Title::LINK_ATTRIBUTES ], [
			'data-tracking-trigger' => 'click',
			'data-tracking-event'   => 'view_product',
			'data-tracking-data'    => wp_json_encode( [
				'post_id'    => $product->post_id(),
				'product_id' => $product->bc_id(),
				'name'       => get_the_title( $product->post_id() ),
			] ),
		] );

		return $options;
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.