Send a tracks event when analytics settings are reset to defaults.

This commit is contained in:
Jeff Stieler 2019-07-11 13:30:42 -06:00
parent 280542255f
commit e5424fdd4d
1 changed files with 15 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components'; import { Button } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element'; import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose'; import { compose } from '@wordpress/compose';
import { remove, transform } from 'lodash'; import { partial, remove, transform } from 'lodash';
import { withDispatch } from '@wordpress/data'; import { withDispatch } from '@wordpress/data';
/** /**
@ -80,7 +80,7 @@ class Settings extends Component {
) { ) {
const settings = {}; const settings = {};
analyticsSettings.forEach( setting => ( settings[ setting.name ] = setting.defaultValue ) ); 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; const { settings } = this.state;
this.persistChanges( this.state ); this.persistChanges( this.state );
this.props.updateSettings( { wc_admin: settings } ); this.props.updateSettings( { wc_admin: settings } );
const eventProps = transform( if ( 'reset' === source ) {
analyticsSettings, recordEvent( 'analytics_settings_reset_defaults' );
( props, setting ) => { } else {
props[ setting.name ] = settings[ setting.name ]; const eventProps = transform(
}, analyticsSettings,
{} ( props, setting ) => {
); props[ setting.name ] = settings[ setting.name ];
recordEvent( 'analytics_settings_save', eventProps ); },
{}
);
recordEvent( 'analytics_settings_save', eventProps );
}
// TODO: remove this optimistic set of isDirty to false once #2541 is resolved. // TODO: remove this optimistic set of isDirty to false once #2541 is resolved.
this.setState( { saving: true, isDirty: false } ); this.setState( { saving: true, isDirty: false } );