New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getReport
selector to modules/analytics
store
#1775
Comments
I was unclear on what
site-kit-wp/includes/Modules/Analytics.php Line 891 in 3f100ac
startDate and endDate don't require either params, and also that startDate and endDate are the end-goal of date code. Given the ACs also mandate they work out-of-the-box and there's only one place to change the approach used, I propose we scrap the older arguments and just use startDate and endDate . It's much easier to understand, easier to implement, and code in the UI can sort out things like last-28-days to create the correct startDate and endDate values.
I wondered about accepting plain date objects rather than formatted Unless I'm missing something, I think doing that should simplify this issue, reduce technical debt, and reduce code complexity. |
@tofumatt See my comment on #1774, we should keep these legacy parameters around for now since implementing on the client is not trivial and should happen separately. I'm open to discussing whether we should not document them, but we should implement support for them per the ACs. It shouldn't be complex to implement because the complex parts are all already there - I agree the legacy args are complex to understand, but we'll still need them for now. |
Sounds good, I've updated the IB to be more in-line with #1774 then, and changed the startDate and endDate to be strings for now as that IB was already accepted. It's not a big deal, but if we want to use |
IB ✅ |
Code review approved; just assigning here to merge the code. 😄 |
There should be a
getReport
selector issuing an API request to ourGET:modules/analytics/data/report
datapoint, which relies on https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet.While maintaining backward-compatibility, the datapoint should be adjusted to support a range of arguments closer to the original. At the same time, this should happen in a way where similar arguments are named the same way across different report datapoints (e.g. in Search Console or AdSense).
While not yet fully in its intended a state, a good reference here is the existing
getReport
selector of themodules/adsense
store. The one here should be approached similarly.While the PageSpeed Insights report endpoint is not time-based and generally simpler than the ones here, it's good to have a look at that respective selector implementation too.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
modules/analytics
JS store should expose a selectorgetReport( options = {} )
.createFetchStore
to issue an API request to theGET:modules/analytics/data/report
datapoint.startDate
: Required, unlessdateRange
is provided. Start date to query report data for asYYYY-mm-dd
.endDate
: Required, unlessdateRange
is provided. End date to query report data for asYYYY-mm-dd
.dateRange
: Required, alternatively tostartDate
andendDate
. A date range string such as 'last-28-days'.compareDateRanges
: Optional, only relevant withdateRange
. Defaultfalse
.multiDateRange
: Optional, only relevant withdateRange
. Defaultfalse
.startDate
andendDate
. For now, our code should continue to usedateRange
(andcompareDateRanges
andmultiDateRange
where needed).startDate
andendDate
however should already work today, to allow for flexible queries regardless of Site Kit limitations.metrics
: Required. List of metrics to query. See https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/ for possible values. Alternatively to a string, each element can also be an object with 'expression' and 'alias' properties. At least one metric is required.dimensions
: Optional. List of dimensions to group results by. See https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/ for possible values. Default empty array.orderby
: Optional. An order definition object, or a list of order definition objects, each one containing 'fieldName' and 'sortOrder'. 'sortOrder' must be either 'ASCENDING' or 'DESCENDING'. Default empty array.url
: Optional. URL to get a report for only this URL. Default empty string.limit
: Optional. Maximum number of entries to return. Default 1000.GET:modules/analytics/data/report
datapoint should be modified to support arguments as described above, while maintaining full backward-compatibility. For example:startDate
andendDate
are provided, omitparse_date_range
logic and related, and set them directly.metrics
items as string or object/associative array.dimensions
as either array or string (while only the array should be documented).orderby
to also be a single object.Implementation Brief
getReport( options = {} )
to a new fileassets/js/modules/analytics/datastore/report.js
.createFetchStore
to issue an API request to theGET:modules/analytics/data/report
datapoint.startDate
: Required, unlessdateRange
is provided. Start date to query report data for asYYYY-mm-dd
.endDate
: Required, unlessdateRange
is provided. End date to query report data for asYYYY-mm-dd
.dateRange
: Required, alternatively tostartDate
andendDate
. A date range string such as 'last-28-days'.compareDateRanges
: Optional, only relevant withdateRange
. Defaultfalse
.multiDateRange
: Optional, only relevant withdateRange
. Defaultfalse
.metrics
: Required. List of metrics to query. See https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/ for possible values. Alternatively to a string, each element can also be an object with 'expression' and 'alias' properties. At least one metric is required.dimensions
: Optional. List of dimensions to group results by. See https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/ for possible values. Default empty array.orderby
: Optional. An order definition object, or a list of order definition objects, each one containing 'fieldName' and 'sortOrder'. 'sortOrder' must be either 'ASCENDING' or 'DESCENDING'. Default empty array.url
: Optional. URL to get a report for only this URL. Default empty string.limit
: Optional. Maximum number of entries to return. Default 1000.GET:modules/analytics/data/report
datapoint in PHP to support arguments as described above, while maintaining backward-compatibility for older arguments. For example:startDate
andendDate
are provided, omitparse_date_range
logic and related, and set them directly.metrics
items as string or object/associative array.dimensions
as either array or string (while only the array should be documented).orderby
to also be a single object.QA Brief
Changelog entry
getReport( options )
selector tomodules/analytics
store for querying Analytics reports.The text was updated successfully, but these errors were encountered: