2019-02-21 22:45:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Extensions Tracking
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tracks
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class adds actions to track usage of the WooCommerce Extensions page.
|
|
|
|
*/
|
|
|
|
class WC_Extensions_Tracking {
|
|
|
|
/**
|
|
|
|
* Init tracking.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function init() {
|
|
|
|
add_action( 'load-woocommerce_page_wc-addons', array( $this, 'track_extensions_page' ) );
|
|
|
|
add_action( 'woocommerce_helper_connect_start', array( $this, 'track_helper_connection_start' ) );
|
|
|
|
add_action( 'woocommerce_helper_denied', array( $this, 'track_helper_connection_cancelled' ) );
|
|
|
|
add_action( 'woocommerce_helper_connected', array( $this, 'track_helper_connection_complete' ) );
|
|
|
|
add_action( 'woocommerce_helper_disconnected', array( $this, 'track_helper_disconnected' ) );
|
|
|
|
add_action( 'woocommerce_helper_subscriptions_refresh', array( $this, 'track_helper_subscriptions_refresh' ) );
|
2021-02-23 03:25:40 +00:00
|
|
|
add_action( 'woocommerce_addon_installed', array( $this, 'track_addon_install' ), 10, 2 );
|
2019-02-21 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks event when an Extensions page is viewed.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_extensions_page() {
|
2019-12-13 19:58:14 +00:00
|
|
|
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
2019-02-21 22:45:43 +00:00
|
|
|
$properties = array(
|
|
|
|
'section' => empty( $_REQUEST['section'] ) ? '_featured' : wc_clean( wp_unslash( $_REQUEST['section'] ) ),
|
|
|
|
);
|
|
|
|
|
2021-08-12 13:50:55 +00:00
|
|
|
$event = 'extensions_view';
|
|
|
|
if ( 'helper' === $properties['section'] ) {
|
|
|
|
$event = 'subscriptions_view';
|
|
|
|
}
|
|
|
|
|
2019-02-21 22:45:43 +00:00
|
|
|
if ( ! empty( $_REQUEST['search'] ) ) {
|
|
|
|
$event = 'extensions_view_search';
|
|
|
|
$properties['search_term'] = wc_clean( wp_unslash( $_REQUEST['search'] ) );
|
|
|
|
}
|
|
|
|
// phpcs:enable
|
|
|
|
|
|
|
|
WC_Tracks::record_event( $event, $properties );
|
|
|
|
}
|
2019-02-21 23:28:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks even when a Helper connection process is initiated.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_helper_connection_start() {
|
2019-02-21 23:28:15 +00:00
|
|
|
WC_Tracks::record_event( 'extensions_subscriptions_connect' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks even when a Helper connection process is cancelled.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_helper_connection_cancelled() {
|
2019-02-21 23:28:15 +00:00
|
|
|
WC_Tracks::record_event( 'extensions_subscriptions_cancelled' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks even when a Helper connection process completed successfully.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_helper_connection_complete() {
|
2019-02-21 23:28:15 +00:00
|
|
|
WC_Tracks::record_event( 'extensions_subscriptions_connected' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks even when a Helper has been disconnected.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_helper_disconnected() {
|
2019-02-21 23:28:15 +00:00
|
|
|
WC_Tracks::record_event( 'extensions_subscriptions_disconnect' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a Tracks even when Helper subscriptions are refreshed.
|
|
|
|
*/
|
2019-03-05 00:30:01 +00:00
|
|
|
public function track_helper_subscriptions_refresh() {
|
2019-02-21 23:28:15 +00:00
|
|
|
WC_Tracks::record_event( 'extensions_subscriptions_update' );
|
|
|
|
}
|
2021-02-08 08:29:44 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-11 04:54:44 +00:00
|
|
|
* Send a Tracks event when addon is installed via the Extensions page.
|
|
|
|
*
|
|
|
|
* @param string $addon_id Addon slug.
|
2021-02-23 03:25:40 +00:00
|
|
|
* @param string $section Extensions tab.
|
2021-02-08 08:29:44 +00:00
|
|
|
*/
|
2021-02-23 03:25:40 +00:00
|
|
|
public function track_addon_install( $addon_id, $section ) {
|
|
|
|
$properties = array(
|
|
|
|
'context' => 'extensions',
|
|
|
|
'section' => $section,
|
|
|
|
);
|
2021-02-08 08:29:44 +00:00
|
|
|
|
2021-02-11 04:54:44 +00:00
|
|
|
if ( 'woocommerce-payments' === $addon_id ) {
|
|
|
|
WC_Tracks::record_event( 'woocommerce_payments_install', $properties );
|
|
|
|
}
|
2021-02-08 08:29:44 +00:00
|
|
|
}
|
2019-02-21 22:45:43 +00:00
|
|
|
}
|