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

Display "Origin" column in Orders table in Orders Analytics #46424

Merged
merged 34 commits into from Apr 18, 2024

Conversation

ecgan
Copy link
Member

@ecgan ecgan commented Apr 10, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #46383.

In this PR:

  • We add a new "Origin" column into the Orders table in Orders Analytics.
    • The GET /wp-json/wc-analytics/reports/orders endpoint is modified to return the origin data in extended_info.attribution.origin in the order objects in the API response. Example screenshot below:
image

Screenshot below shows the new "Origin" column in the Orders table in Orders Analytics:

image

Screenshot below shows the new "Origin" column in the exported CSV file:

image

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

NOTE: Orders Analytics has a cache in place. To test the code, you may refer to commit 1a48761 to disable caching.

  1. Create some orders with different order attribution origin. You may refer to PR Hide unnecessary order attribution details #44907 on how to do that.
    • You should have less than 25 orders to test client side CSV export file generation.
    • Alternatively, you can also use the date filter in Orders Analytics page to adjust the number of orders to be displayed.
  2. Go to Orders Analytics: /wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Forders
  3. In the Orders table at the bottom of the page, there should be a new "Origin" column. Make sure the values are correct for the orders, i.e. they should match what you see in the Orders listing page or in Order details page.
  4. In the table header, click on the "Download" button. A CSV file should be generated and downloaded immediately. Check that the CSV file contains the "Origin" column, and the values are correct for the orders.
  5. Create more orders with different order attribution origin. You should have more than 25 orders to test server side CSV export file generation.
  6. Go to Orders Analytics: /wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Forders
  7. In the table header, click on the "Download" button. You should see a notification toast at the bottom that says you will receive an email with a link to download the CSV file. You may need to wait for a few seconds or minutes to get the email. In the email, click on the link to get the CSV file. Check that the CSV file contains the "Origin" column, and the values are correct for the orders.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@ecgan ecgan added team: Ventures focus: order attribution Issues related to the order attribution feature labels Apr 10, 2024
@ecgan ecgan self-assigned this Apr 10, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 11, 2024
@ecgan ecgan changed the title Display Channel column in Orders table in Orders Analytics Display "Origin" column in Orders table in Orders Analytics Apr 15, 2024
@ecgan ecgan requested a review from a team April 15, 2024 16:52
@ecgan ecgan marked this pull request as ready for review April 15, 2024 16:52
Copy link
Contributor

github-actions bot commented Apr 15, 2024

Hi @ibndawood,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@ecgan
Copy link
Member Author

ecgan commented Apr 15, 2024

@layoutd , since you are the main contributor for the order attribution feature, could you help to review and test this feature please? 🙏

Also cc my co-DRI @ibndawood , for your info.

We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders.

By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin.
Copy link
Contributor

@ibndawood ibndawood left a comment

Choose a reason for hiding this comment

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

Hey @ecgan, I've added my review with some feedback. Please take a look and let me know what do you think.

@ecgan ecgan requested a review from ibndawood April 17, 2024 18:18
@ecgan
Copy link
Member Author

ecgan commented Apr 17, 2024

@ibndawood , thanks for the review. I have addressed your comments and make the necessary changes. Could you do another round of review please?

Copy link
Contributor

@ibndawood ibndawood left a comment

Choose a reason for hiding this comment

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

Thank you, @ecgan, for the changes. I've tested the PR with and without HPOS. I've also followed the test instructions. The changes test well. I've added one input and some cosmetic changes. I've approved the PR. 🚀

ecgan and others added 5 commits April 18, 2024 19:36
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
@ecgan ecgan enabled auto-merge (squash) April 18, 2024 16:14
@ecgan ecgan merged commit 48f2a4c into trunk Apr 18, 2024
24 of 25 checks passed
@ecgan ecgan deleted the add/orders-analytics-channel-column branch April 18, 2024 16:16
@github-actions github-actions bot added this to the 8.9.0 milestone Apr 18, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Apr 18, 2024
nielslange pushed a commit that referenced this pull request Apr 20, 2024
* Display channel column in Orders Analytics UI.

* Set $data to false to not use cache.

For development purpose.

* Get channel info from order meta and put into extended_info.

* Set channel in order item level.

* Replace channel with get_origin_label in extended_info.

* Remove unnneeded channel in orders_data.

* Display origin instead of channel in table.

* Fix lint errors.

* Query order meta table based on HPOS.

* Remove code for development purpose.

* Add changelog.

* Fix code comment.

* Guard against null values.

`_wc_order_attribution_utm_source` can be null when the order is created via web admin.

* Set default origin label to "Unknown".

This default is the same as found in `output_origin_column` function in plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php.

* Support server side report download.

This is needed when there are more than 25 records in the Orders Analytics report.

* Fix failed test.

* Fix lint error.

* Simplify code.

We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders.

By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin.

* Change "channel" to "attribution" object in controller.

This is because we need more than one piece of information, so we need it to be an object with properties like `origin`, `device` etc.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Change `origin` string to `attribution` array in Orders DataStore.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Change origin string to attribution object.

* Fix indexing after changing from origin string to attribution object.

* Change from origin string to attribution object in table.js.

* Simplify code.

To make code shorter and easier to read, instead of long horizontal code.

* Fix lint errors.

* Fix failed test.

* Fix lint error.

* Fix retrieving origin in CSV export.

* Use $wpdb->postmeta; cosmetic change.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Cosmetic change.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Sanitize order IDs by using absint.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

---------

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
@rodelgc rodelgc added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Apr 22, 2024
@alvarothomas alvarothomas added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Apr 24, 2024
@ecgan
Copy link
Member Author

ecgan commented Apr 26, 2024

Note that the "Origin" column is changed to "Attribution" column in PR #46760.

samueljseay pushed a commit that referenced this pull request Apr 29, 2024
* Display channel column in Orders Analytics UI.

* Set $data to false to not use cache.

For development purpose.

* Get channel info from order meta and put into extended_info.

* Set channel in order item level.

* Replace channel with get_origin_label in extended_info.

* Remove unnneeded channel in orders_data.

* Display origin instead of channel in table.

* Fix lint errors.

* Query order meta table based on HPOS.

* Remove code for development purpose.

* Add changelog.

* Fix code comment.

* Guard against null values.

`_wc_order_attribution_utm_source` can be null when the order is created via web admin.

* Set default origin label to "Unknown".

This default is the same as found in `output_origin_column` function in plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php.

* Support server side report download.

This is needed when there are more than 25 records in the Orders Analytics report.

* Fix failed test.

* Fix lint error.

* Simplify code.

We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders.

By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin.

* Change "channel" to "attribution" object in controller.

This is because we need more than one piece of information, so we need it to be an object with properties like `origin`, `device` etc.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Change `origin` string to `attribution` array in Orders DataStore.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Change origin string to attribution object.

* Fix indexing after changing from origin string to attribution object.

* Change from origin string to attribution object in table.js.

* Simplify code.

To make code shorter and easier to read, instead of long horizontal code.

* Fix lint errors.

* Fix failed test.

* Fix lint error.

* Fix retrieving origin in CSV export.

* Use $wpdb->postmeta; cosmetic change.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Cosmetic change.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

* Sanitize order IDs by using absint.

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>

---------

Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: order attribution Issues related to the order attribution feature needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. release: highlight Issues that have a high user impact and need to be discussed/paid attention to. status: analysis complete Indicates if a PR has been analysed by Solaris team: Ventures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display "Origin" column in Orders table in Orders Analytics
4 participants