woocommerce/plugins/woocommerce-admin/client/wp-admin-scripts/add-term-tracking/index.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { recordEvent } from '@woocommerce/tracks';
const addNewTag = document.querySelector( '#addtag #submit' );
function actionButtonEventHandler( event ) {
const actionClass = event.target.parentElement.classList[ 0 ];
const actions = {
edit: 'edit',
inline: 'quick_edit',
delete: 'delete',
view: 'preview',
};
if ( ! actions[ actionClass ] ) {
return;
}
recordEvent( 'product_attributes_term_list_action_click', {
selected_action: actions[ actionClass ],
} );
}
function addActionButtonListeners() {
const actionButtons = document.querySelectorAll( '.row-actions span' );
actionButtons.forEach( ( button ) => {
button.removeEventListener( 'click', actionButtonEventHandler );
button.addEventListener( 'click', actionButtonEventHandler );
} );
}
addActionButtonListeners();
addNewTag?.addEventListener( 'click', function () {
recordEvent( 'product_attributes_add_term', {
page: 'tags',
} );
setTimeout( () => {
addActionButtonListeners();
}, 1000 );
} );