File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Tracking.tar
EventTracking.php 0000644 00000003667 15154217471 0010044 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ValidateInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\ActivatedEvents;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\BaseEvent;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\GenericEvents;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\SiteClaimEvents;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\SiteVerificationEvents;
/**
* Wire up the Google for WooCommerce events to Tracks.
* Add all new events to `$events`.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class EventTracking implements ContainerAwareInterface, Registerable, Service {
use ContainerAwareTrait;
use ValidateInterface;
/**
* Individual events classes to load.
*
* @var string[]
*/
protected $events = [
ActivatedEvents::class,
GenericEvents::class,
SiteClaimEvents::class,
SiteVerificationEvents::class,
];
/**
* Hook extension tracker data into the WC tracker data.
*/
public function register(): void {
add_action(
'init',
function () {
$this->register_events();
},
20 // After WC_Admin loads WC_Tracks class (init 10).
);
}
/**
* Register all of our event tracking classes.
*/
protected function register_events() {
foreach ( $this->events as $class ) {
/** @var BaseEvent $instance */
$instance = $this->container->get( $class );
$this->validate_instanceof( $instance, BaseEvent::class );
$instance->register();
}
}
}
Events/ActivatedEvents.php 0000644 00000004237 15154217471 0011627 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Activateable;
/**
* This class adds actions to track when the extension is activated.
* *
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class ActivatedEvents extends BaseEvent implements Activateable {
/**
* The page where activation with a source can occur.
*/
public const ACTIVATION_PAGE = 'plugin-install.php';
/**
* The query parameters used to determine activation source details.
*/
public const SOURCE_PARAMS = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
];
/**
* @var array The request SERVER variables.
*/
private $server_vars;
/**
* ActivatedEvents constructor.
*
* @param array $server_vars The request SERVER variables.
*/
public function __construct( array $server_vars ) {
$this->server_vars = $server_vars;
}
/**
* Nothing to register (method invoked manually).
*/
public function register(): void {}
/**
* Track when the extension is activated from a source.
*/
public function maybe_track_activation_source(): void {
// Skip WP-CLI activations
if ( empty( $this->server_vars['HTTP_REFERER'] ) ) {
return;
}
$url_components = wp_parse_url( $this->server_vars['HTTP_REFERER'] );
// Skip invalid URLs or URLs missing parts
if ( ! is_array( $url_components ) || empty( $url_components['query'] ) || empty( $url_components['path'] ) ) {
return;
}
// Skip activations from anywhere except the Add Plugins page
if ( false === strstr( $url_components['path'], self::ACTIVATION_PAGE ) ) {
return;
}
wp_parse_str( $url_components['query'], $query_vars );
$available_source_params = array_intersect_key( $query_vars, array_flip( self::SOURCE_PARAMS ) );
// Skip if no source params are present
if ( empty( $available_source_params ) ) {
return;
}
$this->record_event( 'activated_from_source', $available_source_params );
}
/**
* Activate the service.
*
* @return void
*/
public function activate(): void {
$this->maybe_track_activation_source();
}
}
Events/BaseEvent.php 0000644 00000001564 15154217471 0010412 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\TracksAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\TracksAwareTrait;
/**
* Class BaseEvent
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events
*/
abstract class BaseEvent implements TracksEventInterface, TracksAwareInterface {
use TracksAwareTrait;
use PluginHelper;
/**
* Record an event using the Tracks instance.
*
* @param string $event_name The event name to record.
* @param array $properties (Optional) Properties to record with the event.
*/
protected function record_event( string $event_name, $properties = [] ) {
$this->tracks->record_event( $event_name, $properties );
}
}
Events/GenericEvents.php 0000644 00000001637 15154217471 0011300 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
/**
* This class adds an action to track a generic event, which can be triggered by:
* `do_action( 'woocommerce_gla_track_event', 'event_name', $properties )`
*
* @since 2.5.16
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class GenericEvents extends BaseEvent {
/**
* Register the tracking class.
*/
public function register(): void {
add_action( 'woocommerce_gla_track_event', [ $this, 'track_event' ], 10, 2 );
}
/**
* Track a generic event providing event name and optional list of properties.
*
* @param string $event_name Event name to record.
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_event( string $event_name, array $properties = [] ) {
$this->record_event( $event_name, $properties );
}
}
Events/SiteClaimEvents.php 0000644 00000005725 15154217471 0011600 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
/**
* This class adds actions to track for Site Claim actions:
* - Site claim required
* - Site claim success
* - Site claim failure
* - Merchant Center URL switch
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class SiteClaimEvents extends BaseEvent {
/**
* Register the tracking class.
*/
public function register(): void {
add_action( 'woocommerce_gla_site_claim_overwrite_required', [ $this, 'track_site_claim_overwrite_required' ] );
add_action( 'woocommerce_gla_site_claim_success', [ $this, 'track_site_claim_success' ] );
add_action( 'woocommerce_gla_site_claim_failure', [ $this, 'track_site_claim_failure' ] );
add_action( 'woocommerce_gla_url_switch_required', [ $this, 'track_url_switch_required' ] );
add_action( 'woocommerce_gla_url_switch_success', [ $this, 'track_url_switch_success' ] );
}
/**
* Track when a site claim needs to be overwritten.
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_site_claim_overwrite_required( array $properties = [] ): void {
$properties['action'] = 'overwrite_required';
$this->track_site_claim_event( $properties );
}
/**
* Track when a site is claimed successfully.
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_site_claim_success( array $properties = [] ): void {
$properties['action'] = 'success';
$this->track_site_claim_event( $properties );
}
/**
* Track when a site fails to be claimed.
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_site_claim_failure( array $properties = [] ): void {
$properties['action'] = 'failure';
$this->track_site_claim_event( $properties );
}
/**
* Track the generic site claim event with the action property.
*
* @param array $properties
*/
protected function track_site_claim_event( array $properties = [] ): void {
$this->record_event( 'site_claim', $properties );
}
/**
* Track when a site requires a URL switch
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_url_switch_required( array $properties = [] ): void {
$properties['action'] = 'required';
$this->track_url_switch_event( $properties );
}
/**
* Track when a site executes a successful URL switch
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_url_switch_success( array $properties = [] ): void {
$properties['action'] = 'success';
$this->track_url_switch_event( $properties );
}
/**
* Track the generic url switch event with the action property.
*
* @param array $properties
*/
protected function track_url_switch_event( array $properties = [] ): void {
$this->record_event( 'mc_url_switch', $properties );
}
}
Events/SiteVerificationEvents.php 0000644 00000002202 15154217471 0013160 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
/**
* This class adds actions to track when Site Verification is attempted (succeeds/fails).
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class SiteVerificationEvents extends BaseEvent {
/**
* Register the tracking class.
*/
public function register(): void {
add_action( 'woocommerce_gla_site_verify_success', [ $this, 'track_site_verify_success' ] );
add_action( 'woocommerce_gla_site_verify_failure', [ $this, 'track_site_verify_failure' ] );
}
/**
* Track when a site is verified
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_site_verify_success( array $properties = [] ): void {
$this->record_event( 'site_verify_success', $properties );
}
/**
* Track when a site fails to be verified.
*
* @param array $properties Optional additional properties to pass with the event.
*/
public function track_site_verify_failure( array $properties = [] ): void {
$this->record_event( 'site_verify_failure', $properties );
}
}
Events/TracksEventInterface.php 0000644 00000000553 15154217471 0012605 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
/**
* Interface describing an event tracker class.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
interface TracksEventInterface extends Registerable {}
TrackerSnapshot.php 0000644 00000010704 15154217471 0010401 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
use Automattic\WooCommerce\GoogleListingsAndAds\Ads\AdsService;
use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\MerchantMetrics;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Registerable;
use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\MerchantCenterService;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\TargetAudience;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper;
/**
* Include Google for WooCommerce data in the WC Tracker snapshot.
*
* ContainerAware used to access:
* - AdsService
* - MerchantCenterService
* - MerchantMetrics
* - TargetAudience
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class TrackerSnapshot implements ContainerAwareInterface, OptionsAwareInterface, Registerable, Service {
use ContainerAwareTrait;
use OptionsAwareTrait;
use PluginHelper;
/**
* Hook extension tracker data into the WC tracker data.
*/
public function register(): void {
add_filter(
'woocommerce_tracker_data',
function ( $data ) {
return $this->include_snapshot_data( $data );
}
);
}
/**
* Add extension data to the WC Tracker snapshot.
*
* @param array $data The existing array of tracker data.
*
* @return array The updated array of tracker data.
*/
protected function include_snapshot_data( $data = [] ): array {
if ( ! isset( $data['extensions'] ) ) {
$data['extensions'] = [];
}
$data['extensions'][ $this->get_slug() ] = [
'settings' => $this->get_settings(),
];
return $data;
}
/**
* Get general extension and settings data for the extension.
*
* @return array
*/
protected function get_settings(): array {
/** @var TargetAudience $target_audience */
$target_audience = $this->container->get( TargetAudience::class );
$mc_settings = $this->options->get( OptionsInterface::MERCHANT_CENTER );
/** @var AdsService $ads_service */
$ads_service = $this->container->get( AdsService::class );
/** @var MerchantCenterService $mc_service */
$mc_service = $this->container->get( MerchantCenterService::class );
/** @var MerchantMetrics $merchant_metrics */
$merchant_metrics = $this->container->get( MerchantMetrics::class );
return [
'version' => $this->get_version(),
'db_version' => $this->options->get( OptionsInterface::DB_VERSION ),
'tos_accepted' => $this->get_boolean_value( OptionsInterface::WP_TOS_ACCEPTED ),
'google_connected' => $this->get_boolean_value( OptionsInterface::GOOGLE_CONNECTED ),
'mc_setup' => $this->get_boolean_value( OptionsInterface::MC_SETUP_COMPLETED_AT ),
'ads_setup' => $this->get_boolean_value( OptionsInterface::ADS_SETUP_COMPLETED_AT ),
'target_audience' => $target_audience->get_target_countries(),
'shipping_rate' => $mc_settings['shipping_rate'] ?? '',
'shipping_time' => $mc_settings['shipping_time'] ?? '',
'tax_rate' => $mc_settings['tax_rate'] ?? '',
'has_account_issue' => $mc_service->is_connected() && $mc_service->has_account_issues() ? 'yes' : 'no',
'has_at_least_one_synced_product' => $mc_service->is_connected() && $mc_service->has_at_least_one_synced_product() ? 'yes' : 'no',
'ads_setup_started' => $ads_service->is_setup_started() ? 'yes' : 'no',
'ads_customer_id' => $this->options->get_ads_id(),
'ads_campaign_count' => $merchant_metrics->get_campaign_count(),
'wpcom_api_authorized' => $this->options->is_wpcom_api_authorized(),
];
}
/**
* Get boolean value from options, return as yes or no.
*
* @param string $key Option key name.
*
* @return string
*/
protected function get_boolean_value( string $key ): string {
return (bool) $this->options->get( $key ) ? 'yes' : 'no';
}
}
Tracks.php 0000644 00000003363 15154217471 0006520 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\Tracks as TracksProxy;
/**
* Tracks implementation for Google for WooCommerce.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
class Tracks implements TracksInterface, OptionsAwareInterface {
use OptionsAwareTrait;
use PluginHelper;
/**
* @var TracksProxy
*/
protected $tracks;
/**
* Tracks constructor.
*
* @param TracksProxy $tracks The proxy tracks object.
*/
public function __construct( TracksProxy $tracks ) {
$this->tracks = $tracks;
}
/**
* Record an event in Tracks - this is the preferred way to record events from PHP.
*
* @param string $event_name The name of the event.
* @param array $properties Custom properties to send with the event.
*/
public function record_event( $event_name, $properties = [] ) {
// Include base properties.
$base_properties = [
"{$this->get_slug()}_version" => $this->get_version(),
];
// Include connected accounts (if connected).
if ( $this->options->get_ads_id() ) {
$base_properties[ "{$this->get_slug()}_ads_id" ] = $this->options->get_ads_id();
}
if ( $this->options->get_merchant_id() ) {
$base_properties[ "{$this->get_slug()}_mc_id" ] = $this->options->get_merchant_id();
}
$properties = array_merge( $base_properties, $properties );
$full_event_name = "{$this->get_slug()}_{$event_name}";
$this->tracks->record_event( $full_event_name, $properties );
}
}
TracksAwareInterface.php 0000644 00000000611 15154217471 0011312 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
/**
* Interface TracksAwareInterface
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
interface TracksAwareInterface {
/**
* Set the tracks interface object.
*
* @param TracksInterface $tracks
*/
public function set_tracks( TracksInterface $tracks ): void;
}
TracksAwareTrait.php 0000644 00000000753 15154217471 0010504 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
/**
* Trait TracksAwareTrait
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
trait TracksAwareTrait {
/**
* The tracks object.
*
* @var TracksInterface
*/
protected $tracks;
/**
* Set the tracks interface object.
*
* @param TracksInterface $tracks
*/
public function set_tracks( TracksInterface $tracks ): void {
$this->tracks = $tracks;
}
}
TracksInterface.php 0000644 00000001036 15154217471 0010334 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Tracking;
/**
* Tracks interface for Google for WooCommerce.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Tracking
*/
interface TracksInterface {
/**
* Record an event in Tracks - this is the preferred way to record events from PHP.
*
* @param string $event_name The name of the event.
* @param array $properties Custom properties to send with the event.
*/
public function record_event( $event_name, $properties = [] );
}