add: lys badge tracks (#46509)
This commit is contained in:
parent
0cd8740a85
commit
2898efa648
|
@ -6,6 +6,7 @@ import { Icon, moreVertical, edit, cog } from '@wordpress/icons';
|
|||
import { Dropdown, Button, MenuGroup, MenuItem } from '@wordpress/components';
|
||||
import { getAdminLink, getSetting } from '@woocommerce/settings';
|
||||
import classnames from 'classnames';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -66,6 +67,16 @@ export const LaunchYourStoreStatus = ( {
|
|||
<>
|
||||
<MenuGroup className="woocommerce-lys-status-popover">
|
||||
<MenuItem
|
||||
onClick={ () => {
|
||||
recordEvent(
|
||||
'launch_your_store_badge_menu_manage_site_visibility_click',
|
||||
{
|
||||
site_visibility: isComingSoon
|
||||
? 'coming_soon'
|
||||
: 'live',
|
||||
}
|
||||
);
|
||||
} }
|
||||
// @ts-expect-error Prop gets passed down to underlying button https://developer.wordpress.org/block-editor/reference-guides/components/menu-item/#props
|
||||
href={ getAdminLink(
|
||||
'admin.php?page=wc-settings&tab=site-visibility'
|
||||
|
@ -80,6 +91,11 @@ export const LaunchYourStoreStatus = ( {
|
|||
{ isComingSoon &&
|
||||
getSetting( 'currentThemeIsFSETheme' ) && (
|
||||
<MenuItem
|
||||
onClick={ () => {
|
||||
recordEvent(
|
||||
'launch_your_store_badge_menu_customize_coming_soon_click'
|
||||
);
|
||||
} }
|
||||
// @ts-expect-error Prop gets passed down to underlying button https://developer.wordpress.org/block-editor/reference-guides/components/menu-item/#props
|
||||
href={
|
||||
COMING_SOON_PAGE_EDITOR_LINK
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: add
|
||||
|
||||
Add tracks events for the LYS badge
|
|
@ -28,30 +28,42 @@ class LaunchYourStore {
|
|||
* @return void
|
||||
*/
|
||||
public function save_site_visibility_options() {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) {
|
||||
$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
|
||||
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'woocommerce-settings' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// options to allowed update and their allowed values.
|
||||
$options = array(
|
||||
'woocommerce_coming_soon' => array( 'yes', 'no' ),
|
||||
'woocommerce_store_pages_only' => array( 'yes', 'no' ),
|
||||
'woocommerce_private_link' => array( 'yes', 'no' ),
|
||||
);
|
||||
|
||||
$at_least_one_saved = false;
|
||||
foreach ( $options as $name => $option ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( isset( $_POST[ $name ] ) && in_array( $_POST[ $name ], $option, true ) ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
update_option( $name, wp_unslash( $_POST[ $name ] ) );
|
||||
$at_least_one_saved = true;
|
||||
}
|
||||
}
|
||||
$event_data = array();
|
||||
|
||||
if ( $at_least_one_saved ) {
|
||||
wc_admin_record_tracks_event( 'site_visibility_saved' );
|
||||
foreach ( $options as $name => $allowed_values ) {
|
||||
$current_value = get_option( $name, 'not set' );
|
||||
$new_value = $current_value;
|
||||
|
||||
if ( isset( $_POST[ $name ] ) ) {
|
||||
$input_value = sanitize_text_field( wp_unslash( $_POST[ $name ] ) );
|
||||
|
||||
// no-op if input value is invalid.
|
||||
if ( in_array( $input_value, $allowed_values, true ) ) {
|
||||
update_option( $name, $input_value );
|
||||
$new_value = $input_value;
|
||||
|
||||
// log the transition if there is one.
|
||||
if ( $current_value !== $new_value ) {
|
||||
$enabled_or_disabled = 'yes' === $new_value ? 'enabled' : 'disabled';
|
||||
$event_data[ $name . '_toggled' ] = $enabled_or_disabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
$event_data[ $name ] = $new_value;
|
||||
}
|
||||
wc_admin_record_tracks_event( 'site_visibility_saved', $event_data );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue