From e5424fdd4da769e24ac2ba568affe5c653145813 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 13:30:42 -0600 Subject: [PATCH] Send a tracks event when analytics settings are reset to defaults. --- .../client/analytics/settings/index.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/settings/index.js b/plugins/woocommerce-admin/client/analytics/settings/index.js index d93616a5b1f..23b5dd94d14 100644 --- a/plugins/woocommerce-admin/client/analytics/settings/index.js +++ b/plugins/woocommerce-admin/client/analytics/settings/index.js @@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { Component, Fragment } from '@wordpress/element'; import { compose } from '@wordpress/compose'; -import { remove, transform } from 'lodash'; +import { partial, remove, transform } from 'lodash'; import { withDispatch } from '@wordpress/data'; /** @@ -80,7 +80,7 @@ class Settings extends Component { ) { const settings = {}; analyticsSettings.forEach( setting => ( settings[ setting.name ] = setting.defaultValue ) ); - this.setState( { settings }, this.saveChanges ); + this.setState( { settings }, partial( this.saveChanges, 'reset' ) ); } }; @@ -126,19 +126,23 @@ class Settings extends Component { } ); } - saveChanges = () => { + saveChanges = source => { const { settings } = this.state; this.persistChanges( this.state ); this.props.updateSettings( { wc_admin: settings } ); - const eventProps = transform( - analyticsSettings, - ( props, setting ) => { - props[ setting.name ] = settings[ setting.name ]; - }, - {} - ); - recordEvent( 'analytics_settings_save', eventProps ); + if ( 'reset' === source ) { + recordEvent( 'analytics_settings_reset_defaults' ); + } else { + const eventProps = transform( + analyticsSettings, + ( props, setting ) => { + props[ setting.name ] = settings[ setting.name ]; + }, + {} + ); + recordEvent( 'analytics_settings_save', eventProps ); + } // TODO: remove this optimistic set of isDirty to false once #2541 is resolved. this.setState( { saving: true, isDirty: false } );