Skip to content

Route stats deep links to New Stats when enabled - #23183

Open
nbradbury wants to merge 8 commits into
trunkfrom
newstats/stats-deep-links
Open

Route stats deep links to New Stats when enabled#23183
nbradbury wants to merge 8 commits into
trunkfrom
newstats/stats-deep-links

Conversation

@nbradbury

@nbradbury nbradbury commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

Even when new stats are enabled, deep links continued to open old stats. This PR resolves the problem and updates related analytics tracking.

Testing instructions

Testing this PR may seem tedious, but you can point Claude at this PR and ask it to do the testing steps for you.

Custom scheme links

adb shell am start -a android.intent.action.VIEW -d 'jetpack://stats'
adb shell am start -a android.intent.action.VIEW -d 'jetpack://stats/day'
adb shell am start -a android.intent.action.VIEW -d 'jetpack://stats/month'
adb shell am start -a android.intent.action.VIEW -d 'jetpack://stats/insights'
adb shell am start -a android.intent.action.VIEW -d 'jetpack://stats/subscribers'
  • jetpack://stats → New Stats, Traffic tab, persisted period
  • /stats/day → Traffic, Today
  • /stats/month → Traffic, Last 30 days
  • /stats/insightsInsights tab
  • /stats/subscribersSubscribers tab

Web links

Replace YOURSITE.com below with a domain that actually exists in your account. App Links aren't verified on a debug build, so a bare am start may hand off to Chrome. Target the alias explicitly (com.jetpack.android.prealpha for jetpackDebug, org.wordpress.android.prealpha for wordpressDebug):

adb shell am start \
  -n com.jetpack.android.prealpha/org.wordpress.android.WebLinksDeepLinkingIntentReceiverActivity \
  -a android.intent.action.VIEW \
  -d 'https://wordpress.com/stats/week/YOURSITE.com'

Swap the last segment through each timeframe:

  • https://wordpress.com/stats/day/YOURSITE.com → that site, Traffic, Today
  • https://wordpress.com/stats/week/YOURSITE.com → Traffic, Last 7 days
  • https://wordpress.com/stats/month/YOURSITE.com → Traffic, Last 30 days
  • https://wordpress.com/stats/year/YOURSITE.com → Traffic, Last 12 months
  • https://wordpress.com/stats/insights/YOURSITE.comInsights tab
  • https://wordpress.com/stats/subscribers/YOURSITE.comSubscribers tab

The New Stats rollout gated the My Site menu, the post-login path, the
Today's Stats card and the two widget intents, but not deep links. A user
on the rollout tapping wordpress://stats or an emailed stats link landed
in old Stats.

The gate lives in ActivityNavigator rather than at the call sites, since
it is already injected into both DeepLinkNavigator and WPMainActivity and
already owns the TaskStackBuilder-over-WPMainActivity pattern. openStats
covers the site-less links (which must keep relaunching WPMainActivity so
back lands on My Site) and openStatsInNewStack the site-qualified ones. A
null site falls through to the old path on purpose, which reports
STATS_ACCESS_ERROR and toasts.

New Stats could not open on a given tab, which /stats/insights/ and
/stats/subscribers/ need, so StatsTab moves out of NewStatsActivity into
its own file and NewStatsScreen takes an initialTab. NewStatsTarget maps
the old-stats StatsTimeframe onto the closest tab and period; nothing maps
to Last6Months.

Shortcuts, notifications and the activity log still go to old Stats.
Routing the site-qualified stats deep links through
ActivityNavigator.openStatsInNewStack left the three-argument
viewStatsInNewStack with no callers - DeepLinkNavigator's OpenStatsForSite
arm was the only one. The four- and five-argument overloads and the
context-only variant are all still in use.
@dangermattic

dangermattic commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23183-0a4c003
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit0a4c003
Installation URL4sii0eik3eur8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23183-0a4c003
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit0a4c003
Installation URL454voetoplk8g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.23256% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.91%. Comparing base (474abeb) to head (0a4c003).

Files with missing lines Patch % Lines
...java/org/wordpress/android/ui/ActivityNavigator.kt 0.00% 16 Missing ⚠️
...ui/stats/refresh/lists/widget/utils/WidgetUtils.kt 0.00% 8 Missing ⚠️
...ordpress/android/ui/deeplinks/DeepLinkNavigator.kt 0.00% 3 Missing ⚠️
.../wordpress/android/ui/newstats/NewStatsActivity.kt 0.00% 2 Missing ⚠️
...rg/wordpress/android/ui/newstats/NewStatsTarget.kt 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #23183   +/-   ##
=======================================
  Coverage   37.90%   37.91%           
=======================================
  Files        2348     2350    +2     
  Lines      127693   127716   +23     
  Branches    17734    17739    +5     
=======================================
+ Hits        48408    48421   +13     
- Misses      75326    75335    +9     
- Partials     3959     3960    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

New Stats had no launch-source intake and fired no open event, so every
route into it - widgets, the My Site menu, the Today's Stats card and now
deep links - was invisible in analytics. During the rollout that reads as
stats traffic falling off rather than moving.

NewStatsActivity now takes a launchedFrom extra and reports STATS_ACCESSED
through the same trackStatsAccessed helper StatsViewModel uses, so the two
screens stay comparable. Tracking is guarded on savedInstanceState so a
rotation doesn't double-count; the activity is launchMode standard, so the
widgets' CLEAR_TOP recreates it and is correctly counted as a new launch.

launchedFrom is a required parameter rather than a defaulted one, since a
default is how this came to be dropped in the first place. buildIntent now
takes a localSiteId instead of a SiteModel, which lets the two widget paths
stop hand-rolling their intents and pick up the source for free.

Each call site reports what its old-stats twin already reported.
WidgetUtils passes the NewStatsActivity Intent to setPendingIntentTemplate,
and the per-row fill-in that supplies LOCAL_SITE_ID is merged by
system_server, which has no classloader for StatsTab or StatsLaunchedFrom.
Intent.fillIn catches the unmarshalling failure and logs it rather than
rethrowing, so the merge would be dropped silently and a widget row tap
would open whichever site was previously selected - the multi-site bug the
comment above getPendingSelfIntent already warns about.

Both extras now travel as names, matching how StatsPeriod already crosses
this boundary via toTypeString(). Lazy bundle unparcelling from API 33
likely hid this on newer devices; minSdk is 26.
@nbradbury
nbradbury marked this pull request as ready for review August 7, 2026 18:17
@nbradbury
nbradbury requested a review from adalpari August 7, 2026 18:17
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.

3 participants