Add_To_Cart

Summary

No summary available.

Source

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

class Add_To_Cart {


	/**
	 * @param array $args
	 * @param array $data
	 *
	 * @return array
	 */
	public function set_tracking_attributes_on_success_message( $args, $data ) {
		if ( ! array_key_exists( 'data', $data ) ) {
			return $args;
		}
		$data = $data[ 'data' ];
		if ( array_key_exists( 'key', $data ) && $data[ 'key' ] == 'add_to_cart' ) {
			$data = wp_parse_args( $data, [
				'cart_id'    => '',
				'post_id'    => 0,
				'product_id' => 0,
				'variant_id' => 0,
			] );

			$args[ Message::ATTRIBUTES ] = array_merge( $args[ Message::ATTRIBUTES ], [
				'data-tracking-trigger' => 'ready',
				'data-tracking-event'   => 'add_to_cart',
				'data-tracking-data'    => json_encode( [
					'cart_id'    => $data[ 'cart_id' ],
					'post_id'    => $data[ 'post_id' ],
					'product_id' => $data[ 'product_id' ],
					'variant_id' => $data[ 'variant_id' ],
				] ),
			] );
		}

		return $args;
	}
}

Methods


User Contributed Notes

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