-
Notifications
You must be signed in to change notification settings - Fork 278
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
Use pivot reports to fetch audiences metrics. #8870
Use pivot reports to fetch audiences metrics. #8870
Conversation
Build files for e9b2a6a are ready:
|
Size Change: +178 B (+0.01%) Total Size: 1.55 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ankitrox, good work so far. I've left a number of comments to address, please take a look.
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Outdated
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Outdated
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Outdated
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/AudienceTilesWidget.js
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ankitrox, thanks for the update. This does need another update, though - I've noticed the output for the mock data is not quite as expected, and there are a couple of other points to address. Please take a look.
// TODO: as part of #8484 the report props should be updated to expect | ||
// the full report rows for the current tile to reduce data manipulation | ||
// in AudienceTiles. | ||
function getDataFromRows( { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our convention is to extract utility functions like these to a separate file.
Please can you extract getDataFromRows()
and collectAudienceRows()
to a new utils.js
file in the same folder, and add JSDoc?
See DashboardAllTrafficWidgetGA4/utils.js
by way of example.
* }, | ||
* { | ||
* fieldNames: [ 'pagePath', 'pageTitle' ], // having 3 rows | ||
* limit: 3, | ||
* }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is slightly off here. Also, did you mean to duplicate the field names?
* }, | |
* { | |
* fieldNames: [ 'pagePath', 'pageTitle' ], // having 3 rows | |
* limit: 3, | |
* }, | |
* }, | |
* { | |
* fieldNames: [ 'totalUsers' ], // having 3 rows | |
* limit: 3, | |
* }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The long test posts have been lost in the various stories - these were there to demonstrate the ellipses. Please can you restore them?
dimensions: [ 'city', 'audienceResourceName', 'country' ], | ||
pivots: [ | ||
{ | ||
fieldNames: [ 'audienceResourceName' ], | ||
limit: 2, | ||
}, | ||
{ | ||
fieldNames: [ 'city', 'country' ], | ||
limit: 3, | ||
orderby: [ | ||
{ | ||
metric: { | ||
metricName: 'totalUsers', | ||
}, | ||
desc: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
fieldNames: [ 'country' ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting output is a bit confusing to read with country
specified in two pivots. I'd suggest using an additional dimension:
dimensions: [ 'city', 'audienceResourceName', 'country' ], | |
pivots: [ | |
{ | |
fieldNames: [ 'audienceResourceName' ], | |
limit: 2, | |
}, | |
{ | |
fieldNames: [ 'city', 'country' ], | |
limit: 3, | |
orderby: [ | |
{ | |
metric: { | |
metricName: 'totalUsers', | |
}, | |
desc: true, | |
}, | |
], | |
}, | |
{ | |
fieldNames: [ 'country' ], | |
dimensions: [ | |
'city', | |
'audienceResourceName', | |
'country', | |
'sessionDefaultChannelGrouping', | |
], | |
pivots: [ | |
{ | |
fieldNames: [ 'audienceResourceName' ], | |
limit: 2, | |
}, | |
{ | |
fieldNames: [ 'city', 'country' ], | |
limit: 3, | |
orderby: [ | |
{ | |
metric: { | |
metricName: 'totalUsers', | |
}, | |
desc: true, | |
}, | |
], | |
}, | |
{ | |
fieldNames: [ 'sessionDefaultChannelGrouping' ], |
...s/modules/analytics-4/utils/__fixtures__/mocked-pivot-report-multi-dimension-fieldnames.json
Show resolved
Hide resolved
"pivotDimensionHeaders": [ | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "Dublin" | ||
} | ||
] | ||
}, | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "(not set)" | ||
} | ||
] | ||
}, | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "Cork" | ||
} | ||
] | ||
} | ||
], | ||
"rowCount": 3 | ||
}, | ||
{ | ||
"pivotDimensionHeaders": [ | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "United States" | ||
} | ||
] | ||
}, | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "United Kingdom" | ||
} | ||
] | ||
}, | ||
{ | ||
"dimensionValues": [ | ||
{ | ||
"value": "India" | ||
} | ||
] | ||
} | ||
], | ||
"rowCount": 3 | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see from the JSON example I posted in my comment at the top of the file - the expected response for a multi-dimensional pivot is for there to be a single pivotDimensionHeaders
object for the pivot, with multiple entries in each dimensionValues
array (one entry per field name).
However the current test output seems to have a single pivotDimensionHeaders
object per field name, with just one entry in each dimensionValues
array.
Expected shape (taken from my example so the values are different)
{
"pivotDimensionHeaders": [
{
"dimensionValues": [
{
"value": "Dublin"
},
{
"value": "Ireland"
}
]
},
{
"dimensionValues": [
{
"value": "Cork"
},
{
"value": "Ireland"
}
]
},
{
"dimensionValues": [
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
}
]
}
],
"rowCount": 1123
},
Current shape
{
"pivotDimensionHeaders": [
{
"dimensionValues": [
{
"value": "Dublin"
}
]
},
{
"dimensionValues": [
{
"value": "(not set)"
}
]
},
{
"dimensionValues": [
{
"value": "Cork"
}
]
}
],
"rowCount": 3
},
{
"pivotDimensionHeaders": [
{
"dimensionValues": [
{
"value": "United States"
}
]
},
{
"dimensionValues": [
{
"value": "United Kingdom"
}
]
},
{
"dimensionValues": [
{
"value": "India"
}
]
}
],
"rowCount": 3
},
"rowCount": 3 | ||
} | ||
], | ||
"aggregates": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number and shape of the aggregates is also not correct. As you can see, for each pivot, we should have effectively have the number of rows (i.e. limit
in our output) x 3 (TOTAL, MINIMUM and MAXIMUM).
So there should be 2x3 + 3x3 + 3x3 = 24 entries in aggregates
. As you can see the current output only has 9 entries. Also, the each entry should contain 4 dimension values.
Expected shape (taken from my example)
"aggregates": [
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
}
],
"metricValues": [
{
"value": "4892"
},
{
"value": "4892"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "2104"
},
{
"value": "2104"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "1936"
},
{
"value": "1936"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_TOTAL"
}
],
"metricValues": [
{
"value": "1202"
},
{
"value": "1202"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "690"
},
{
"value": "690"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_MAX"
}
],
"metricValues": [
{
"value": "551"
},
{
"value": "551"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "551"
},
{
"value": "551"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
}
],
"metricValues": [
{
"value": "551"
},
{
"value": "551"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
},
{
"value": "RESERVED_TOTAL"
}
],
"metricValues": [
{
"value": "530"
},
{
"value": "530"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "430"
},
{
"value": "430"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_TOTAL"
}
],
"metricValues": [
{
"value": "244"
},
{
"value": "244"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "RESERVED_TOTAL"
}
],
"metricValues": [
{
"value": "196"
},
{
"value": "196"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_MAX"
}
],
"metricValues": [
{
"value": "191"
},
{
"value": "191"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "121"
},
{
"value": "121"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "RESERVED_MAX"
}
],
"metricValues": [
{
"value": "83"
},
{
"value": "83"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
},
{
"value": "RESERVED_MAX"
}
],
"metricValues": [
{
"value": "78"
},
{
"value": "78"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_MIN"
}
],
"metricValues": [
{
"value": "4"
},
{
"value": "4"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "RESERVED_MIN"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "RESERVED_MIN"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
},
{
"value": "RESERVED_MIN"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
}
],
Current output
"aggregates": [
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "city"
}
],
"metricValues": [
{
"value": "27"
},
{
"value": "91"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "audienceResourceName"
}
],
"metricValues": [
{
"value": "86"
},
{
"value": "53"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MIN"
},
{
"value": "country"
}
],
"metricValues": [
{
"value": "38"
},
{
"value": "71"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "city"
}
],
"metricValues": [
{
"value": "21"
},
{
"value": "74"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "audienceResourceName"
}
],
"metricValues": [
{
"value": "66"
},
{
"value": "80"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_MAX"
},
{
"value": "country"
}
],
"metricValues": [
{
"value": "16"
},
{
"value": "22"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "city"
}
],
"metricValues": [
{
"value": "45"
},
{
"value": "34"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "audienceResourceName"
}
],
"metricValues": [
{
"value": "23"
},
{
"value": "91"
}
]
},
{
"dimensionValues": [
{
"value": "RESERVED_TOTAL"
},
{
"value": "country"
}
],
"metricValues": [
{
"value": "38"
},
{
"value": "66"
}
]
}
],
] | ||
} | ||
], | ||
"rows": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, the number of rows
is not as expected either.
The number of rows should be the product of multiplying the row count for each pivot together. So with pivots returning 2, 3 and 3 rows, the report row count should be 2x3x3 = 18.
However the current output only has 6 rows, so it evidently doesn't have the right combination of values.
Expected shape (taken from my example)
"rows": [
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "551"
},
{
"value": "551"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "430"
},
{
"value": "430"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "191"
},
{
"value": "191"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "121"
},
{
"value": "121"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "83"
},
{
"value": "83"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "78"
},
{
"value": "78"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "70"
},
{
"value": "70"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "64"
},
{
"value": "64"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "36"
},
{
"value": "36"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "26"
},
{
"value": "26"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "21"
},
{
"value": "21"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Dublin"
},
{
"value": "Ireland"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "14"
},
{
"value": "14"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "12"
},
{
"value": "12"
}
]
},
{
"dimensionValues": [
{
"value": "new"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "8"
},
{
"value": "8"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "iOS"
}
],
"metricValues": [
{
"value": "7"
},
{
"value": "7"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "Android"
}
],
"metricValues": [
{
"value": "4"
},
{
"value": "4"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Sao Paulo"
},
{
"value": "Brazil"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "4"
},
{
"value": "4"
}
]
},
{
"dimensionValues": [
{
"value": "returning"
},
{
"value": "Cork"
},
{
"value": "Ireland"
},
{
"value": "Windows"
}
],
"metricValues": [
{
"value": "1"
},
{
"value": "1"
}
]
}
],
Current output
"rows": [
{
"dimensionValues": [
{
"value": "properties/12345/audiences/2"
},
{
"value": "Cork"
},
{
"value": "India"
},
{
"value": "India"
}
],
"metricValues": [
{
"value": "98"
},
{
"value": "7"
}
]
},
{
"dimensionValues": [
{
"value": "properties/12345/audiences/2"
},
{
"value": "(not set)"
},
{
"value": "United Kingdom"
},
{
"value": "United Kingdom"
}
],
"metricValues": [
{
"value": "89"
},
{
"value": "62"
}
]
},
{
"dimensionValues": [
{
"value": "properties/12345/audiences/1"
},
{
"value": "Dublin"
},
{
"value": "United States"
},
{
"value": "United States"
}
],
"metricValues": [
{
"value": "55"
},
{
"value": "14"
}
]
},
{
"dimensionValues": [
{
"value": "properties/12345/audiences/1"
},
{
"value": "Cork"
},
{
"value": "India"
},
{
"value": "India"
}
],
"metricValues": [
{
"value": "17"
},
{
"value": "39"
}
]
},
{
"dimensionValues": [
{
"value": "properties/12345/audiences/2"
},
{
"value": "Dublin"
},
{
"value": "United States"
},
{
"value": "United States"
}
],
"metricValues": [
{
"value": "10"
},
{
"value": "73"
}
]
},
{
"dimensionValues": [
{
"value": "properties/12345/audiences/1"
},
{
"value": "(not set)"
},
{
"value": "United Kingdom"
},
{
"value": "United Kingdom"
}
],
"metricValues": [
{
"value": "3"
},
{
"value": "13"
}
]
}
],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ankitrox, just a few last comments to address and this should be good to go.
assets/js/modules/analytics-4/utils/__fixtures__/mocked-pivot-report-3-dimensions.json
Outdated
Show resolved
Hide resolved
assets/js/modules/analytics-4/utils/__fixtures__/mocked-pivot-report.json
Outdated
Show resolved
Hide resolved
assets/js/modules/analytics-4/components/audience-segmentation/dashboard/utils.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work @ankitrox!
Summary
Addresses issue:
Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist