From 29a46f0665dffcf6ba828aa4c0cdfc42a4abf465 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 10 Jul 2019 16:42:02 -0600 Subject: [PATCH 1/9] Send a tracks event for reordering dashboard sections. --- plugins/woocommerce-admin/client/dashboard/customizable.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/woocommerce-admin/client/dashboard/customizable.js b/plugins/woocommerce-admin/client/dashboard/customizable.js index 7c7002e8adb..38b79d4a475 100644 --- a/plugins/woocommerce-admin/client/dashboard/customizable.js +++ b/plugins/woocommerce-admin/client/dashboard/customizable.js @@ -127,6 +127,12 @@ class CustomizableDashboard extends Component { // Yes, lets insert. sections.splice( newIndex, 0, movedSection ); this.updateSections( sections ); + + const eventProps = { + key: movedSection.key, + direction: 0 < change ? 'down' : 'up', + }; + recordEvent( 'dash_section_order_change', eventProps ); } else { // No, lets try the next one. this.onMove( index, change + change ); From 314e6d90e0aaf2ef620674a82600c6fa6d1d1027 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 10 Jul 2019 16:52:15 -0600 Subject: [PATCH 2/9] Send tracks event when adding dashboard section. --- plugins/woocommerce-admin/client/dashboard/customizable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/client/dashboard/customizable.js b/plugins/woocommerce-admin/client/dashboard/customizable.js index 38b79d4a475..f0b818fb2ee 100644 --- a/plugins/woocommerce-admin/client/dashboard/customizable.js +++ b/plugins/woocommerce-admin/client/dashboard/customizable.js @@ -103,7 +103,9 @@ class CustomizableDashboard extends Component { toggledSection.isVisible = ! toggledSection.isVisible; sections.push( toggledSection ); - if ( ! toggledSection.isVisible ) { + if ( toggledSection.isVisible ) { + recordEvent( 'dash_section_add', { key: toggledSection.key } ); + } else { recordEvent( 'dash_section_remove', { key: toggledSection.key } ); } From c36bfe6026adb580d2c6ab58abfab63f8558ff7e Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 10 Jul 2019 17:02:37 -0600 Subject: [PATCH 3/9] Send tracks event when dashboard sections are renamed. --- plugins/woocommerce-admin/client/dashboard/customizable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/woocommerce-admin/client/dashboard/customizable.js b/plugins/woocommerce-admin/client/dashboard/customizable.js index f0b818fb2ee..d4bfd61c9bc 100644 --- a/plugins/woocommerce-admin/client/dashboard/customizable.js +++ b/plugins/woocommerce-admin/client/dashboard/customizable.js @@ -86,6 +86,7 @@ class CustomizableDashboard extends Component { onSectionTitleUpdate( updatedKey ) { return updatedTitle => { + recordEvent( 'dash_section_rename', { key: updatedKey } ); this.updateSection( updatedKey, { title: updatedTitle } ); }; } From 9e217fbcaf66cf54e5136f7cc0d82f9e70818cb7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 08:49:53 -0600 Subject: [PATCH 4/9] Send tracks event when dashboard chart interval changes. --- .../woocommerce-admin/client/dashboard/dashboard-charts/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js b/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js index 7f39d35a9f8..c88dbefe404 100644 --- a/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js +++ b/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js @@ -139,6 +139,7 @@ class DashboardCharts extends Component { [ 'dashboard_chart_interval' ]: this.state.interval, }; this.props.updateCurrentUserData( userDataFields ); + recordEvent( 'dash_charts_interval', { interval } ); } ); }; From c820c92fe41b73e0733d0686083e5a47b282ca14 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 08:55:52 -0600 Subject: [PATCH 5/9] Send a tracks event when the dashboard chart type is toggled. --- .../woocommerce-admin/client/dashboard/dashboard-charts/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js b/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js index c88dbefe404..3cc3b205c89 100644 --- a/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js +++ b/plugins/woocommerce-admin/client/dashboard/dashboard-charts/index.js @@ -43,6 +43,7 @@ class DashboardCharts extends Component { [ 'dashboard_chart_type' ]: chartType, }; this.props.updateCurrentUserData( userDataFields ); + recordEvent( 'dash_charts_type_toggle', { chart_type: chartType } ); }; } From 1da8aba8e8e1673630908e262bd6c0ef322b2f10 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 11:53:47 -0600 Subject: [PATCH 6/9] Send a tracks event for report table pagination actions. --- .../client/analytics/components/report-table/index.js | 11 ++++++++++- .../packages/components/src/pagination/index.js | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/components/report-table/index.js b/plugins/woocommerce-admin/client/analytics/components/report-table/index.js index f6de37ee4b6..765c9b0d91f 100644 --- a/plugins/woocommerce-admin/client/analytics/components/report-table/index.js +++ b/plugins/woocommerce-admin/client/analytics/components/report-table/index.js @@ -66,7 +66,8 @@ class ReportTable extends Component { } } - onPageChange() { + onPageChange( newPage, source ) { + const { endpoint } = this.props; this.scrollPointRef.current.scrollIntoView(); const tableElement = this.scrollPointRef.current.nextSibling.querySelector( '.woocommerce-table__table' @@ -76,6 +77,14 @@ class ReportTable extends Component { if ( focusableElements.length ) { focusableElements[ 0 ].focus(); } + + if ( source ) { + if ( 'goto' === source ) { + recordEvent( 'analytics_table_go_to_page', { report: endpoint, page: newPage } ); + } else { + recordEvent( 'analytics_table_page_click', { report: endpoint, direction: source } ); + } + } } trackTableSearch() { diff --git a/plugins/woocommerce-admin/packages/components/src/pagination/index.js b/plugins/woocommerce-admin/packages/components/src/pagination/index.js index 2c4f89f9358..38185ea6cd7 100644 --- a/plugins/woocommerce-admin/packages/components/src/pagination/index.js +++ b/plugins/woocommerce-admin/packages/components/src/pagination/index.js @@ -38,7 +38,7 @@ class Pagination extends Component { if ( page - 1 < 1 ) { return; } - onPageChange( page - 1 ); + onPageChange( page - 1, 'previous' ); } nextPage( event ) { @@ -47,7 +47,7 @@ class Pagination extends Component { if ( page + 1 > this.pageCount ) { return; } - onPageChange( page + 1 ); + onPageChange( page + 1, 'next' ); } perPageChange( perPage ) { @@ -71,7 +71,7 @@ class Pagination extends Component { const newPage = parseInt( event.target.value, 10 ); if ( newPage !== page && isFinite( newPage ) && newPage > 0 && this.pageCount && this.pageCount >= newPage ) { - onPageChange( newPage ); + onPageChange( newPage, 'goto' ); } } From 280542255feb70259bc383d86f9112c5e8bee433 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 12:16:20 -0600 Subject: [PATCH 7/9] Send a track event when analytics settings are saved. --- .../client/analytics/settings/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/settings/index.js b/plugins/woocommerce-admin/client/analytics/settings/index.js index 44fe86a56a8..d93616a5b1f 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 } from 'lodash'; +import { remove, transform } from 'lodash'; import { withDispatch } from '@wordpress/data'; /** @@ -22,6 +22,7 @@ import { analyticsSettings } from './config'; import Setting from './setting'; import HistoricalData from './historical-data'; import withSelect from 'wc-api/with-select'; +import { recordEvent } from 'lib/tracks'; const SETTINGS_FILTER = 'woocommerce_admin_analytics_settings'; @@ -126,8 +127,18 @@ class Settings extends Component { } saveChanges = () => { + const { settings } = this.state; this.persistChanges( this.state ); - this.props.updateSettings( { wc_admin: this.state.settings } ); + this.props.updateSettings( { wc_admin: settings } ); + + 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 } ); From e5424fdd4da769e24ac2ba568affe5c653145813 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 13:30:42 -0600 Subject: [PATCH 8/9] 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 } ); From 562a1a231dbcb131199a1c539e1e788991937bdb Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 13:50:24 -0600 Subject: [PATCH 9/9] Send tracks event when historical data is deleted. --- .../client/analytics/settings/historical-data/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/woocommerce-admin/client/analytics/settings/historical-data/index.js b/plugins/woocommerce-admin/client/analytics/settings/historical-data/index.js index 920cd180efd..894670f64b0 100644 --- a/plugins/woocommerce-admin/client/analytics/settings/historical-data/index.js +++ b/plugins/woocommerce-admin/client/analytics/settings/historical-data/index.js @@ -18,6 +18,7 @@ import { stringifyQuery } from '@woocommerce/navigation'; */ import { formatParams } from './utils'; import HistoricalDataLayout from './layout'; +import { recordEvent } from 'lib/tracks'; class HistoricalData extends Component { constructor() { @@ -100,6 +101,7 @@ class HistoricalData extends Component { this.setState( { activeImport: false, } ); + recordEvent( 'analytics_import_delete_previous' ); } onReimportData() {