Skip to content
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 Analytics pivot report support to the plugin. #8811

Merged
merged 8 commits into from
Jun 20, 2024

Conversation

benbowler
Copy link
Collaborator

@benbowler benbowler commented Jun 5, 2024

Summary

Addresses issue:

Relevant technical choices

I implemented pivot reporting mostly to the IB with some naming changes where I thought it would be more clear. I also:

  1. Used traits for both the create request and report parsing logic as this allows these methods to be cleanly used within the report/request classes for each report type
  2. Skipped the check for pivots.length, in the pivot store, validateParams function becuase this is handled in isValidPivots.

I didn't implement multi date range support but it's trivial to add this while I'm here so I might create a follow up ticket with a draft PR in triage for future use if this is needed.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@benbowler benbowler force-pushed the enhancement/8484-pivot-reports branch from bb86462 to 24ce52e Compare June 5, 2024 12:48
@benbowler benbowler marked this pull request as ready for review June 6, 2024 14:37
Copy link

github-actions bot commented Jun 6, 2024

Build files for 1d565f6 have been deleted.

Copy link

github-actions bot commented Jun 6, 2024

Size Change: +35 kB (+2.31%)

Total Size: 1.55 MB

Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 54.8 kB +503 B (+0.93%)
./dist/assets/js/34-********************.js 3.12 kB +1 B (+0.03%)
./dist/assets/js/contact-form-7-********************.js 645 B -1 B (-0.15%)
./dist/assets/js/googlesitekit-activation-********************.js 24.1 kB +36 B (+0.15%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 59.6 kB +334 B (+0.56%)
./dist/assets/js/googlesitekit-adminbar-********************.js 34.7 kB +40 B (+0.12%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 5.88 kB +1 B (+0.02%)
./dist/assets/js/googlesitekit-components-gm3-********************.js 10.1 kB -4 B (-0.04%)
./dist/assets/js/googlesitekit-data-********************.js 2.17 kB -4 B (-0.18%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.14 kB +3 B (+0.03%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.09 kB +2 B (+0.1%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 20 kB +106 B (+0.53%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10.1 kB +10 B (+0.1%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 25.2 kB +21 B (+0.08%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 74 kB +162 B (+0.22%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 126 kB +8.58 kB (+7.28%) 🔍
./dist/assets/js/googlesitekit-modules-********************.js 22.2 kB +78 B (+0.35%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 29.4 kB +320 B (+1.1%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 113 kB +1.03 kB (+0.92%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 140 kB +9.48 kB (+7.26%) 🔍
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 22.6 kB +63 B (+0.28%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 58.6 kB +312 B (+0.54%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32.2 kB +1.75 kB (+5.76%) 🔍
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B -1 B (-0.26%)
./dist/assets/js/googlesitekit-settings-********************.js 61.8 kB +123 B (+0.2%)
./dist/assets/js/googlesitekit-splash-********************.js 73.1 kB +433 B (+0.6%)
./dist/assets/js/googlesitekit-user-input-********************.js 48.3 kB +93 B (+0.19%)
./dist/assets/js/googlesitekit-vendor-********************.js 317 kB +121 B (+0.04%)
./dist/assets/js/googlesitekit-widgets-********************.js 59.2 kB +9.39 kB (+18.85%) ⚠️
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 61.7 kB +1.29 kB (+2.13%)
./dist/assets/js/optin-monster-********************.js 673 B +2 B (+0.3%)
./dist/assets/js/runtime-********************.js 1.3 kB +1 B (+0.08%)
./dist/assets/js/woocommerce-********************.js 652 B -1 B (-0.15%)
./dist/assets/js/wpforms-********************.js 632 B -1 B (-0.16%)
./dist/assets/js/ninja-forms-********************.js 727 B +727 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.2 kB
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 770 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 7.47 kB
./dist/assets/js/29-********************.js 2.76 kB
./dist/assets/js/30-********************.js 2.25 kB
./dist/assets/js/31-********************.js 3.64 kB
./dist/assets/js/32-********************.js 935 B
./dist/assets/js/33-********************.js 892 B
./dist/assets/js/analytics-advanced-tracking-********************.js 776 B
./dist/assets/js/googlesitekit-api-********************.js 10.2 kB
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB
./dist/assets/js/mailchimp-********************.js 629 B
./dist/assets/js/popup-maker-********************.js 634 B

compressed-size-action

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @benbowler nice work on this one. I just left you a few comments

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbowler Thanks, LGTM.

Can you just please update QAB to provide an example snippet for the QA to use, so they can test the pivot report. The referenced issue does not have QAB yet, so there is no JS snippet there either. After this is updated you can move it straight to the MR

@benbowler
Copy link
Collaborator Author

Thanks @zutigrm, I added an example to the QAB.

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏻

I have some comments around naming/readability mostly, but they're quite minor. After those are addressed should be good to merge 😄

Comment on lines 770 to 776
return acc.sort( ( rowA, rowB ) =>
orderbyItem.desc
? rowB.metricValues[ metricIndex ].value -
rowA.metricValues[ metricIndex ].value
: rowA.metricValues[ metricIndex ].value -
rowB.metricValues[ metricIndex ].value
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tough to read; it's technically all one statement with an implicit return and multiline-ternary. It winds up being tough to glance at and figure out. How about:

Suggested change
return acc.sort( ( rowA, rowB ) =>
orderbyItem.desc
? rowB.metricValues[ metricIndex ].value -
rowA.metricValues[ metricIndex ].value
: rowA.metricValues[ metricIndex ].value -
rowB.metricValues[ metricIndex ].value
);
return acc.sort( ( rowA, rowB ) => {
if ( orderbyItem.desc ) {
return rowB.metricValues[ metricIndex ].value - rowA.metricValues[ metricIndex ].value;
}
return rowA.metricValues[ metricIndex ].value - rowB.metricValues[ metricIndex ].value;
} );

(Arguably you could also just sort it one way, then reverse the array if orderbyItem.desc is set, but technically I guess this is more efficient and it's not any harder to read 😄 )

Comment on lines 868 to 874
const val =
ANALYTICS_4_DIMENSION_OPTIONS[ dimension ]( i );
if ( val ) {
observer.next( val );
} else {
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets avoid shortened words for things like value. Even better to say what kind of value this is, as variable names like value, data, etc. don't provide any context. At least this is a bit more explicit:

Suggested change
const val =
ANALYTICS_4_DIMENSION_OPTIONS[ dimension ]( i );
if ( val ) {
observer.next( val );
} else {
break;
}
const dimensionValue =
ANALYTICS_4_DIMENSION_OPTIONS[ dimension ]( i );
if ( dimensionValue ) {
observer.next( dimensionValue );
} else {
break;
}

* @param {Object[]} pivots The pivots to check.
* @return {boolean} TRUE if pivot definitions are valid, otherwise FALSE.
*/
export function isValidPivots( pivots ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isValidPivots seems a bit vague, because a pivot itself isn't a clear noun 😅

Would isValidPivotsDefinition or something be more clear? Or arePivotDefinitionsValid? 🤷🏻

Maybe not, but this just seems a bit incompletely named 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with isValidPivotsObject to match other validation checks such as isValidDateString and isPlainObject.

Comment on lines +44 to +46
// NOTE: The majority of this classes logic has been abstracted to
// ReportParsers which contains the shared methods for both
// Report and PivotReport classes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is even really left of this class? It seems like it isn't implementing anything itself… why keep it around? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should keep this class around for a consistant structure between both report types and in theory we can use this class in future to implement any non pivot report specific logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty, works for me 👍🏻

* @return Google_Service_AnalyticsData_Dimension[] An array of AnalyticsData Dimension objects.
*/
protected function parse_dimensions( Data_Request $data ) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

* @access private
* @ignore
*/
class ReportParsers {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be plural? Wouldn't it be a ReportParser? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the class contains multiple parsers so this is the report parsers class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough 😄

@tofumatt tofumatt merged commit 3b3ebf9 into develop Jun 20, 2024
26 of 28 checks passed
@tofumatt tofumatt deleted the enhancement/8484-pivot-reports branch June 20, 2024 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants