Skip to content

Premium Analytics: Add WP-Cron CSV export for Jetpack Stats POC - #50362

Closed
layoutd wants to merge 14 commits into
trunkfrom
add/pa-stats-wpcron-export
Closed

layoutd wants to merge 14 commits into
trunkfrom
add/pa-stats-wpcron-export

Conversation

@layoutd

@layoutd layoutd commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes WOOA7S-1672

Proposed changes

  • Add a Jetpack Stats CSV export REST endpoint at POST /wp-json/jetpack-premium-analytics/v1/reports/stats-csv-export for direct downloads and WP-Cron scheduled email delivery.
  • Register stats-top-posts as the first Jetpack Stats export report, backed by the Stats top-posts proxy endpoint.
  • Add WooCommerce-free Jetpack Stats export bootstrap, WP-Cron scheduling, and wp_mail() attachment delivery.
  • Extend the shared Premium Analytics export fetcher/controller contract so Jetpack Stats reports can prepare Stats-specific request parameters and normalize Stats proxy summary payloads.
  • Add PHPUnit coverage for the Stats Top Posts controller, REST controller, WP-Cron scheduler, and wp_mail() delivery.
  • Add a Premium Analytics changelog entry.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No new tracking or data collection. This exports existing Jetpack Stats data for authorized users. Download delivery streams the CSV response, and email delivery schedules a WP-Cron job that sends the CSV as an attachment to the requesting user's account email.

Testing instructions

  • On a Jetpack-connected site with Premium Analytics active, log in as a user who can view stats.
  • POST to /wp-json/jetpack-premium-analytics/v1/reports/stats-csv-export with report_type=stats-top-posts, a valid from / to ISO date range, and delivery_method=download.
  • Confirm a CSV downloads for Top Posts & Pages with Title, Views, Type, and URL columns.
  • Repeat with delivery_method=email.
  • Confirm the endpoint returns 202 and the CSV arrives as an email attachment after WP-Cron runs.
  • Confirm a user without stats/admin permissions is denied.

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 9, 2026
@layoutd layoutd removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 9, 2026

This comment was marked as outdated.

@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from 136e503 to 19403d2 Compare July 9, 2026 12:51
@layoutd
layoutd requested a review from Copilot July 9, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

@jp-launch-control

jp-launch-control Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/Reports/Export/class-abstract-csv-report-controller.php 66/95 (69.47%) -0.74% 1 ❤️‍🩹
projects/packages/premium-analytics/src/class-analytics.php 4/64 (6.25%) -0.10% 1 ❤️‍🩹
projects/packages/premium-analytics/src/Reports/Export/class-report-data-fetcher.php 76/199 (38.19%) 30.13% -48 💚

6 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/premium-analytics/src/Reports/Export/Logging/class-error-log-logger.php 7/11 (63.64%) 💚
projects/packages/premium-analytics/src/Reports/Export/Exports/class-top-posts-export-controller.php 38/57 (66.67%) 💚
projects/packages/premium-analytics/src/Reports/Export/class-wp-cron-export-scheduler.php 114/158 (72.15%) 💚
projects/packages/premium-analytics/src/Reports/Export/class-wp-mail-export-email.php 48/53 (90.57%) 💚
projects/packages/premium-analytics/src/Reports/Export/class-stats-export.php 16/17 (94.12%) 💚

Full summary · PHP report

@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from 19403d2 to 1f325fb Compare July 9, 2026 13:17
@layoutd
layoutd requested a review from Copilot July 9, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Comment thread projects/packages/premium-analytics/changelog/add-pa-stats-wpcron-export Outdated
@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from 1f325fb to 7c8bfe0 Compare July 9, 2026 13:32
@layoutd
layoutd requested a review from Copilot July 9, 2026 13:32
@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from 7c8bfe0 to ca8d1cd Compare July 9, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from ca8d1cd to 01567fd Compare July 9, 2026 13:43
@layoutd
layoutd requested a review from Copilot July 9, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

@layoutd
layoutd force-pushed the add/pa-stats-wpcron-export branch from 01567fd to 04097ce Compare July 9, 2026 13:49
@layoutd
layoutd requested a review from Copilot July 9, 2026 13:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.

Comment thread projects/packages/premium-analytics/changelog/add-pa-stats-wpcron-export Outdated
@layoutd layoutd changed the title Premium Analytics: Add WP-Cron CSV export for Jetpack Stats Premium Analytics: Add WP-Cron CSV export for Jetpack Stats POC Jul 14, 2026
@layoutd

layoutd commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a POC in favor of client-side + direct retrieval combo: #50456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants