[Single Variation] Add missing tracks events (#40996)

* Add note prop

* Add note for single variation

* Add event recording for generic toggle

* Add changelog

* Add parent_id to toggle event

* move logic inside recordProductEvent

* Modify postType
This commit is contained in:
Fernando Marichal 2023-10-26 00:45:53 -03:00 committed by GitHub
parent 2639aba8a9
commit 898eb30f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
[Single Variation] Add missing tracks events #40996

View File

@ -4,6 +4,11 @@
import { createElement } from '@wordpress/element';
import { ToggleControl } from '@wordpress/components';
import { useWooBlockProps } from '@woocommerce/block-templates';
import { recordEvent } from '@woocommerce/tracks';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore No types for this exist yet.
// eslint-disable-next-line @woocommerce/dependency-group
import { useEntityProp, useEntityId } from '@wordpress/core-data';
/**
* Internal dependencies
@ -12,6 +17,7 @@ import { ToggleBlockAttributes } from './types';
import { sanitizeHTML } from '../../../utils/sanitize-html';
import { ProductEditorBlockEditProps } from '../../../types';
import useProductEntityProp from '../../../hooks/use-product-entity-prop';
import { TRACKS_SOURCE } from '../../../constants';
export function Edit( {
attributes,
@ -19,6 +25,7 @@ export function Edit( {
}: ProductEditorBlockEditProps< ToggleBlockAttributes > ) {
const blockProps = useWooBlockProps( attributes );
const {
_templateBlockId,
label,
property,
disabled,
@ -30,6 +37,12 @@ export function Edit( {
postType,
fallbackValue: false,
} );
const productId = useEntityId( 'postType', postType );
const [ parentId ] = useEntityProp< number >(
'postType',
postType,
'parent_id'
);
function isChecked() {
if ( checkedValue !== undefined ) {
@ -39,6 +52,11 @@ export function Edit( {
}
function handleChange( checked: boolean ) {
recordEvent( 'product_toggle_click', {
block_id: _templateBlockId,
source: TRACKS_SOURCE,
product_id: parentId > 0 ? parentId : productId,
} );
if ( checked ) {
setValue( checkedValue !== undefined ? checkedValue : checked );
} else {

View File

@ -18,6 +18,7 @@ const potentialTrackableProductValueKeys = [
'description',
'manage_stock',
'menu_order',
'note',
'purchase_note',
'sale_price',
'short_description',
@ -43,6 +44,11 @@ export function recordProductEvent(
product_type: type,
};
if ( product.parent_id > 0 ) {
product.note = product.description;
delete product.description;
}
for ( const productValueKey of Object.keys( product ) ) {
if ( potentialTrackableProductValueKeys.includes( productValueKey ) ) {
const eventPropKey =