Skip to content

Stats: Update the stats map in Odyssey stats to match the map in Calypso #103822

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

Merged
merged 6 commits into from
Jun 3, 2025

Conversation

Nikschavan
Copy link
Contributor

@Nikschavan Nikschavan commented May 30, 2025

Part of #

Proposed Changes

  • Use useGeoLocationQuery() hook to fetch the current user location as a fallback if getCurrentUserCountryCode() does not return the country code
  • On Odyssey getCurrentUserCountryCode() does not have the value as the current user is not set there and on Odyssey user's could not have a WordPress.com account even
  • Google charts update the map per user's location

Why are these changes being made?

  • Match the Stats geo map on Calypso and Odyssey

Testing Instructions

  • View the map in Odyssey and Calypso; the map should match

Before in Odyssey, when India is viewed from India

image

After

image

The map matches the Calypso map, where user country code is available from getCurrentUserCountryCode()

Arc -2025-05-30 at 09 00 04@2x

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

Copy link

github-actions bot commented May 30, 2025

@Nikschavan Nikschavan requested review from a team and Copilot May 30, 2025 03:31
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 30, 2025
@matticbot
Copy link
Contributor

matticbot commented May 30, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~205 bytes added 📈 [gzipped])

name   parsed_size           gzip_size
stats       +526 B  (+0.0%)     +205 B  (+0.1%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@Nikschavan Nikschavan added the [Feature] Stats Everything related to our analytics product at /stats/ label May 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fetch the user’s country code via a geolocation hook as a fallback when getCurrentUserCountryCode() returns nothing, so the Stats geo map on Odyssey matches Calypso.

  • Import and use useGeoLocationQuery and useSelector to retrieve a fallback country code.
  • Wrap the existing StatsGeochart in StatsGeochartWrapper, computing finalCountryCode from user or geo data.
  • Change the default export to the new wrapper component.
Comments suppressed due to low confidence (2)

client/my-sites/stats/geochart/index.jsx:503

  • [nitpick] The variable name geoLocationReady suggests a boolean flag but actually holds a country code string or false. Consider renaming it to fallbackCountryCode for clarity.
const geoLocationReady = ! isGeoLocationLoading && geoCountryCode;

client/my-sites/stats/geochart/index.jsx:497

  • The new fallback logic via useGeoLocationQuery isn’t covered by existing tests. Adding tests for scenarios when currentUserCountryCode is missing will ensure correct behavior.
const StatsGeochartWrapper = ( props ) => {

@@ -491,3 +493,17 @@ export default connect( ( state, ownProps ) => {
statType,
};
} )( localize( StatsGeochart ) );

const StatsGeochartWrapper = ( props ) => {
Copy link
Preview

Copilot AI May 30, 2025

Choose a reason for hiding this comment

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

[nitpick] StatsGeochartWrapper isn’t documented with PropTypes or a displayName. Adding PropTypes and setting StatsGeochartWrapper.displayName would improve clarity in tooling and future maintenance.

Copilot uses AI. Check for mistakes.

@matticbot
Copy link
Contributor

matticbot commented May 30, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug odyssey-geo-map-location on your sandbox.

@Nikschavan Nikschavan changed the title Stats: Fetch location for the user when displaying the map Stats: Match stats map in Odyssey stats to Calypso May 30, 2025
@Nikschavan Nikschavan added the [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account label May 30, 2025
@Nikschavan Nikschavan changed the title Stats: Match stats map in Odyssey stats to Calypso Stats: Update the stats map in Odyssey stats to match the map in Calypso May 30, 2025
Copy link
Contributor

@kangzj kangzj left a comment

Choose a reason for hiding this comment

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

Good catch and nice fix! LGTM 👍

@Nikschavan Nikschavan merged commit 130b4a9 into trunk Jun 3, 2025
11 checks passed
@Nikschavan Nikschavan deleted the odyssey-geo-map-location branch June 3, 2025 04:24
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Stats Everything related to our analytics product at /stats/ [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants