Merge pull request #29052 from woocommerce/add/install_wcpay_addon_tracks

Add tracks event for WooCommerce Payments install via wc-addons page
This commit is contained in:
Peter Fabian 2021-02-25 15:04:36 +01:00 committed by GitHub
commit 47bfca58b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -641,7 +641,7 @@ class WC_Admin_Addons {
self::install_woocommerce_services_addon(); self::install_woocommerce_services_addon();
break; break;
case 'woocommerce-payments': case 'woocommerce-payments':
self::install_woocommerce_payments_addon(); self::install_woocommerce_payments_addon( $section );
break; break;
default: default:
// Do nothing. // Do nothing.
@ -693,9 +693,11 @@ class WC_Admin_Addons {
/** /**
* Install WooCommerce Payments from the Extensions screens. * Install WooCommerce Payments from the Extensions screens.
* *
* @param string $section Optional. Extenstions tab.
*
* @return void * @return void
*/ */
public static function install_woocommerce_payments_addon() { public static function install_woocommerce_payments_addon( $section = '_featured' ) {
check_admin_referer( 'install-addon_woocommerce-payments' ); check_admin_referer( 'install-addon_woocommerce-payments' );
$wcpay_plugin_id = 'woocommerce-payments'; $wcpay_plugin_id = 'woocommerce-payments';
@ -704,7 +706,9 @@ class WC_Admin_Addons {
'repo-slug' => 'woocommerce-payments', 'repo-slug' => 'woocommerce-payments',
); );
WC_Install::background_installer( $services_plugin_id, $wcpay_plugin ); WC_Install::background_installer( $wcpay_plugin_id, $wcpay_plugin );
do_action( 'woocommerce_addon_installed', $wcpay_plugin_id, $section );
wp_safe_redirect( remove_query_arg( array( 'install-addon', '_wpnonce' ) ) ); wp_safe_redirect( remove_query_arg( array( 'install-addon', '_wpnonce' ) ) );
exit; exit;

View File

@ -21,6 +21,7 @@ class WC_Extensions_Tracking {
add_action( 'woocommerce_helper_connected', array( $this, 'track_helper_connection_complete' ) ); 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_disconnected', array( $this, 'track_helper_disconnected' ) );
add_action( 'woocommerce_helper_subscriptions_refresh', array( $this, 'track_helper_subscriptions_refresh' ) ); add_action( 'woocommerce_helper_subscriptions_refresh', array( $this, 'track_helper_subscriptions_refresh' ) );
add_action( 'woocommerce_addon_installed', array( $this, 'track_addon_install' ), 10, 2 );
} }
/** /**
@ -76,4 +77,21 @@ class WC_Extensions_Tracking {
public function track_helper_subscriptions_refresh() { public function track_helper_subscriptions_refresh() {
WC_Tracks::record_event( 'extensions_subscriptions_update' ); WC_Tracks::record_event( 'extensions_subscriptions_update' );
} }
/**
* Send a Tracks event when addon is installed via the Extensions page.
*
* @param string $addon_id Addon slug.
* @param string $section Extensions tab.
*/
public function track_addon_install( $addon_id, $section ) {
$properties = array(
'context' => 'extensions',
'section' => $section,
);
if ( 'woocommerce-payments' === $addon_id ) {
WC_Tracks::record_event( 'woocommerce_payments_install', $properties );
}
}
} }