site-kit-wp: Analytics: Inconsistent reporting periods / incorrect dates

Bug Description

The Analytics dashboard in Site Kit shows inconsistent and possibly incorrect reporting dates based on dropdown selection selection, in particular 90 days reporting period.

image

Examples below:

From WordPress user Current date is Feb 5th 2020. Below are examples or incorrect reporting periods

Related WordPress support topic https://wordpress.org/support/topic/wrong-date-with-analytics/

Reproduced

Screenshots

Additional Context


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The timeframe displayed in GA report should be within 1-3 days at most of the actual timeframe (i.e. if the user selects “90 days”, the chart should display 87 days the least)

Implementation Brief

  • When constructing the Analytics chart in AnalyticsDashboardWidgetSiteStats, add hAxis.minValue and hAxis.maxValue to the chart options:
    • In extractAnalyticsDashboardData - return minDate and maxDate values. maxDate is the date of the last returned entry. Because the query compares two time periods minDate is the date of the row that starts the latter half of the rows (lastMonth).
    • In AnalyticsDashboardWidgetSiteStats, pass the min/max values to the call to setOptions: const options = this.setOptions( dataMap.minDate, dataMap.maxDate );
    • Adjust setOptions to accept min/max values, using them for hAxis.minValue and hAxis.maxValues.

Changelog entry

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

@adamsilverstein minValue and maxValue seem to require a number but the IB references dates which I assume are strings.

The type of the value depends on the way you have configured the x- axis (what data type it is set to). In our case, the type here is specified as “date” (https://github.com/google/site-kit-wp/blob/0eacc17f4c2627ad4f7e4ba81d666dbe3058d738/assets/js/modules/analytics/util/index.js#L147) and it is constructed from Date objects (https://github.com/google/site-kit-wp/blob/develop/assets/js/modules/analytics/util/index.js#L82-L84). I tested the code in the IB and observed an improvement of the x-axis labeling. eg, adding:

minValue: new Date( '01/20/2020' ),
maxValue: new Date( '04/20/2020' ),

resulted in the chart showing those dates at the left and right hand end of the x axis (except at very small screen sizes).