* Spike out customer effort score

* Refactor CustomerEffortScore as Package (https://github.com/woocommerce/woocommerce-admin/pull/5342)

* Tidy up _webpack.config.js

* Fix linter issues

* refactor setting up CES tracking, add try..catch around loading from localStorage

* Add CES feature toggle (https://github.com/woocommerce/woocommerce-admin/pull/5387)

* Add feature toggle to only enable the customer effort score in development

* Move check into Loader

* fix logic 🙄

Co-authored-by: Rebecca Scott <me@becdetat.com>

* Add client-side check of the feature flag

* fix tabs in config

* Fix comment

* Use product lifecycle and options

* Add product count to tracks props

* Use Loader::load_features instead of DIY

* Only show the CES survey in the correct screen

Co-authored-by: Rebecca Scott <me@becdetat.com>
Co-authored-by: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com>
This commit is contained in:
Bec Scott 2020-11-02 16:08:17 +10:00 committed by GitHub
parent 1e1e428354
commit 0a1cec3d4e
2 changed files with 42 additions and 10 deletions

View File

@ -31,13 +31,19 @@ function CustomerEffortScoreTracksContainer( {
return null;
}
if ( queue.length ) {
const queueForPage = queue.filter(
( item ) =>
item.pagenow === window.pagenow &&
item.adminpage === window.adminpage
);
if ( queueForPage.length ) {
clearQueue();
}
return (
<>
{ queue.map( ( item, index ) => (
{ queueForPage.map( ( item, index ) => (
<CustomerEffortScoreTracks
key={ index }
initiallyVisible={ true }
@ -86,7 +92,10 @@ export default compose(
// directly puts this into an infinite loop which is picked
// up by React.
updateOptions( {
woocommerce_clear_ces_tracks_queue: true,
woocommerce_clear_ces_tracks_queue_for_page: {
pagenow: window.pagenow,
adminpage: window.adminpage,
},
} );
},
};

View File

@ -13,8 +13,10 @@ defined( 'ABSPATH' ) || exit;
* Triggers customer effort score on several different actions.
*/
class CustomerEffortScoreTracks {
const CES_TRACKS_QUEUE_OPTION_NAME = 'woocommerce_ces_tracks_queue';
const CLEAR_CES_TRACKS_QUEUE_OPTION_NAME = 'woocommerce_clear_ces_tracks_queue';
const CES_TRACKS_QUEUE_OPTION_NAME = 'woocommerce_ces_tracks_queue';
const CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME
= 'woocommerce_clear_ces_tracks_queue_for_page';
/**
* Constructor. Sets up filters to hook into WooCommerce.
@ -98,6 +100,8 @@ class CustomerEffortScoreTracks {
'How easy was it to add a product?',
'woocommerce-admin'
),
'pagenow' => 'product',
'adminpage' => 'post-php',
'props' => array(
'product_count' => $this->get_product_count(),
),
@ -118,6 +122,8 @@ class CustomerEffortScoreTracks {
'How easy was it to edit your product?',
'woocommerce-admin'
),
'pagenow' => 'product',
'adminpage' => 'post-php',
'props' => array(
'product_count' => $this->get_product_count(),
),
@ -133,14 +139,31 @@ class CustomerEffortScoreTracks {
* sets the clear option.
*/
public function maybe_clear_ces_tracks_queue() {
$clear_ces_tracks_queue = get_option(
self::CLEAR_CES_TRACKS_QUEUE_OPTION_NAME,
$clear_ces_tracks_queue_for_page = get_option(
self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME,
false
);
if ( $clear_ces_tracks_queue ) {
update_option( self::CES_TRACKS_QUEUE_OPTION_NAME, array() );
update_option( self::CLEAR_CES_TRACKS_QUEUE_OPTION_NAME, false );
if ( ! $clear_ces_tracks_queue_for_page ) {
return;
}
$queue = get_option(
self::CES_TRACKS_QUEUE_OPTION_NAME,
array()
);
$remaining_items = array_filter(
$queue,
function( $item ) use ( $clear_ces_tracks_queue_for_page ) {
return $clear_ces_tracks_queue_for_page['pagenow'] !== $item['pagenow']
|| $clear_ces_tracks_queue_for_page['adminpage'] !== $item['adminpage'];
}
);
update_option(
self::CES_TRACKS_QUEUE_OPTION_NAME,
array_values( $remaining_items )
);
update_option( self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME, false );
}
}