class-wc-admin-setup-wizard-tracking.php
5 years ago
class-wc-coupon-tracking.php
6 years ago
class-wc-coupons-tracking.php
7 months ago
class-wc-extensions-tracking.php
1 year ago
class-wc-importer-tracking.php
3 years ago
class-wc-order-tracking.php
6 years ago
class-wc-orders-tracking.php
1 year ago
class-wc-product-collection-block-tracking.php
7 months ago
class-wc-products-tracking.php
1 month ago
class-wc-settings-tracking.php
11 months ago
class-wc-status-tracking.php
7 months ago
class-wc-theme-tracking.php
1 year ago
class-wc-extensions-tracking.php
136 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Extensions Tracking |
| 4 | * |
| 5 | * @package WooCommerce\Tracks |
| 6 | */ |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * This class adds actions to track usage of the WooCommerce Extensions page. |
| 12 | */ |
| 13 | class WC_Extensions_Tracking { |
| 14 | /** |
| 15 | * Init tracking. |
| 16 | */ |
| 17 | public function init() { |
| 18 | add_action( 'load-woocommerce_page_wc-addons', array( $this, 'track_extensions_page' ) ); |
| 19 | add_action( 'woocommerce_helper_connect_start', array( $this, 'track_helper_connection_start' ) ); |
| 20 | add_action( 'woocommerce_helper_denied', array( $this, 'track_helper_connection_cancelled' ) ); |
| 21 | add_action( 'woocommerce_helper_connected', array( $this, 'track_helper_connection_complete' ) ); |
| 22 | add_action( 'woocommerce_helper_disconnected', array( $this, 'track_helper_disconnected' ) ); |
| 23 | add_action( 'woocommerce_helper_subscriptions_refresh', array( $this, 'track_helper_subscriptions_refresh' ) ); |
| 24 | add_action( 'woocommerce_addon_installed', array( $this, 'track_addon_install' ), 10, 2 ); |
| 25 | add_action( 'woocommerce_page_wc-addons_connection_error', array( $this, 'track_extensions_page_connection_error' ), 10, 1 ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Send a Tracks event when an Extensions page is viewed. |
| 30 | */ |
| 31 | public function track_extensions_page() { |
| 32 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 33 | $properties = array( |
| 34 | 'section' => empty( $_REQUEST['section'] ) ? '_featured' : wc_clean( wp_unslash( $_REQUEST['section'] ) ), |
| 35 | ); |
| 36 | |
| 37 | $event = 'extensions_view'; |
| 38 | if ( 'helper' === $properties['section'] ) { |
| 39 | $event = 'subscriptions_view'; |
| 40 | } |
| 41 | |
| 42 | if ( ! empty( $_REQUEST['search'] ) ) { |
| 43 | $event = 'extensions_view_search'; |
| 44 | $properties['search_term'] = wc_clean( wp_unslash( $_REQUEST['search'] ) ); |
| 45 | } |
| 46 | // phpcs:enable |
| 47 | |
| 48 | WC_Tracks::record_event( $event, $properties ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Send a Tracks event when the Extensions page gets a bad response or no response |
| 53 | * from the WCCOM extensions API. |
| 54 | * |
| 55 | * @param string $error Error message. |
| 56 | */ |
| 57 | public function track_extensions_page_connection_error( string $error = '' ) { |
| 58 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 59 | $properties = array( |
| 60 | 'section' => empty( $_REQUEST['section'] ) ? '_featured' : wc_clean( wp_unslash( $_REQUEST['section'] ) ), |
| 61 | ); |
| 62 | |
| 63 | if ( ! empty( $_REQUEST['search'] ) ) { |
| 64 | $properties['search_term'] = wc_clean( wp_unslash( $_REQUEST['search'] ) ); |
| 65 | } |
| 66 | // phpcs:enable |
| 67 | |
| 68 | if ( ! empty( $error ) ) { |
| 69 | $properties['error_data'] = $error; |
| 70 | } |
| 71 | WC_Tracks::record_event( 'extensions_view_connection_error', $properties ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Send a Tracks even when a Helper connection process is initiated. |
| 76 | */ |
| 77 | public function track_helper_connection_start() { |
| 78 | WC_Tracks::record_event( 'extensions_subscriptions_connect' ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Send a Tracks even when a Helper connection process is cancelled. |
| 83 | */ |
| 84 | public function track_helper_connection_cancelled() { |
| 85 | WC_Tracks::record_event( 'extensions_subscriptions_cancelled' ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Send a Tracks even when a Helper connection process completed successfully. |
| 90 | */ |
| 91 | public function track_helper_connection_complete() { |
| 92 | $properties = array(); |
| 93 | |
| 94 | if ( ! empty( $_GET['utm_source'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 95 | $properties['utm_source'] = wc_clean( wp_unslash( $_GET['utm_source'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 96 | } |
| 97 | |
| 98 | if ( ! empty( $_GET['utm_campaign'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 99 | $properties['utm_campaign'] = wc_clean( wp_unslash( $_GET['utm_campaign'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 100 | } |
| 101 | |
| 102 | WC_Tracks::record_event( 'extensions_subscriptions_connected', $properties ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Send a Tracks even when a Helper has been disconnected. |
| 107 | */ |
| 108 | public function track_helper_disconnected() { |
| 109 | WC_Tracks::record_event( 'extensions_subscriptions_disconnect' ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Send a Tracks even when Helper subscriptions are refreshed. |
| 114 | */ |
| 115 | public function track_helper_subscriptions_refresh() { |
| 116 | WC_Tracks::record_event( 'extensions_subscriptions_update' ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Send a Tracks event when addon is installed via the Extensions page. |
| 121 | * |
| 122 | * @param string $addon_id Addon slug. |
| 123 | * @param string $section Extensions tab. |
| 124 | */ |
| 125 | public function track_addon_install( $addon_id, $section ) { |
| 126 | $properties = array( |
| 127 | 'context' => 'extensions', |
| 128 | 'section' => $section, |
| 129 | ); |
| 130 | |
| 131 | if ( 'woocommerce-payments' === $addon_id ) { |
| 132 | WC_Tracks::record_event( 'woocommerce_payments_install', $properties ); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 |