Commit 813ea1bff7 for woocommerce

commit 813ea1bff733f861981476f589db501ef6d95e88
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date:   Wed Feb 25 13:35:30 2026 +0300

    [WOOPLUG-6345] Add unified shipping partner Tracks events on settings page (#63437)

    * [WOOPLUG-6345] add: shipping partner Tracks tracking on settings page

    Add unified shipping_partner_* Tracks events to the Shipping settings page:
    - shipping_partner_impression (on page load)
    - shipping_partner_click (on Install/Activate click)
    - shipping_partner_install (success/failure)
    - shipping_partner_activate (success/failure)

    All events include context, country, plugins, and selected_plugin properties.

    * Normalize countryCode once to ensure consistent event payloads

    The impression event used raw countryCode (possibly undefined)
    while trackingProps used countryCode ?? ''. Extract a single
    normalizedCountry variable used everywhere.

diff --git a/plugins/woocommerce/client/admin/client/shipping/experimental-shipping-recommendations.tsx b/plugins/woocommerce/client/admin/client/shipping/experimental-shipping-recommendations.tsx
index ef4bf9d0e2..82cc9ab178 100644
--- a/plugins/woocommerce/client/admin/client/shipping/experimental-shipping-recommendations.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/experimental-shipping-recommendations.tsx
@@ -2,11 +2,13 @@
  * External dependencies
  */
 import { useSelect } from '@wordpress/data';
+import { useEffect, useRef } from '@wordpress/element';
 import {
 	pluginsStore,
 	settingsStore,
 	onboardingStore,
 } from '@woocommerce/data';
+import { recordEvent } from '@woocommerce/tracks';

 /**
  * Internal dependencies
@@ -74,16 +76,37 @@ const ShippingRecommendations = () => {
 		};
 	}, [] );

-	if ( isSellingDigitalProductsOnly ) {
-		return <ShippingTour showShippingRecommendationsStep={ false } />;
-	}
+	const normalizedCountry = countryCode ?? '';

 	const extensionsForCountry =
-		COUNTRY_EXTENSIONS_MAP[ countryCode ?? '' ] ?? [];
+		COUNTRY_EXTENSIONS_MAP[ normalizedCountry ] ?? [];

-	const visibleExtensions = extensionsForCountry.filter(
-		( ext ) => ! activePlugins.includes( EXTENSION_PLUGIN_SLUGS[ ext ] )
-	);
+	const visibleExtensions = isSellingDigitalProductsOnly
+		? []
+		: extensionsForCountry.filter(
+				( ext ) =>
+					! activePlugins.includes( EXTENSION_PLUGIN_SLUGS[ ext ] )
+		  );
+
+	const visiblePluginSlugs = visibleExtensions
+		.map( ( ext ) => EXTENSION_PLUGIN_SLUGS[ ext ] )
+		.join( ',' );
+
+	const impressionFired = useRef( false );
+	useEffect( () => {
+		if ( visibleExtensions.length > 0 && ! impressionFired.current ) {
+			recordEvent( 'shipping_partner_impression', {
+				context: 'settings',
+				country: normalizedCountry,
+				plugins: visiblePluginSlugs,
+			} );
+			impressionFired.current = true;
+		}
+	}, [ visibleExtensions.length, normalizedCountry, visiblePluginSlugs ] );
+
+	if ( isSellingDigitalProductsOnly ) {
+		return <ShippingTour showShippingRecommendationsStep={ false } />;
+	}

 	if ( visibleExtensions.length === 0 ) {
 		return <ShippingTour showShippingRecommendationsStep={ false } />;
@@ -97,6 +120,11 @@ const ShippingRecommendations = () => {
 					const isPluginInstalled = installedPlugins.includes(
 						EXTENSION_PLUGIN_SLUGS[ ext ]
 					);
+					const trackingProps = {
+						context: 'settings' as const,
+						country: normalizedCountry,
+						plugins: visiblePluginSlugs,
+					};
 					switch ( ext ) {
 						case 'woocommerce-shipping':
 							return (
@@ -106,6 +134,7 @@ const ShippingRecommendations = () => {
 									pluginsBeingSetup={ pluginsBeingSetup }
 									onInstallClick={ handleInstall }
 									onActivateClick={ handleActivate }
+									tracking={ trackingProps }
 								/>
 							);
 						case 'shipstation':
@@ -116,6 +145,7 @@ const ShippingRecommendations = () => {
 									pluginsBeingSetup={ pluginsBeingSetup }
 									onInstallClick={ handleInstall }
 									onActivateClick={ handleActivate }
+									tracking={ trackingProps }
 								/>
 							);
 						case 'packlink':
@@ -126,6 +156,7 @@ const ShippingRecommendations = () => {
 									pluginsBeingSetup={ pluginsBeingSetup }
 									onInstallClick={ handleInstall }
 									onActivateClick={ handleActivate }
+									tracking={ trackingProps }
 								/>
 							);
 						default:
diff --git a/plugins/woocommerce/client/admin/client/shipping/experimental-woocommerce-shipping-item.tsx b/plugins/woocommerce/client/admin/client/shipping/experimental-woocommerce-shipping-item.tsx
index d7eb64a22f..5161d45936 100644
--- a/plugins/woocommerce/client/admin/client/shipping/experimental-woocommerce-shipping-item.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/experimental-woocommerce-shipping-item.tsx
@@ -15,27 +15,46 @@ import WooIcon from './woo-icon.svg';

 const WOOCOMMERCE_SHIPPING_PLUGIN_SLUG = 'woocommerce-shipping';

+export type ShippingPartnerTrackingProps = {
+	context: 'settings';
+	country: string;
+	plugins: string;
+};
+
 const WooCommerceShippingItem = ( {
 	isPluginInstalled,
 	onInstallClick,
 	onActivateClick,
 	pluginsBeingSetup,
+	tracking,
 }: {
 	isPluginInstalled: boolean;
 	pluginsBeingSetup: Array< string >;
 	onInstallClick: ( slugs: string[] ) => PromiseLike< void >;
 	onActivateClick: ( slugs: string[] ) => PromiseLike< void >;
+	tracking?: ShippingPartnerTrackingProps;
 } ) => {
 	const { createSuccessNotice } = useDispatch( 'core/notices' );

 	const handleClick = () => {
-		recordEvent( 'settings_shipping_recommendation_setup_click', {
-			plugin: WOOCOMMERCE_SHIPPING_PLUGIN_SLUG,
-			action: isPluginInstalled ? 'activate' : 'install',
-		} );
+		const trackingBase = {
+			...( tracking ?? {} ),
+			selected_plugin: WOOCOMMERCE_SHIPPING_PLUGIN_SLUG,
+		};
+
+		recordEvent( 'shipping_partner_click', trackingBase );
+
 		const action = isPluginInstalled ? onActivateClick : onInstallClick;
+		const eventName = isPluginInstalled
+			? 'shipping_partner_activate'
+			: 'shipping_partner_install';
+
 		action( [ WOOCOMMERCE_SHIPPING_PLUGIN_SLUG ] ).then(
 			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: true,
+				} );
 				createSuccessNotice(
 					isPluginInstalled
 						? __( 'WooCommerce Shipping activated!', 'woocommerce' )
@@ -46,7 +65,12 @@ const WooCommerceShippingItem = ( {
 					{}
 				);
 			},
-			() => {}
+			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: false,
+				} );
+			}
 		);
 	};

diff --git a/plugins/woocommerce/client/admin/client/shipping/packlink-item.tsx b/plugins/woocommerce/client/admin/client/shipping/packlink-item.tsx
index acff31e74b..19f4cd3fd4 100644
--- a/plugins/woocommerce/client/admin/client/shipping/packlink-item.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/packlink-item.tsx
@@ -10,6 +10,7 @@ import { recordEvent } from '@woocommerce/tracks';
  * Internal dependencies
  */
 import './woocommerce-shipping-item.scss';
+import type { ShippingPartnerTrackingProps } from './experimental-woocommerce-shipping-item';

 const PACKLINK_PLUGIN_SLUG = 'packlink-pro-shipping';

@@ -18,22 +19,35 @@ const PacklinkItem = ( {
 	onInstallClick,
 	onActivateClick,
 	pluginsBeingSetup,
+	tracking,
 }: {
 	isPluginInstalled: boolean;
 	pluginsBeingSetup: Array< string >;
 	onInstallClick: ( slugs: string[] ) => PromiseLike< void >;
 	onActivateClick: ( slugs: string[] ) => PromiseLike< void >;
+	tracking?: ShippingPartnerTrackingProps;
 } ) => {
 	const { createSuccessNotice } = useDispatch( 'core/notices' );

 	const handleClick = () => {
-		recordEvent( 'settings_shipping_recommendation_setup_click', {
-			plugin: PACKLINK_PLUGIN_SLUG,
-			action: isPluginInstalled ? 'activate' : 'install',
-		} );
+		const trackingBase = {
+			...( tracking ?? {} ),
+			selected_plugin: PACKLINK_PLUGIN_SLUG,
+		};
+
+		recordEvent( 'shipping_partner_click', trackingBase );
+
 		const action = isPluginInstalled ? onActivateClick : onInstallClick;
+		const eventName = isPluginInstalled
+			? 'shipping_partner_activate'
+			: 'shipping_partner_install';
+
 		action( [ PACKLINK_PLUGIN_SLUG ] ).then(
 			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: true,
+				} );
 				createSuccessNotice(
 					isPluginInstalled
 						? __( 'Packlink PRO activated!', 'woocommerce' )
@@ -41,7 +55,12 @@ const PacklinkItem = ( {
 					{}
 				);
 			},
-			() => {}
+			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: false,
+				} );
+			}
 		);
 	};

diff --git a/plugins/woocommerce/client/admin/client/shipping/shipstation-item.tsx b/plugins/woocommerce/client/admin/client/shipping/shipstation-item.tsx
index 14845b07a4..624ef670cb 100644
--- a/plugins/woocommerce/client/admin/client/shipping/shipstation-item.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/shipstation-item.tsx
@@ -10,6 +10,7 @@ import { recordEvent } from '@woocommerce/tracks';
  * Internal dependencies
  */
 import './woocommerce-shipping-item.scss';
+import type { ShippingPartnerTrackingProps } from './experimental-woocommerce-shipping-item';

 const SHIPSTATION_PLUGIN_SLUG = 'woocommerce-shipstation-integration';

@@ -18,22 +19,35 @@ const ShipStationItem = ( {
 	onInstallClick,
 	onActivateClick,
 	pluginsBeingSetup,
+	tracking,
 }: {
 	isPluginInstalled: boolean;
 	pluginsBeingSetup: Array< string >;
 	onInstallClick: ( slugs: string[] ) => PromiseLike< void >;
 	onActivateClick: ( slugs: string[] ) => PromiseLike< void >;
+	tracking?: ShippingPartnerTrackingProps;
 } ) => {
 	const { createSuccessNotice } = useDispatch( 'core/notices' );

 	const handleClick = () => {
-		recordEvent( 'settings_shipping_recommendation_setup_click', {
-			plugin: SHIPSTATION_PLUGIN_SLUG,
-			action: isPluginInstalled ? 'activate' : 'install',
-		} );
+		const trackingBase = {
+			...( tracking ?? {} ),
+			selected_plugin: SHIPSTATION_PLUGIN_SLUG,
+		};
+
+		recordEvent( 'shipping_partner_click', trackingBase );
+
 		const action = isPluginInstalled ? onActivateClick : onInstallClick;
+		const eventName = isPluginInstalled
+			? 'shipping_partner_activate'
+			: 'shipping_partner_install';
+
 		action( [ SHIPSTATION_PLUGIN_SLUG ] ).then(
 			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: true,
+				} );
 				createSuccessNotice(
 					isPluginInstalled
 						? __( 'ShipStation activated!', 'woocommerce' )
@@ -41,7 +55,12 @@ const ShipStationItem = ( {
 					{}
 				);
 			},
-			() => {}
+			() => {
+				recordEvent( eventName, {
+					...trackingBase,
+					success: false,
+				} );
+			}
 		);
 	};

diff --git a/plugins/woocommerce/client/admin/client/shipping/test/experimental-shipping-recommendations.tsx b/plugins/woocommerce/client/admin/client/shipping/test/experimental-shipping-recommendations.tsx
index 54ada43e5c..d8938ce035 100644
--- a/plugins/woocommerce/client/admin/client/shipping/test/experimental-shipping-recommendations.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/test/experimental-shipping-recommendations.tsx
@@ -261,6 +261,68 @@ describe( 'ShippingRecommendations', () => {
 		} );
 	} );

+	describe( 'impression tracking', () => {
+		it( 'should fire shipping_partner_impression on mount for US', () => {
+			mockSelectForCountry( 'US' );
+			render( <ShippingRecommendations /> );
+
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_impression',
+				{
+					context: 'settings',
+					country: 'US',
+					plugins:
+						'woocommerce-shipping,woocommerce-shipstation-integration',
+				}
+			);
+		} );
+
+		it( 'should fire shipping_partner_impression with correct plugins for DE', () => {
+			( recordEvent as jest.Mock ).mockClear();
+			mockSelectForCountry( 'DE' );
+			render( <ShippingRecommendations /> );
+
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_impression',
+				{
+					context: 'settings',
+					country: 'DE',
+					plugins:
+						'woocommerce-shipstation-integration,packlink-pro-shipping',
+				}
+			);
+		} );
+
+		it( 'should not fire shipping_partner_impression for unsupported countries', () => {
+			( recordEvent as jest.Mock ).mockClear();
+			mockSelectForCountry( 'JP' );
+			render( <ShippingRecommendations /> );
+
+			expect( recordEvent ).not.toHaveBeenCalledWith(
+				'shipping_partner_impression',
+				expect.anything()
+			);
+		} );
+
+		it( 'should not fire shipping_partner_impression when selling digital products only', () => {
+			( recordEvent as jest.Mock ).mockClear();
+			( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
+				fn( () => ( {
+					...defaultSelectReturn,
+					getProfileItems: () => ( {
+						product_types: [ 'downloads' ],
+					} ),
+				} ) )
+			);
+			render( <ShippingRecommendations /> );
+
+			expect( recordEvent ).not.toHaveBeenCalledWith(
+				'shipping_partner_impression',
+				expect.anything()
+			);
+		} );
+	} );
+
 	describe( 'WooCommerce Shipping item', () => {
 		it( 'should render WC Shipping when not installed', () => {
 			render( <ShippingRecommendations /> );
@@ -333,10 +395,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Install' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'woocommerce-shipping',
-					action: 'install',
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
 				}
 			);
 			expect( installPluginsMock ).toHaveBeenCalledWith( [
@@ -367,10 +431,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Install' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'woocommerce-shipstation-integration',
-					action: 'install',
+					context: 'settings',
+					country: 'CA',
+					plugins: 'woocommerce-shipstation-integration',
+					selected_plugin: 'woocommerce-shipstation-integration',
 				}
 			);
 			expect( installPluginsMock ).toHaveBeenCalledWith( [
@@ -401,10 +467,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Install' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'packlink-pro-shipping',
-					action: 'install',
+					context: 'settings',
+					country: 'FR',
+					plugins: 'packlink-pro-shipping',
+					selected_plugin: 'packlink-pro-shipping',
 				}
 			);
 			expect( installPluginsMock ).toHaveBeenCalledWith( [
@@ -419,6 +487,144 @@ describe( 'ShippingRecommendations', () => {
 		} );
 	} );

+	describe( 'install result tracking', () => {
+		it( 'should fire shipping_partner_install with success on successful install', async () => {
+			( recordEvent as jest.Mock ).mockClear();
+			const installPluginsMock = jest.fn().mockResolvedValue( undefined );
+			( useDispatch as jest.Mock ).mockReturnValue( {
+				installAndActivatePlugins: jest
+					.fn()
+					.mockResolvedValue( undefined ),
+				installPlugins: installPluginsMock,
+				activatePlugins: jest.fn().mockResolvedValue( undefined ),
+				createSuccessNotice: jest.fn(),
+			} );
+			mockSelectForCountry( 'CA' );
+			render( <ShippingRecommendations /> );
+
+			userEvent.click( screen.getByText( 'Install' ) );
+
+			await waitFor( () => {
+				expect( recordEvent ).toHaveBeenCalledWith(
+					'shipping_partner_install',
+					{
+						context: 'settings',
+						country: 'CA',
+						plugins: 'woocommerce-shipstation-integration',
+						selected_plugin: 'woocommerce-shipstation-integration',
+						success: true,
+					}
+				);
+			} );
+		} );
+
+		it( 'should fire shipping_partner_install with failure on failed install', async () => {
+			( recordEvent as jest.Mock ).mockClear();
+			const installPluginsMock = jest.fn().mockRejectedValue( {
+				errors: { plugin: 'Install failed' },
+			} );
+			( useDispatch as jest.Mock ).mockReturnValue( {
+				installAndActivatePlugins: jest
+					.fn()
+					.mockResolvedValue( undefined ),
+				installPlugins: installPluginsMock,
+				activatePlugins: jest.fn().mockResolvedValue( undefined ),
+				createSuccessNotice: jest.fn(),
+			} );
+			mockSelectForCountry( 'CA' );
+			render( <ShippingRecommendations /> );
+
+			userEvent.click( screen.getByText( 'Install' ) );
+
+			await waitFor( () => {
+				expect( recordEvent ).toHaveBeenCalledWith(
+					'shipping_partner_install',
+					{
+						context: 'settings',
+						country: 'CA',
+						plugins: 'woocommerce-shipstation-integration',
+						selected_plugin: 'woocommerce-shipstation-integration',
+						success: false,
+					}
+				);
+			} );
+		} );
+	} );
+
+	describe( 'activate result tracking', () => {
+		it( 'should fire shipping_partner_activate with success on successful activation', async () => {
+			( recordEvent as jest.Mock ).mockClear();
+			const activatePluginsMock = jest
+				.fn()
+				.mockResolvedValue( undefined );
+			( useDispatch as jest.Mock ).mockReturnValue( {
+				installAndActivatePlugins: jest
+					.fn()
+					.mockResolvedValue( undefined ),
+				installPlugins: jest.fn().mockResolvedValue( undefined ),
+				activatePlugins: activatePluginsMock,
+				createSuccessNotice: jest.fn(),
+			} );
+			mockSelectForCountry( 'CA', [], {
+				getInstalledPlugins: () => [
+					'woocommerce-shipstation-integration',
+				],
+			} );
+			render( <ShippingRecommendations /> );
+
+			userEvent.click( screen.getByText( 'Activate' ) );
+
+			await waitFor( () => {
+				expect( recordEvent ).toHaveBeenCalledWith(
+					'shipping_partner_activate',
+					{
+						context: 'settings',
+						country: 'CA',
+						plugins: 'woocommerce-shipstation-integration',
+						selected_plugin: 'woocommerce-shipstation-integration',
+						success: true,
+					}
+				);
+			} );
+		} );
+
+		it( 'should fire shipping_partner_activate with failure on failed activation', async () => {
+			( recordEvent as jest.Mock ).mockClear();
+			const activatePluginsMock = jest.fn().mockRejectedValue( {
+				errors: { plugin: 'Activate failed' },
+			} );
+			( useDispatch as jest.Mock ).mockReturnValue( {
+				installAndActivatePlugins: jest
+					.fn()
+					.mockResolvedValue( undefined ),
+				installPlugins: jest.fn().mockResolvedValue( undefined ),
+				activatePlugins: activatePluginsMock,
+				createSuccessNotice: jest.fn(),
+			} );
+			mockSelectForCountry( 'CA', [], {
+				getInstalledPlugins: () => [
+					'woocommerce-shipstation-integration',
+				],
+			} );
+			render( <ShippingRecommendations /> );
+
+			userEvent.click( screen.getByText( 'Activate' ) );
+
+			await waitFor( () => {
+				expect( recordEvent ).toHaveBeenCalledWith(
+					'shipping_partner_activate',
+					{
+						context: 'settings',
+						country: 'CA',
+						plugins: 'woocommerce-shipstation-integration',
+						selected_plugin: 'woocommerce-shipstation-integration',
+						success: false,
+					}
+				);
+			} );
+		} );
+	} );
+
 	describe( 'plugin activation (installed but not active)', () => {
 		it( 'shows Activate button for WooCommerce Shipping when installed but not active', () => {
 			mockSelectForCountry( 'US', [], {
@@ -480,10 +686,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Activate' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'woocommerce-shipping',
-					action: 'activate',
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
 				}
 			);
 			expect( activatePluginsMock ).toHaveBeenCalledWith( [
@@ -520,10 +728,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Activate' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'woocommerce-shipstation-integration',
-					action: 'activate',
+					context: 'settings',
+					country: 'CA',
+					plugins: 'woocommerce-shipstation-integration',
+					selected_plugin: 'woocommerce-shipstation-integration',
 				}
 			);
 			expect( activatePluginsMock ).toHaveBeenCalledWith( [
@@ -558,10 +768,12 @@ describe( 'ShippingRecommendations', () => {
 			userEvent.click( screen.getByText( 'Activate' ) );

 			expect( recordEvent ).toHaveBeenCalledWith(
-				'settings_shipping_recommendation_setup_click',
+				'shipping_partner_click',
 				{
-					plugin: 'packlink-pro-shipping',
-					action: 'activate',
+					context: 'settings',
+					country: 'FR',
+					plugins: 'packlink-pro-shipping',
+					selected_plugin: 'packlink-pro-shipping',
 				}
 			);
 			expect( activatePluginsMock ).toHaveBeenCalledWith( [
diff --git a/plugins/woocommerce/client/admin/client/shipping/test/experimental-woocommerce-shipping-item.tsx b/plugins/woocommerce/client/admin/client/shipping/test/experimental-woocommerce-shipping-item.tsx
index 21da32cc5f..6616a22649 100644
--- a/plugins/woocommerce/client/admin/client/shipping/test/experimental-woocommerce-shipping-item.tsx
+++ b/plugins/woocommerce/client/admin/client/shipping/test/experimental-woocommerce-shipping-item.tsx
@@ -1,7 +1,7 @@
 /**
  * External dependencies
  */
-import { render, screen } from '@testing-library/react';
+import { render, screen, waitFor } from '@testing-library/react';
 import { useDispatch } from '@wordpress/data';
 import { recordEvent } from '@woocommerce/tracks';

@@ -96,40 +96,48 @@ describe( 'WooCommerceShippingItem', () => {
 		] );
 	} );

-	it( 'should record track when clicking Install button', () => {
+	it( 'should record shipping_partner_click when clicking Install button', () => {
 		render(
 			<WooCommerceShippingItem
 				isPluginInstalled={ false }
 				{ ...defaultProps }
+				tracking={ {
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+				} }
 			/>
 		);

 		screen.queryByRole( 'button', { name: 'Install' } )?.click();
-		expect( recordEvent ).toHaveBeenCalledWith(
-			'settings_shipping_recommendation_setup_click',
-			{
-				plugin: 'woocommerce-shipping',
-				action: 'install',
-			}
-		);
+		expect( recordEvent ).toHaveBeenCalledWith( 'shipping_partner_click', {
+			context: 'settings',
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+			selected_plugin: 'woocommerce-shipping',
+		} );
 	} );

-	it( 'should record track when clicking Activate button', () => {
+	it( 'should record shipping_partner_click when clicking Activate button', () => {
 		render(
 			<WooCommerceShippingItem
 				isPluginInstalled={ true }
 				{ ...defaultProps }
+				tracking={ {
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+				} }
 			/>
 		);

 		screen.queryByRole( 'button', { name: 'Activate' } )?.click();
-		expect( recordEvent ).toHaveBeenCalledWith(
-			'settings_shipping_recommendation_setup_click',
-			{
-				plugin: 'woocommerce-shipping',
-				action: 'activate',
-			}
-		);
+		expect( recordEvent ).toHaveBeenCalledWith( 'shipping_partner_click', {
+			context: 'settings',
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+			selected_plugin: 'woocommerce-shipping',
+		} );
 	} );

 	it( 'should call onActivateClick when clicking Activate button', () => {
@@ -148,4 +156,128 @@ describe( 'WooCommerceShippingItem', () => {
 			'woocommerce-shipping',
 		] );
 	} );
+
+	it( 'should record shipping_partner_install with success on successful install', async () => {
+		const tracking = {
+			context: 'settings' as const,
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+		};
+		render(
+			<WooCommerceShippingItem
+				isPluginInstalled={ false }
+				{ ...defaultProps }
+				onInstallClick={ jest.fn( () => Promise.resolve() ) }
+				tracking={ tracking }
+			/>
+		);
+
+		screen.queryByRole( 'button', { name: 'Install' } )?.click();
+
+		await waitFor( () => {
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_install',
+				{
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
+					success: true,
+				}
+			);
+		} );
+	} );
+
+	it( 'should record shipping_partner_install with failure on failed install', async () => {
+		const tracking = {
+			context: 'settings' as const,
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+		};
+		render(
+			<WooCommerceShippingItem
+				isPluginInstalled={ false }
+				{ ...defaultProps }
+				onInstallClick={ jest.fn( () => Promise.reject() ) }
+				tracking={ tracking }
+			/>
+		);
+
+		screen.queryByRole( 'button', { name: 'Install' } )?.click();
+
+		await waitFor( () => {
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_install',
+				{
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
+					success: false,
+				}
+			);
+		} );
+	} );
+
+	it( 'should record shipping_partner_activate with success on successful activation', async () => {
+		const tracking = {
+			context: 'settings' as const,
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+		};
+		render(
+			<WooCommerceShippingItem
+				isPluginInstalled={ true }
+				{ ...defaultProps }
+				onActivateClick={ jest.fn( () => Promise.resolve() ) }
+				tracking={ tracking }
+			/>
+		);
+
+		screen.queryByRole( 'button', { name: 'Activate' } )?.click();
+
+		await waitFor( () => {
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_activate',
+				{
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
+					success: true,
+				}
+			);
+		} );
+	} );
+
+	it( 'should record shipping_partner_activate with failure on failed activation', async () => {
+		const tracking = {
+			context: 'settings' as const,
+			country: 'US',
+			plugins: 'woocommerce-shipping',
+		};
+		render(
+			<WooCommerceShippingItem
+				isPluginInstalled={ true }
+				{ ...defaultProps }
+				onActivateClick={ jest.fn( () => Promise.reject() ) }
+				tracking={ tracking }
+			/>
+		);
+
+		screen.queryByRole( 'button', { name: 'Activate' } )?.click();
+
+		await waitFor( () => {
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'shipping_partner_activate',
+				{
+					context: 'settings',
+					country: 'US',
+					plugins: 'woocommerce-shipping',
+					selected_plugin: 'woocommerce-shipping',
+					success: false,
+				}
+			);
+		} );
+	} );
 } );