From b40c4a95e5f8e92413abb335d1687d8b8efc230b Mon Sep 17 00:00:00 2001 From: Vlad Olaru Date: Mon, 9 Sep 2024 18:06:43 +0300 Subject: [PATCH] Attach WooPayments incentive ID to wcadmin_tasklist_click Tracks event props (#51105) * Add WooPayments incentive ID to task additional data * Attach WooPayments incentive ID to wcadmin_tasklist_click Tracks event * Add changelog * Add changelog * Replace short array syntax * docs: Update docs --- ...1103-woopayments-incentive-to-tracks-props | 4 +++ packages/js/data/src/onboarding/types.ts | 1 + .../task-lists/fills/tax/test/index.tsx | 2 +- .../setup-task-list/setup-task-list.tsx | 4 +++ ...1103-woopayments-incentive-to-tracks-props | 5 +++ plugins/woocommerce/src/Admin/API/Plugins.php | 4 +-- .../Tasks/WooCommercePayments.php | 17 +++++++++- .../src/Internal/Admin/WcPayWelcomePage.php | 33 ++++++++++++++++--- 8 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 packages/js/data/changelog/update-51103-woopayments-incentive-to-tracks-props create mode 100644 plugins/woocommerce/changelog/update-51103-woopayments-incentive-to-tracks-props diff --git a/packages/js/data/changelog/update-51103-woopayments-incentive-to-tracks-props b/packages/js/data/changelog/update-51103-woopayments-incentive-to-tracks-props new file mode 100644 index 00000000000..c0d87293d0e --- /dev/null +++ b/packages/js/data/changelog/update-51103-woopayments-incentive-to-tracks-props @@ -0,0 +1,4 @@ +Significance: patch +Type: update + +Add wooPaymentsIncentiveId to the TaskType additionalData. diff --git a/packages/js/data/src/onboarding/types.ts b/packages/js/data/src/onboarding/types.ts index a39fa627e63..7e3e3058c73 100644 --- a/packages/js/data/src/onboarding/types.ts +++ b/packages/js/data/src/onboarding/types.ts @@ -35,6 +35,7 @@ export type TaskType = { stripeTaxActivated?: boolean; woocommerceTaxActivated?: boolean; woocommerceShippingActivated?: boolean; + wooPaymentsIncentiveId?: string; }; // Possibly added in DeprecatedTasks.mergeDeprecatedCallbackFunctions isDeprecated?: boolean; diff --git a/plugins/woocommerce-admin/client/task-lists/fills/tax/test/index.tsx b/plugins/woocommerce-admin/client/task-lists/fills/tax/test/index.tsx index 0e744c53f33..2b1edb3e310 100644 --- a/plugins/woocommerce-admin/client/task-lists/fills/tax/test/index.tsx +++ b/plugins/woocommerce-admin/client/task-lists/fills/tax/test/index.tsx @@ -17,7 +17,7 @@ jest.mock( '@wordpress/data', () => ( { const fakeTask: { additionalData: { - [ key: string ]: boolean | string[]; + [ key: string ]: boolean | string | string[]; }; } = { additionalData: {}, diff --git a/plugins/woocommerce-admin/client/task-lists/setup-task-list/setup-task-list.tsx b/plugins/woocommerce-admin/client/task-lists/setup-task-list/setup-task-list.tsx index 9649f9c3b75..df515f70e93 100644 --- a/plugins/woocommerce-admin/client/task-lists/setup-task-list/setup-task-list.tsx +++ b/plugins/woocommerce-admin/client/task-lists/setup-task-list/setup-task-list.tsx @@ -200,6 +200,10 @@ export const SetupTaskList: React.FC< TaskListProps > = ( { recordEvent( `${ listEventPrefix }click`, { task_name: task.id, context: layoutString, + ...( task?.additionalData?.wooPaymentsIncentiveId && { + woopayments_incentive_id: + task.additionalData.wooPaymentsIncentiveId, + } ), } ); }; diff --git a/plugins/woocommerce/changelog/update-51103-woopayments-incentive-to-tracks-props b/plugins/woocommerce/changelog/update-51103-woopayments-incentive-to-tracks-props new file mode 100644 index 00000000000..3a20bc5b0f6 --- /dev/null +++ b/plugins/woocommerce/changelog/update-51103-woopayments-incentive-to-tracks-props @@ -0,0 +1,5 @@ +Significance: patch +Type: tweak +Comment: If there is a WooPayments incentive active, attach its ID to the wcadmin_tasklist_click Tracks event. + + diff --git a/plugins/woocommerce/src/Admin/API/Plugins.php b/plugins/woocommerce/src/Admin/API/Plugins.php index f8b3e43150f..6fa02a01bab 100644 --- a/plugins/woocommerce/src/Admin/API/Plugins.php +++ b/plugins/woocommerce/src/Admin/API/Plugins.php @@ -592,9 +592,9 @@ class Plugins extends \WC_REST_Data_Controller { } /** - * Returns a URL that can be used to by WCPay to verify business details. + * Returns a URL that can be used by WooPayments to verify business details. * - * @return WP_Error|array Connect URL. + * @return \WP_Error|array Connect URL. */ public function connect_wcpay() { if ( ! class_exists( 'WC_Payments' ) ) { diff --git a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/WooCommercePayments.php b/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/WooCommercePayments.php index 5c6d45255f6..64f7cf1b4e7 100644 --- a/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/WooCommercePayments.php +++ b/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks/WooCommercePayments.php @@ -6,7 +6,6 @@ use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task; use Automattic\WooCommerce\Admin\PluginsHelper; use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\Init as Suggestions; -use Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init as WCPayPromotionInit; use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\DefaultPaymentGateways; /** @@ -65,6 +64,22 @@ class WooCommercePayments extends Task { ); } + /** + * Additional data. + * + * @return mixed + */ + public function get_additional_data() { + /** + * Filter WooPayments onboarding task additional data. + * + * @since 9.4.0 + * + * @param ?array $additional_data The task additional data. + */ + return apply_filters( 'woocommerce_admin_woopayments_onboarding_task_additional_data', null ); + } + /** * Time. * diff --git a/plugins/woocommerce/src/Internal/Admin/WcPayWelcomePage.php b/plugins/woocommerce/src/Internal/Admin/WcPayWelcomePage.php index 0815e1b4f8a..446c336d9b1 100644 --- a/plugins/woocommerce/src/Internal/Admin/WcPayWelcomePage.php +++ b/plugins/woocommerce/src/Internal/Admin/WcPayWelcomePage.php @@ -43,10 +43,11 @@ class WcPayWelcomePage { * WCPayWelcomePage constructor. */ public function __construct() { - add_action( 'admin_menu', [ $this, 'register_payments_welcome_page' ] ); - add_filter( 'woocommerce_admin_shared_settings', [ $this, 'shared_settings' ] ); - add_filter( 'woocommerce_admin_allowed_promo_notes', [ $this, 'allowed_promo_notes' ] ); - add_filter( 'woocommerce_admin_woopayments_onboarding_task_badge', [ $this, 'onboarding_task_badge' ] ); + add_action( 'admin_menu', array( $this, 'register_payments_welcome_page' ) ); + add_filter( 'woocommerce_admin_shared_settings', array( $this, 'shared_settings' ) ); + add_filter( 'woocommerce_admin_allowed_promo_notes', array( $this, 'allowed_promo_notes' ) ); + add_filter( 'woocommerce_admin_woopayments_onboarding_task_badge', array( $this, 'onboarding_task_badge' ) ); + add_filter( 'woocommerce_admin_woopayments_onboarding_task_additional_data', array( $this, 'onboarding_task_additional_data' ) ); } /** @@ -211,6 +212,30 @@ class WcPayWelcomePage { return $this->get_incentive()['task_badge'] ?? $badge; } + /** + * Filter the onboarding task additional data to add the WooPayments incentive data to it. + * + * @param ?array $additional_data The current task additional data. + * + * @return ?array The filtered task additional data. + */ + public function onboarding_task_additional_data( ?array $additional_data ): ?array { + // Return early if the incentive must not be visible. + if ( ! $this->must_be_visible() ) { + return $additional_data; + } + + // If we have an incentive, add the incentive ID to the additional data. + if ( $this->get_incentive()['id'] ) { + if ( empty( $additional_data ) ) { + $additional_data = array(); + } + $additional_data['wooPaymentsIncentiveId'] = $this->get_incentive()['id']; + } + + return $additional_data; + } + /** * Check if the WooPayments payment gateway is active and set up or was at some point, * or there are orders processed with it, at some moment.