Add additional global attributes and local attributes information when saving product attributes (#36858)

* Add additional global attributes and local attributes information when saving product attributes

* Log only local attributes
Add attribute name
Fix issue with attribute_value and names selectors

* Save name and slug for global attributes and global terms
This commit is contained in:
Nathan Silveira 2023-02-20 19:55:01 -03:00 committed by GitHub
parent 48c8db8ade
commit 41eab0d669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View File

@ -34,8 +34,12 @@ function addActionButtonListeners() {
addActionButtonListeners();
addNewTag?.addEventListener( 'click', function () {
const name = document.querySelector( '#tag-name' );
const slug = document.querySelector( '#tag-slug' );
recordEvent( 'product_attributes_add_term', {
page: 'tags',
name: name?.value,
slug: slug?.value,
} );
setTimeout( () => {
addActionButtonListeners();

View File

@ -11,9 +11,13 @@ const configureTerms = document.querySelectorAll( '.configure-terms' );
addNewAttribute?.addEventListener( 'click', function () {
const archiveInput = document.querySelector( '#attribute_public' );
const sortOrder = document.querySelector( '#attribute_orderby' );
const name = document.querySelector( '#attribute_label' );
const slug = document.querySelector( '#attribute_name' );
recordEvent( 'product_attributes_add', {
enable_archive: archiveInput?.checked ? 'yes' : 'no',
default_sort_order: sortOrder?.value,
name: name?.value,
slug: slug?.value,
page: 'attributes',
} );
} );

View File

@ -418,10 +418,31 @@ export const initProductScreenTracks = () => {
'.woocommerce_attribute'
).length;
if ( newAttributesCount > attributesCount ) {
const local_attributes = [
...document.querySelectorAll(
'.woocommerce_attribute:not(.pa_glbattr)'
),
].map( ( attr ) => {
const terms =
(
attr.querySelector(
"[name^='attribute_values']"
) as HTMLTextAreaElement
)?.value.split( '|' ).length ?? 0;
return {
name: (
attr.querySelector(
'[name^="attribute_names"]'
) as HTMLInputElement
)?.value,
terms,
};
} );
recordEvent( 'product_attributes_add', {
page: 'product',
enable_archive: '',
default_sort_order: '',
local_attributes,
} );
}
} );

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add additional global attributes and local attributes information when saving product attributes