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
This commit is contained in:
Vlad Olaru 2024-09-09 18:06:43 +03:00 committed by GitHub
parent 0e8d19d43b
commit b40c4a95e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 62 additions and 8 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Add wooPaymentsIncentiveId to the TaskType additionalData.

View File

@ -35,6 +35,7 @@ export type TaskType = {
stripeTaxActivated?: boolean;
woocommerceTaxActivated?: boolean;
woocommerceShippingActivated?: boolean;
wooPaymentsIncentiveId?: string;
};
// Possibly added in DeprecatedTasks.mergeDeprecatedCallbackFunctions
isDeprecated?: boolean;

View File

@ -17,7 +17,7 @@ jest.mock( '@wordpress/data', () => ( {
const fakeTask: {
additionalData: {
[ key: string ]: boolean | string[];
[ key: string ]: boolean | string | string[];
};
} = {
additionalData: {},

View File

@ -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,
} ),
} );
};

View File

@ -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.

View File

@ -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' ) ) {

View File

@ -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.
*

View File

@ -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.