Add missing Tracks events to attribute modals (#40517)

* Add tracks events

* Add remove icon recording

* Add tracking to new product modal

* Add changelog

* Remove not used `recordEvent`
This commit is contained in:
Fernando Marichal 2023-10-03 08:26:39 -03:00 committed by GitHub
parent 07a178760f
commit e224445bf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 17 deletions

View file

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Add missing Tracks events to attribute modals #40517

View file

@ -14,6 +14,7 @@ import {
ProductAttribute, ProductAttribute,
useUserPreferences, useUserPreferences,
} from '@woocommerce/data'; } from '@woocommerce/data';
import { recordEvent } from '@woocommerce/tracks';
import { Link } from '@woocommerce/components'; import { Link } from '@woocommerce/components';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore No types for this exist yet. // @ts-ignore No types for this exist yet.
@ -113,6 +114,9 @@ export function Edit( {
attributes, attributes,
entityDefaultAttributes, entityDefaultAttributes,
] ) } ] ) }
onAdd={ () => {
recordEvent( 'product_options_modal_add_button_click' );
} }
onChange={ handleChange } onChange={ handleChange }
createNewAttributesAsGlobal={ true } createNewAttributesAsGlobal={ true }
useRemoveConfirmationModal={ true } useRemoveConfirmationModal={ true }
@ -121,6 +125,32 @@ export function Edit( {
product_block_variable_options_notice_dismissed: 'yes', product_block_variable_options_notice_dismissed: 'yes',
} ) } )
} }
onAddAnother={ () => {
recordEvent(
'product_add_options_modal_add_another_option_button_click'
);
} }
onNewModalCancel={ () => {
recordEvent( 'product_options_modal_cancel_button_click' );
} }
onNewModalOpen={ () => {
recordEvent( 'product_options_add_option' );
} }
onRemoveItem={ () => {
recordEvent(
'product_add_options_modal_remove_option_button_click'
);
} }
onRemove={ () =>
recordEvent(
'product_remove_option_confirmation_confirm_click'
)
}
onRemoveCancel={ () =>
recordEvent(
'product_remove_option_confirmation_cancel_click'
)
}
disabledAttributeIds={ entityAttributes disabledAttributeIds={ entityAttributes
.filter( ( attr ) => ! attr.variation ) .filter( ( attr ) => ! attr.variation )
.map( ( attr ) => attr.id ) } .map( ( attr ) => attr.id ) }

View file

@ -79,6 +79,7 @@ export function Edit( {
const openNewModal = () => { const openNewModal = () => {
setIsNewModalVisible( true ); setIsNewModalVisible( true );
recordEvent( 'product_options_add_first_option' );
}; };
const closeNewModal = () => { const closeNewModal = () => {
@ -133,9 +134,22 @@ export function Edit( {
createNewAttributesAsGlobal={ true } createNewAttributesAsGlobal={ true }
notice={ '' } notice={ '' }
onCancel={ () => { onCancel={ () => {
recordEvent(
'product_options_modal_cancel_button_click'
);
closeNewModal(); closeNewModal();
} } } }
onAdd={ handleAdd } onAdd={ handleAdd }
onAddAnother={ () => {
recordEvent(
'product_add_options_modal_add_another_option_button_click'
);
} }
onRemoveItem={ () => {
recordEvent(
'product_add_options_modal_remove_option_button_click'
);
} }
selectedAttributeIds={ variationOptions.map( selectedAttributeIds={ variationOptions.map(
( attr ) => attr.id ( attr ) => attr.id
) } ) }

View file

@ -36,6 +36,8 @@ import { TRACKS_SOURCE } from '../../constants';
type AttributeControlProps = { type AttributeControlProps = {
value: EnhancedProductAttribute[]; value: EnhancedProductAttribute[];
onAdd?: ( attribute: EnhancedProductAttribute[] ) => void; onAdd?: ( attribute: EnhancedProductAttribute[] ) => void;
onAddAnother?: () => void;
onRemoveItem?: () => void;
onChange: ( value: ProductAttribute[] ) => void; onChange: ( value: ProductAttribute[] ) => void;
onEdit?: ( attribute: ProductAttribute ) => void; onEdit?: ( attribute: ProductAttribute ) => void;
onRemove?: ( attribute: ProductAttribute ) => void; onRemove?: ( attribute: ProductAttribute ) => void;
@ -71,6 +73,8 @@ type AttributeControlProps = {
export const AttributeControl: React.FC< AttributeControlProps > = ( { export const AttributeControl: React.FC< AttributeControlProps > = ( {
value, value,
onAdd = () => {}, onAdd = () => {},
onAddAnother = () => {},
onRemoveItem = () => {},
onChange, onChange,
onEdit = () => {}, onEdit = () => {},
onNewModalCancel = () => {}, onNewModalCancel = () => {},
@ -183,13 +187,6 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
getAttributeId( newAttr ) === getAttributeId( current ) getAttributeId( newAttr ) === getAttributeId( current )
) )
); );
recordEvent( 'product_options_add', {
source: TRACKS_SOURCE,
options: addedAttributesOnly.map( ( attribute ) => ( {
attribute: attribute.name,
values: attribute.options,
} ) ),
} );
handleChange( [ ...value, ...addedAttributesOnly ] ); handleChange( [ ...value, ...addedAttributesOnly ] );
onAdd( newAttributes ); onAdd( newAttributes );
closeNewModal(); closeNewModal();
@ -244,9 +241,6 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
className="woocommerce-add-attribute-list-item__add-button" className="woocommerce-add-attribute-list-item__add-button"
onClick={ () => { onClick={ () => {
openNewModal(); openNewModal();
recordEvent( 'product_options_add_button_click', {
source: TRACKS_SOURCE,
} );
} } } }
> >
{ uiStrings.newAttributeListItemLabel } { uiStrings.newAttributeListItemLabel }
@ -305,6 +299,8 @@ export const AttributeControl: React.FC< AttributeControlProps > = ( {
onNewModalCancel(); onNewModalCancel();
} } } }
onAdd={ handleAdd } onAdd={ handleAdd }
onAddAnother={ onAddAnother }
onRemoveItem={ onRemoveItem }
selectedAttributeIds={ value.map( ( attr ) => attr.id ) } selectedAttributeIds={ value.map( ( attr ) => attr.id ) }
createNewAttributesAsGlobal={ createNewAttributesAsGlobal } createNewAttributesAsGlobal={ createNewAttributesAsGlobal }
disabledAttributeIds={ disabledAttributeIds } disabledAttributeIds={ disabledAttributeIds }

View file

@ -14,7 +14,6 @@ import {
ProductAttribute, ProductAttribute,
ProductAttributeTerm, ProductAttributeTerm,
} from '@woocommerce/data'; } from '@woocommerce/data';
import { recordEvent } from '@woocommerce/tracks';
import { Button, Modal, Notice } from '@wordpress/components'; import { Button, Modal, Notice } from '@wordpress/components';
/** /**
@ -44,6 +43,8 @@ type NewAttributeModalProps = {
addLabel?: string; addLabel?: string;
onCancel: () => void; onCancel: () => void;
onAdd: ( newCategories: EnhancedProductAttribute[] ) => void; onAdd: ( newCategories: EnhancedProductAttribute[] ) => void;
onAddAnother?: () => void;
onRemoveItem?: () => void;
selectedAttributeIds?: number[]; selectedAttributeIds?: number[];
createNewAttributesAsGlobal?: boolean; createNewAttributesAsGlobal?: boolean;
disabledAttributeIds?: number[]; disabledAttributeIds?: number[];
@ -75,6 +76,8 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
addLabel = __( 'Add', 'woocommerce' ), addLabel = __( 'Add', 'woocommerce' ),
onCancel, onCancel,
onAdd, onAdd,
onAddAnother = () => {},
onRemoveItem = () => {},
selectedAttributeIds = [], selectedAttributeIds = [],
createNewAttributesAsGlobal = false, createNewAttributesAsGlobal = false,
disabledAttributeIds = [], disabledAttributeIds = [],
@ -102,6 +105,7 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
) => { ) => {
setValue( 'attributes', [ ...values.attributes, null ] ); setValue( 'attributes', [ ...values.attributes, null ] );
scrollAttributeIntoView( values.attributes.length ); scrollAttributeIntoView( values.attributes.length );
onAddAnother();
}; };
const hasTermsOrOptions = ( attribute: EnhancedProductAttribute ) => { const hasTermsOrOptions = ( attribute: EnhancedProductAttribute ) => {
@ -164,9 +168,7 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
value: AttributeForm[ keyof AttributeForm ] value: AttributeForm[ keyof AttributeForm ]
) => void ) => void
) => { ) => {
recordEvent( onRemoveItem();
'product_add_attributes_modal_remove_attribute_button_click'
);
if ( values.attributes.length > 1 ) { if ( values.attributes.length > 1 ) {
setValue( setValue(
'attributes', 'attributes',
@ -465,9 +467,6 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
variant="tertiary" variant="tertiary"
label={ addAnotherAccessibleLabel } label={ addAnotherAccessibleLabel }
onClick={ () => { onClick={ () => {
recordEvent(
'product_add_attributes_modal_add_another_attribute_button_click'
);
addAnother( values, setValue ); addAnother( values, setValue );
} } } }
> >

View file

@ -57,6 +57,16 @@ export const Attributes: React.FC< AttributesProps > = ( {
} }
recordEvent( 'product_add_attribute_button' ); recordEvent( 'product_add_attribute_button' );
} } } }
onAddAnother={ () => {
recordEvent(
'product_add_attributes_modal_add_another_attribute_button_click'
);
} }
onRemoveItem={ () => {
recordEvent(
'product_add_attributes_modal_remove_attribute_button_click'
);
} }
onRemove={ () => onRemove={ () =>
recordEvent( recordEvent(
'product_remove_attribute_confirmation_confirm_click' 'product_remove_attribute_confirmation_confirm_click'