Tracks: Add tracking event when OBW is started (#22877)

* Check if current step matches event before firing

* Move step check to switch statement

* Track when the OBW has started

* Rename Jetpack activation tracking method

* Remove duplicate tracking optin check

* Track when option to track is udpated in OBW

* Check if tracking is actively being opted into in is_tracking_enabled()

* Move tracking start check into WC_Admin_Setup_Wizard_Tracking

* Clean up tracking opt-in check logic
This commit is contained in:
Joshua T Flowers 2019-03-01 11:12:30 +08:00 committed by GitHub
parent 234f3a1bb9
commit e53724832d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 8 deletions

View File

@ -32,10 +32,7 @@ class WC_Admin {
add_action( 'admin_footer', 'wc_print_js', 25 );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
add_action( 'wp_ajax_setup_wizard_check_jetpack', array( $this, 'setup_wizard_check_jetpack' ) );
if ( 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) {
add_action( 'init', array( 'WC_Site_Tracking', 'init' ) );
}
add_action( 'init', array( 'WC_Site_Tracking', 'init' ) );
}
/**

View File

@ -21,8 +21,15 @@ class WC_Site_Tracking {
* Don't track users who haven't opted-in to tracking or if a filter
* has been applied to turn it off.
*/
if ( 'yes' !== get_option( 'woocommerce_allow_tracking' ) ||
! apply_filters( 'woocommerce_apply_user_tracking', true ) ) {
if ( ! apply_filters( 'woocommerce_apply_user_tracking', true ) ) {
return false;
}
// Check if tracking is actively being opted into.
$is_obw_opting_in = isset( $_POST['wc_tracker_checkbox'] ) && 'yes' === sanitize_text_field( $_POST['wc_tracker_checkbox'] ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.ValidatedSanitizedInput
if ( 'yes' !== get_option( 'woocommerce_allow_tracking' ) && ! $is_obw_opting_in ) {
return false;
}

View File

@ -46,9 +46,25 @@ class WC_Admin_Setup_Wizard_Tracking {
add_filter( 'woocommerce_setup_wizard_steps', array( __CLASS__, 'set_obw_steps' ) );
add_action( 'shutdown', array( __CLASS__, 'track_skip_step' ), 1 );
add_action( 'add_option_woocommerce_allow_tracking', array( __CLASS__, 'track_start' ), 10, 2 );
self::add_step_save_events();
}
/**
* Track when tracking is opted into and OBW has started.
*
* @param string $option Option name.
* @param string $value Option value.
* @return void
*/
public static function track_start( $option, $value ) {
if ( 'yes' !== $value || empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
return;
}
WC_Tracks::record_event( 'obw_start' );
}
/**
* Track various events when a step is saved.
*/
@ -75,7 +91,7 @@ class WC_Admin_Setup_Wizard_Tracking {
add_action( 'admin_init', array( __CLASS__, 'track_recommended' ), 1 );
break;
case 'activate':
add_action( 'admin_init', array( __CLASS__, 'track_activate' ), 1 );
add_action( 'admin_init', array( __CLASS__, 'track_jetpack_activate' ), 1 );
break;
}
}
@ -180,7 +196,7 @@ class WC_Admin_Setup_Wizard_Tracking {
*
* @return void
*/
public static function track_activate() {
public static function track_jetpack_activate() {
WC_Tracks::record_event( 'obw_activate' );
}