Skip to content

Conversation

@kean
Copy link
Contributor

@kean kean commented Jul 18, 2025

This PR implements the new "Traffic" tab for "Jetpack Stats".

The changes are isolated to the new JetpackStats module, which should make it easier to review – the new code in the module has no risk of introducing regressions to the existing codebase. I limited the number of changes to the existing code – I suggest to focus on that.

In terms of the new architecture and features, I'd suggest asking Claude Code to explain it.

Testing Instructions

  1. Enable New Stats: Open Stats and verify that the tip "Try New Stats" is shown and "Enable Now" buttons works. IT is shown only once.
  2. Test the new features (as you see fit)
  3. Verify that there are no regression in the existing Stats
  4. Verify that you can switch back and forth between new and old stats.

Tip: you can use these options at the bottom to re-test the TipKit:

Screenshot 2025-07-30 at 5 57 15 PM

PRs

Dependency: wordpress-mobile/WordPressKit-iOS#843

Screenshots

Screenshot 2025-07-30 at 1 17 26 PM

@kean kean added this to the 26.1 milestone Jul 18, 2025
@kean kean added the Stats label Jul 18, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 18, 2025

2 Warnings
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 26.1. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@kean kean force-pushed the feature/jetpack-stats branch from 38a433d to b743e7c Compare July 18, 2025 20:07
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 21, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number28433
VersionPR #24677
Bundle IDorg.wordpress.alpha
Commit5b51ea1
Installation URL0p6uqst2l53a0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 21, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number28433
VersionPR #24677
Bundle IDcom.jetpack.alpha
Commit5b51ea1
Installation URL1518dpjromgag
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
Copy link
Contributor

I didn't make the connection between the "Site Time Zone" wording and the "Greenwich Mean Time" wording on screen. Instead of saying "Stats are reported and shown in your site's time zone", maybe we can put the time zone in the wording: "Stats are reported and shown in your site's time zone: Greenwich Mean Time."?

@crazytonyli
Copy link
Contributor

The card customization seems to be stored app-wide, shared by all sites. What do you think of storing the customization per site? Users may want to see different cards on different sites.

@crazytonyli
Copy link
Contributor

The "Most Downloaded" card on my atomic site says "File Download stats are not available for Jetpack sites". I'm not sure what exactly that means. Is it a paid feature? How can I test it?

@kean
Copy link
Contributor Author

kean commented Aug 1, 2025

Meanwhile, do you mind breaking down this PR into some small ones?

That is not happening, I'm sorry ☺️

app quality team can test

They don't test, but we plan to do a Call for Testing to get more help testing it.

easily lead to duplicated content on the screen

I'm not sure that's a problem – you just don't do that, and you can easily remove a chart you don't need.

The top list's content can not be changed. i.e. "Most viewed pages"

I've also been thinking about it. I think it might be a good idea to fix the first chart, but I'm not sure about "Pages". If you truly don't need it – you'll remove it. Most users will likely never touch customization in the first place.

I'll disable removal of the top chart. I think we want to retain some control over it but let the rest of it be fully editable.

maybe we can put the time zone in the wording: "Stats are reported and shown in your site's time zone: Greenwich Mean Time."?

That's where the "Info" button comes in – you can tap it an it explains it in detail. I didn't want it to take more space than that. It's already an improvement over the web that doesn't have any notes about the reporting timezone.

What do you think of storing the customization per site?

I have this on a list for phase 2, but I'm not sure it's worth complicating it. Most users will likely not even touch customization. Most users have a few sites. I don't think it's worth adding. It will complicate it because some users will want app-wide customization and some won't, and the UI will have to accommodate both, which is too complex.

Is it a paid feature? How can I test it?

I opened a defect: CMM-640. If you find more defects, please report them on Linear so they could be addressed later. It's an experimental feature, and it will ship with defects unless we have show-stoppers.

@crazytonyli
Copy link
Contributor

maybe we can put the time zone in the wording: "Stats are reported and shown in your site's time zone: Greenwich Mean Time."?

That's where the "Info" button comes in – you can tap it an it explains it in detail.

I meant updating the wording in the pop-up, not the time zone text at the bottom of the screen.

@kean
Copy link
Contributor Author

kean commented Aug 4, 2025

I opened a defect: CMM-640.

I fixed time zone conversion in 5231fa9.

@kean
Copy link
Contributor Author

kean commented Aug 4, 2025

I meant updating the wording in the pop-up, not the time zone text at the bottom of the screen.

Ah, I misunderstood it. Good point. I move the time zone right under "Site Time Zone". Now it should be clear.

Screenshot 2025-08-04 at 12 58 08 PM

@kean kean enabled auto-merge August 4, 2025 21:55
if additionalSafeAreaInsets.bottom != bottomInset {
additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: min(20, bottomInset), right: 0)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a lot like AutoLayout. Can you implement this using constraints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to eliminate StatsHostingViewController in the scope of https://linear.app/a8c/issue/CMM-631/ipad-show-tabs-in-a-navigation-bar in phase two. The problem and the reason it was needed is that current StatsViewController(legacy) uses UIPageController for switching between pages, which is a bad idea because it's not designed to be used with vertically scrollable content. I plan to refactor it all for the final release.


if FeatureFlag.newStats.enabled {
// Main actions
var mainActions: [UIMenuElement] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: this variable is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to be used below: menuElements.append(contentsOf: mainActions)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I was not clear. By "redundant", I meant that you can put the actions into menuElements directly, without introducing this temporary veriable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, well this class will be removed in 26.2 anyway.

@@ -90,6 +90,8 @@ struct StatsTrafficDatePickerView: View {
private extension StatsPeriodUnit {
var label: String {
switch self {
case .hour:
fatalError("unsupported")
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few of these fatal errors. Replace them with wpAssertionFailure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I forgot to do it. Updated in 1fff562. I used the same returns values as for .day as placeholders.

@crazytonyli
Copy link
Contributor

You may want to add JetpackStatsTests to the unit tests test plan, so that it runs on CI.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 6, 2025

Copy link
Contributor

@crazytonyli crazytonyli left a comment

Choose a reason for hiding this comment

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

Approving to unblock. I have posted comments in the individual PRs listed in #24712.

GitHub is having trouble loading the diff, so I can't comment in the place of the code.

How the card customization is stored in StatsViewModel can be difficult to maintain. It saves TrafficCardConfiguration's default Codable implementation as JSON.

TrafficCardConfiguration has nested properties that are declared and used in other places, whose type declaration may change in the future. If they are changed, the serialization and deserialization may break, which leads to data loss where the display cards go from customized cards to the default ones.

@kean kean added this pull request to the merge queue Aug 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 6, 2025
@crazytonyli crazytonyli added this pull request to the merge queue Aug 7, 2025
Merged via the queue into trunk with commit 8601ae5 Aug 7, 2025
30 of 32 checks passed
@crazytonyli crazytonyli deleted the feature/jetpack-stats branch August 7, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants