Update WCPay Tracks events props (#48901)

* Add path and source props to incentive CTA clicked Tracks event

* Minor inline docs fixes

* Fix wording mistake

* Add from param to Payments settings CTA URL

* Add from param to incentive CTA URL

* refact: Clearer logic for incentive page tracking

* Add changelog

* Fix incentives page tests
This commit is contained in:
Vlad Olaru 2024-07-02 18:45:27 +03:00 committed by GitHub
parent d4438a8833
commit b5cf9826d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 49 additions and 11 deletions

View File

@ -37,10 +37,29 @@ const ConnectAccountPage = () => {
'admin.php?wcpay-connect=1&promo=' + 'admin.php?wcpay-connect=1&promo=' +
encodeURIComponent( incentive.id ) + encodeURIComponent( incentive.id ) +
'&_wpnonce=' + '&_wpnonce=' +
getAdminSetting( 'wcpay_welcome_page_connect_nonce' ), getAdminSetting( 'wcpay_welcome_page_connect_nonce' ) +
'&from=WCADMIN_PAYMENT_INCENTIVE',
}; };
} ); } );
const determineTrackingSource = () => {
const urlParams = new URLSearchParams( window.location.search );
const from = urlParams.get( 'from' ) || '';
// Determine where the user came from.
let source = 'wcadmin';
switch ( from ) {
case 'WCADMIN_PAYMENT_TASK':
source = 'wcadmin-payment-task';
break;
case 'WCADMIN_PAYMENT_SETTINGS':
source = 'wcadmin-settings-page';
break;
}
return source;
};
/** /**
* Record page view and save viewed timestamp. * Record page view and save viewed timestamp.
*/ */
@ -48,6 +67,7 @@ const ConnectAccountPage = () => {
recordEvent( 'page_view', { recordEvent( 'page_view', {
path: 'payments_connect_core_test', path: 'payments_connect_core_test',
incentive_id: incentive.id, incentive_id: incentive.id,
source: determineTrackingSource(),
} ); } );
updateOptions( { updateOptions( {
wcpay_welcome_page_viewed_timestamp: Math.floor( wcpay_welcome_page_viewed_timestamp: Math.floor(
@ -68,12 +88,19 @@ const ConnectAccountPage = () => {
} }
}; };
const handleSetup = async () => { const trackConnectAccountClicked = () => {
setSubmitted( true );
recordEvent( 'wcpay_connect_account_clicked', { recordEvent( 'wcpay_connect_account_clicked', {
wpcom_connection: isJetpackConnected ? 'Yes' : 'No', wpcom_connection: isJetpackConnected ? 'Yes' : 'No',
incentive_id: incentive.id, incentive_id: incentive.id,
path: 'payments_connect_core_test',
source: determineTrackingSource(),
} ); } );
};
const handleSetup = async () => {
setSubmitted( true );
trackConnectAccountClicked();
const pluginsToInstall = [ ...enabledApms ].map( const pluginsToInstall = [ ...enabledApms ].map(
( apm ) => apm.extension ( apm ) => apm.extension

View File

@ -61,6 +61,7 @@ describe( 'Connect Account Page', () => {
expect( recordEvent ).toHaveBeenCalledWith( 'page_view', { expect( recordEvent ).toHaveBeenCalledWith( 'page_view', {
path: 'payments_connect_core_test', path: 'payments_connect_core_test',
incentive_id: 'incentiveId', incentive_id: 'incentiveId',
source: 'wcadmin',
} ); } );
} ); } );
@ -73,6 +74,8 @@ describe( 'Connect Account Page', () => {
{ {
wpcom_connection: 'Yes', wpcom_connection: 'Yes',
incentive_id: 'incentiveId', incentive_id: 'incentiveId',
path: 'payments_connect_core_test',
source: 'wcadmin',
} }
); );
} ); } );

View File

@ -31,7 +31,7 @@ export const Suggestion = ( { paymentGateway, onSetupCallback = null } ) => {
const isWooPayEligible = getAdminSetting( 'isWooPayEligible' ); const isWooPayEligible = getAdminSetting( 'isWooPayEligible' );
const { createNotice } = useDispatch( 'core/notices' ); const { createNotice } = useDispatch( 'core/notices' );
// When the WC Pay is installed and onSetupCallback is null // When WCPay is installed and onSetupCallback is null
// Overwrite onSetupCallback to redirect to the setup page // Overwrite onSetupCallback to redirect to the setup page
// when the user clicks on the "Finish setup" button. // when the user clicks on the "Finish setup" button.
// WCPay doesn't need to be configured in WCA. // WCPay doesn't need to be configured in WCA.

View File

@ -30,7 +30,7 @@ const WoocommercePaymentsTaskItem = () => {
} ) => JSX.Element; } ) => JSX.Element;
} ) => ( } ) => (
<DefaultTaskItem <DefaultTaskItem
// intercept the click on the task list item so that we don't have to see a intermediate page before installing woocommerce payments // Intercept the click on the task list item so that we don't have to see an intermediate page before installing WooPayments.
onClick={ () => { onClick={ () => {
return new Promise( ( resolve, reject ) => { return new Promise( ( resolve, reject ) => {
return installActivateAndConnectWcpay( return installActivateAndConnectWcpay(

View File

@ -0,0 +1,5 @@
Significance: patch
Type: tweak
Comment: Minor updates to WooPayments incentives page tracking props.

View File

@ -189,7 +189,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
break; break;
case 'action': case 'action':
$setup_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . strtolower( $gateway->id ) ); $setup_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . strtolower( $gateway->id ) );
// Override the behaviour for WooPayments plugin. // Override the behaviour for the WooPayments plugin.
if ( if (
// Keep old brand name for backwards compatibility. // Keep old brand name for backwards compatibility.
( 'WooCommerce Payments' === $method_title || 'WooPayments' === $method_title ) && ( 'WooCommerce Payments' === $method_title || 'WooPayments' === $method_title ) &&
@ -197,7 +197,10 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
) { ) {
if ( ! WooCommercePayments::is_connected() || WooCommercePayments::is_account_partially_onboarded() ) { if ( ! WooCommercePayments::is_connected() || WooCommercePayments::is_account_partially_onboarded() ) {
// The CTA text and label is "Finish setup" if the account is not connected or not completely onboarded. // The CTA text and label is "Finish setup" if the account is not connected or not completely onboarded.
$setup_url = WC_Payments_Account::get_connect_url(); // Plugin will handle the redirection to the connect page or directly to the provider (e.g. Stripe). // Plugin will handle the redirection to the connect page or directly to the provider (e.g. Stripe).
$setup_url = WC_Payments_Account::get_connect_url();
// Add the `from` parameter to the URL, so we know where the user came from.
$setup_url = add_query_arg( 'from', 'WCADMIN_PAYMENT_SETTINGS', $setup_url );
/* Translators: %s Payment gateway name. */ /* Translators: %s Payment gateway name. */
echo '<a class="button alignright" aria-label="' . esc_attr( sprintf( __( 'Set up the "%s" payment method', 'woocommerce' ), $method_title ) ) . '" href="' . esc_url( $setup_url ) . '">' . esc_html__( 'Finish setup', 'woocommerce' ) . '</a>'; echo '<a class="button alignright" aria-label="' . esc_attr( sprintf( __( 'Set up the "%s" payment method', 'woocommerce' ), $method_title ) ) . '" href="' . esc_url( $setup_url ) . '">' . esc_html__( 'Finish setup', 'woocommerce' ) . '</a>';
} else { } else {