Skip to content

UNI-828: Premium Analytics: Show cities as markers on the Locations map - #52859

Merged
Nikschavan merged 3 commits into
trunkfrom
uni-828-location-map-does-not-change-based-on-the-city-selector
Sep 29, 2026
Merged

Nikschavan merged 3 commits into
trunkfrom
uni-828-location-map-does-not-change-based-on-the-city-selector

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Fixes UNI-828

Proposed changes

  • When Cities is picked in the Locations widget or on the Cities tab of the Locations report, the map keeps shading whole countries, so it looks the same as the Countries view. The Stats API already sends latitude and longitude for every city, and Calypso Stats uses them to draw each city as a marker; Premium Analytics received them but dropped them.
  • The map now draws each city as a marker at its coordinates, sized and colored by views, in both the widget and the report. A city the API sends without coordinates is left off the map instead of being placed at 0, 0. When no city in the list has coordinates, the map draws an empty world map instead of Google's error bar. When the report is filtered to one country, the map zooms to that country and shows its cities. The Countries and Regions views do not change.
  • @automattic/charts GeoChart gets a displayMode prop ('regions' by default, or 'markers') so the Locations map can ask for markers. Every other GeoChart keeps the shaded regions it draws today.
Before (trunk) After (this branch)
Cities report map shading India and the United States as whole countries Cities report map with a marker on Pune, Mumbai, Chennai and San Jose
The Cities tab shades whole countries, the same as the Countries tab. Each city is a marker, sized and colored by its views.

Related product discussion/links

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

No.

Testing instructions

Get this branch onto a Jetpack site with Stats data from a few cities, either with the Jetpack Beta Tester plugin pointed at this branch or on a Jurassic Ninja site with the branch synced.

  • Go to Jetpack › Stats v2. In the Locations widget, pick Cities in the dropdown. The map shows one marker per city in the list instead of shaded countries.
  • Pick Countries and Regions again. Both still shade countries as before.
  • Click "View all" to open the Locations report, then open the Cities tab. The map shows the same markers.
  • Add a Country filter on the Cities tab. The map zooms to that country and shows only its cities. Remove the filter and the world map comes back.

I tested this on a local site against trunk with cities in India and the United States. I did not have a site where the API sends cities without coordinates, so I removed the coordinates from the locations response in the browser; the Cities map then drew an empty world map with no error.

@Nikschavan Nikschavan added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Sep 28, 2026
@Nikschavan Nikschavan self-assigned this Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the uni-828-location-map-does-not-change-based-on-the-city-selector branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack uni-828-location-map-does-not-change-based-on-the-city-selector
bin/jetpack-downloader test jetpack-mu-wpcom-plugin uni-828-location-map-does-not-change-based-on-the-city-selector

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

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!

@jp-launch-control

jp-launch-control Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/data/src/processing/stats/locations.ts 22/31 (70.97%) 6.97% 0 💚
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/locations-geo-chart/build-geo-data.ts 41/41 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

The Cities view summed cities back up to shaded countries, so the map did not change when Cities was picked. Draw each city at the coordinates the API already sends, as Calypso Stats does, in the widget and the report.
@Nikschavan
Nikschavan force-pushed the uni-828-location-map-does-not-change-based-on-the-city-selector branch from 7c584fe to 006960e Compare September 28, 2026 10:13
A header-only table makes Google type every column as a string, which a markers map rejects with an error bar. Type the header columns, and share StatsLocationCoordinates instead of repeating the shape.

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.

Copilot review overview

🟡 Changes recommended

Correct marker data ordering and address the documentation and plugin changelog gaps.

Review effort: Lite
Findings: 2 Low severity

Open (2)
What changed in this PR

Adds city markers to Premium Analytics Locations maps using API-provided coordinates, while preserving country and region shading.

Changes:

  • Propagates and validates city coordinates through widgets and reports.
  • Adds marker-mode support to GeoChart.
  • Updates tests, documentation, and changelogs.

Review notes: Correct the marker data column ordering, add a focused marker story and guidance, and add corresponding Premium Analytics plugin changelog entries.

File Summary
projects/​packages/​premium-analytics/​widgets/​locations/​use-location-views.ts Carries coordinates into widget rows.
projects/​packages/​premium-analytics/​widgets/​locations/​render.tsx Passes coordinates to the widget map.
projects/​packages/​premium-analytics/​routes/​reports/​locations/​page.tsx Passes coordinates to the report map.
projects/​packages/​premium-analytics/​routes/​reports/​locations/​config/​fields.tsx Adds coordinates to report row types.
projects/​packages/​premium-analytics/​routes/​reports/​locations/​config/​aggregate.ts Preserves coordinates during aggregation.
projects/​packages/​premium-analytics/​packages/​widgets-toolkit/​src/​components/​report-page/​report-locations-map.tsx Updates map guidance text.
projects/​packages/​premium-analytics/​packages/​widgets-toolkit/​src/​components/​locations-geo-chart/​locations-geo-chart.tsx Supplies marker mode to GeoChart.
projects/​packages/​premium-analytics/​packages/​widgets-toolkit/​src/​components/​locations-geo-chart/​build-geo-data.ts Builds marker and regional data; marker value ordering needs correction.
projects/​packages/​premium-analytics/​packages/​widgets-toolkit/​src/​components/​locations-geo-chart/​__tests__/​build-geo-data.test.ts Tests marker data and filtering.
projects/​packages/​premium-analytics/​packages/​data/​src/​processing/​stats/​locations.ts Parses coordinate data.
projects/​packages/​premium-analytics/​packages/​data/​src/​processing/​stats/​index.ts Exports coordinate types.
projects/​packages/​premium-analytics/​packages/​data/​src/​processing/​stats/​__tests__/​locations.test.ts Tests coordinate normalization.
projects/​packages/​premium-analytics/​packages/​data/​src/​index.ts Re-exports coordinate types.
projects/​packages/​premium-analytics/​changelog/​uni-828-city-map-markers Adds the package changelog entry.
projects/​js-packages/​charts/​src/​index.ts Exports GeoDisplayMode.
projects/​js-packages/​charts/​src/​charts/​geo-chart/​types.ts Defines the marker display-mode API.
projects/​js-packages/​charts/​src/​charts/​geo-chart/​test/​geo-chart.test.tsx Tests marker option forwarding.
projects/​js-packages/​charts/​src/​charts/​geo-chart/​stories/​index.api.mdx Documents the new prop; needs a focused marker story and usage guidance.
projects/​js-packages/​charts/​src/​charts/​geo-chart/​index.ts Re-exports the new type.
projects/​js-packages/​charts/​src/​charts/​geo-chart/​geo-chart.tsx Applies marker display options.
projects/​js-packages/​charts/​changelog/​uni-828-city-map-markers Adds the Charts package changelog entry.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Nikschavan
Nikschavan marked this pull request as ready for review September 28, 2026 10:47
@Nikschavan
Nikschavan requested a review from a team as a code owner September 28, 2026 10:47
@Nikschavan Nikschavan added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 28, 2026

@louwie17 louwie17 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.

Thanks @Nikschavan, this tested well and code looks good! I bet users will be happy with this update, it seems to be one of the main requested items in the feedback. I also tested this with some larger numbers and it all looked good.

I did leave one small inline comment, but it's not a blocker. LGTM 🚀

GeoChartProps,
GeoRegion,
GeoResolution,
GeoDisplayMode,

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.

Do we need to export GeoDisplayMode? Nothing imports it, and build-geo-data.ts writes out 'regions' | 'markers' inline anyway. So we should either use it there or keep it internal, GeoChartProps['displayMode'] covers any outside callers. Small nit, happy to ignore this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you. I went with using it: #53016 re-exports GeoDisplayMode through externals and uses it in buildLocationsGeoChart in place of the inline union. I kept the export because the type already shipped in Charts 4.6.0 and it names a value that is already part of GeoChartProps.

@Nikschavan
Nikschavan merged commit 8327a77 into trunk Sep 29, 2026
172 of 173 checks passed
@Nikschavan
Nikschavan deleted the uni-828-location-map-does-not-change-based-on-the-city-selector branch September 29, 2026 03:56
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Charts [Package] Premium Analytics RNA [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants