SILENT KILLERPanel

Current Path: > home > codekrsu > > ameliagraphics.com > wp-content > plugins > pinterest-for-woocommerce > src > >


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: /home/codekrsu//ameliagraphics.com/wp-content/plugins/pinterest-for-woocommerce/src//

NameTypeSizeLast ModifiedActions
API Directory - -
Admin Directory - -
Exception Directory - -
MultichannelMarketing Directory - -
Notes Directory - -
Product Directory - -
Tracking Directory - -
Utilities Directory - -
View Directory - -
AdCredits.php File 8406 bytes August 26 2024 16:35:44.
AdCreditsCoupons.php File 1461 bytes August 26 2024 16:35:44.
AdsCreditCurrency.php File 1946 bytes May 20 2025 15:25:46.
Billing.php File 4901 bytes August 26 2024 16:35:44.
CommerceIntegration.php File 7185 bytes December 04 2024 18:47:06.
Compat.php File 952 bytes November 16 2021 18:14:38.
Crypto.php File 3718 bytes June 23 2025 21:16:30.
FeedFileOperations.php File 4680 bytes August 26 2024 16:35:44.
FeedGenerator.php File 22733 bytes August 26 2024 16:35:44.
FeedRegistration.php File 7230 bytes December 04 2024 18:47:06.
FeedStatusService.php File 20815 bytes March 18 2025 17:31:36.
Feeds.php File 13838 bytes December 04 2024 18:47:06.
Heartbeat.php File 1882 bytes October 23 2024 17:23:10.
LocalFeedConfigs.php File 3327 bytes September 24 2024 11:32:30.
LocaleMapper.php File 3167 bytes March 18 2025 17:31:36.
Logger.php File 3132 bytes August 26 2024 16:35:44.
Merchants.php File 6575 bytes September 24 2024 11:32:30.
PinterestApiException.php File 2767 bytes December 04 2024 18:47:06.
PinterestShippingZone.php File 7161 bytes February 16 2022 03:57:48.
PinterestSyncSettings.php File 3016 bytes August 26 2024 16:35:44.
PluginActivate.php File 785 bytes June 18 2022 00:23:22.
PluginHelper.php File 2537 bytes October 11 2022 17:51:18.
PluginUpdate.php File 11166 bytes May 29 2025 17:27:42.
ProductFeedStatus.php File 4453 bytes August 26 2024 16:35:44.
ProductSync.php File 6351 bytes September 24 2024 11:32:30.
ProductsXmlFeed.php File 17527 bytes February 11 2025 16:39:50.
RefreshToken.php File 3769 bytes August 26 2024 16:35:44.
RichPins.php File 9177 bytes August 26 2024 16:35:44.
SaveToPinterest.php File 3525 bytes April 26 2023 13:47:12.
Shipping.php File 8372 bytes February 16 2022 03:57:48.
TrackerSnapshot.php File 2574 bytes August 26 2024 16:35:44.
Tracking.php File 7488 bytes August 29 2024 22:54:16.
WPConsentAPI.php File 1178 bytes June 16 2025 21:44:24.
error_log File 260 bytes June 23 2025 21:16:32.

Reading File: /home/codekrsu//ameliagraphics.com/wp-content/plugins/pinterest-for-woocommerce/src///Tracking.php

<?php
/**
 * Pinterest tracking main class.
 *
 * @package Pinterest_For_WooCommerce/Classes/
 * @version 1.0.0
 */

namespace Automattic\WooCommerce\Pinterest;

use Automattic\WooCommerce\Pinterest\Tracking\Data;
use Automattic\WooCommerce\Pinterest\Tracking\Data\Category;
use Automattic\WooCommerce\Pinterest\Tracking\Data\Checkout;
use Automattic\WooCommerce\Pinterest\Tracking\Data\None;
use Automattic\WooCommerce\Pinterest\Tracking\Data\Product;
use Automattic\WooCommerce\Pinterest\Tracking\Data\Search;
use Automattic\WooCommerce\Pinterest\Tracking\Tag;
use Automattic\WooCommerce\Pinterest\Tracking\Tracker;
use Throwable;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Tracker responsible for hooking into system events.
 */
class Tracking {

	const EVENT_CHECKOUT      = 'Checkout';

	const EVENT_ADD_TO_CART   = 'AddToCart';

	const EVENT_PAGE_VISIT    = 'PageVisit';

	const EVENT_SEARCH        = 'Search';

	const EVENT_VIEW_CATEGORY = 'ViewCategory';

	/**
	 * @var Tracker[] $trackers A list of available trackers.
	 */
	private $trackers = array();

	/**
	 * Attaches all the required tracking events to corresponding WP/WC hooks.
	 *
	 * @since 1.4.0
	 *
	 * @param array $trackers A list of trackers to track events with.
	 */
	public function __construct( array $trackers = array() ) {
		$this->trackers = $trackers;

		// Tracks page visit events.
		add_action( 'wp_footer', array( $this, 'handle_page_visit' ) );

		// Tracks category visit events.
		add_action( 'wp_footer', array( $this, 'handle_view_category' ) );

		// Tracks search events.
		add_action( 'wp_footer', array( $this, 'handle_search' ) );

		// Tracks add to cart events.
		add_action( 'woocommerce_add_to_cart', array( $this, 'handle_add_to_cart' ), 10, 6 );

		// Tracks checkout events.
		add_action( 'woocommerce_before_thankyou', array( $this, 'handle_checkout' ), 10, 2 );

		array_walk(
			$this->trackers,
			fn ( $tracker ) => call_user_func( array( $tracker, 'init_hooks' ) )
		);
	}

	/**
	 * Used as a callback for the wp_footer hook.
	 *
	 * @since 1.4.0
	 * @since 1.4.8 Added check for product page.
	 *
	 * @return void
	 */
	public function handle_page_visit() {
		if ( is_404() ) {
			// Do not track 404 pages.
			return;
		}

		// Dumy data for when we can't get product data.
		$data = new None( uniqid( 'page' ) );

		// Not a product page.
		if ( ! is_product() ) {
			$this->track_event( static::EVENT_PAGE_VISIT, $data );
			return;
		}

		$product = wc_get_product();
		if ( ! $product instanceof \WC_Product ) {
			$this->track_event( static::EVENT_PAGE_VISIT, $data );
			return;
		}

		$data = new Product(
			uniqid( 'page' ),
			$product->get_id(),
			$product->get_name(),
			wc_get_product_category_list( $product->get_id() ),
			'brand',
			wc_get_price_to_display( $product ),
			get_woocommerce_currency(),
			1
		);
		$this->track_event( static::EVENT_PAGE_VISIT, $data );
	}

	/**
	 * Used as a callback for the wp_footer hook.
	 *
	 * @since 1.4.0
	 *
	 * @return void
	 */
	public function handle_view_category() {
		if ( ! is_product_category() ) {
			return;
		}
		$queried_object = get_queried_object();
		$data           = new Category(
			uniqid( 'category' ),
			$queried_object->term_id,
			$queried_object->name
		);
		$this->track_event( static::EVENT_VIEW_CATEGORY, $data );
	}

	/**
	 * Used as a callback for the woocommerce_add_to_cart hook.
	 *
	 * @since 1.4.0
	 *
	 * @param string $cart_item_key - WooCommerce cart item key.
	 * @param string $product_id           - WooCommerce product id.
	 * @param string $quantity             - Number of products.
	 * @param string $variation_id         - Product variation id if any.
	 *
	 * @return void
	 */
	public function handle_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id ) {
		$object_id = empty( $variation_id ) ? $product_id : $variation_id;
		$product   = wc_get_product( $object_id );
		$data      = new Product(
			uniqid( 'cart' ),
			$product->get_id(),
			$product->get_name(),
			wc_get_product_category_list( $product->get_id() ),
			'brand',
			wc_get_price_to_display( $product ),
			get_woocommerce_currency(),
			$quantity
		);
		$this->track_event( static::EVENT_ADD_TO_CART, $data );
	}

	/**
	 * Used as a callback for the woocommerce_checkout_order_created hook.
	 *
	 * @since 1.4.0
	 *
	 * @param string $order_id WooCommerce order id.
	 *
	 * @return void
	 */
	public function handle_checkout( $order_id ) {
		$order = wc_get_order( $order_id );
		if ( ! $order ) {
			return;
		}

		$items          = array();
		$total_quantity = 0;
		foreach ( $order->get_items() as $order_item ) {
			if ( ! method_exists( $order_item, 'get_product' ) ) {
				continue;
			}

			$product = $order_item->get_product();

			$items[] = new Product(
				uniqid( 'product' ),
				$product->get_id(),
				$order_item->get_name(),
				wc_get_product_category_list( $product->get_id() ),
				'brand',
				wc_get_price_to_display( $product ),
				get_woocommerce_currency(),
				$order_item->get_quantity()
			);

			$total_quantity += $order_item->get_quantity();
		}

		$data = new Checkout(
			uniqid( 'checkout' ),
			(string) $order->get_id(),
			$order->get_total(),
			$total_quantity,
			$order->get_currency(),
			$items
		);
		$this->track_event( static::EVENT_CHECKOUT, $data );
	}

	/**
	 * Search event handler.
	 *
	 * @since 1.4.0
	 *
	 * @return void
	 */
	public function handle_search() {
		if ( ! is_search() ) {
			return;
		}

		$data = new Search(
			uniqid( 'pinterest-for-woocommerce-tag-and-conversions-event-id' ),
			get_search_query()
		);
		$this->track_event( static::EVENT_SEARCH, $data );
	}

	/**
	 * Method which iterates over all the attached trackers and delegates the event to them.
	 *
	 * @since 1.4.0
	 *
	 * @param string $event_name Tracking event name.
	 * @param Data   $data       Event Data object.
	 *
	 * @return void
	 */
	public function track_event( string $event_name, Data $data ) {
		foreach ( $this->get_trackers() as $tracker ) {
			// Skip Pinterest tag tracking if tag is not active.
			if ( $tracker instanceof Tag && ! Tag::get_active_tag() ) {
				continue;
			}

			try {
				$tracker->track_event( $event_name, $data );
			} catch ( Throwable $e ) {
				/* translators: %1$s - event name, %2$s - tracker class name, %3$s - error message */
				$message = sprintf(
					'Error while tracking event %1$s with tracker %2$s. Error: %3$s',
					$event_name,
					get_class( $tracker ),
					$e->getMessage()
				);
				Logger::log( $message, 'error' );
			}
		}
	}

	/**
	 * Returns an array of registered trackers.
	 *
	 * @since 1.4.0
	 *
	 * @return Tracker[]
	 */
	public function get_trackers() {
		return $this->trackers;
	}

	/**
	 * Adds a tracker to the array of trackers.
	 *
	 * @since 1.4.0
	 *
	 * @param Tracker $tracker - One of objects implementing Tracker interface.
	 *
	 * @return void
	 */
	public function add_tracker( Tracker $tracker ) {
		$tracker->init_hooks();
		$this->trackers[ get_class( $tracker ) ] = $tracker;
	}

	/**
	 * Removes a tracker.
	 *
	 * @since 1.4.0
	 *
	 * @param string $tracker Tracker class name to be removed. e.g. Tag::class, Conversions::class.
	 *
	 * @return void
	 */
	public function remove_tracker( string $tracker ) {
		$this->trackers = array_filter(
			$this->trackers,
			function ( $item ) use ( $tracker ) {
				if ( get_class( $item ) === $tracker ) {
					$item->disable_hooks();
					return false;
				}
				return true;
			}
		);
	}
}

SILENT KILLER Tool