Skip to content

🎨 Improved y-axis scaling and country names in Analytics#28708

Open
peterzimon wants to merge 4 commits into
mainfrom
NY-1365/analytics-ui-improvements
Open

🎨 Improved y-axis scaling and country names in Analytics#28708
peterzimon wants to merge 4 commits into
mainfrom
NY-1365/analytics-ui-improvements

Conversation

@peterzimon

@peterzimon peterzimon commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Newsletter chart y-axis scaling

The Avg. click rate chart on Analytics → Newsletters used a fixed-step rounding (nearest 0.1) for its y-axis, which snapped the upper bound to 10% even when the click rate was a fraction of a percent — making sub-1% bars effectively invisible.

This change brackets the y-axis to the actual data:

  • < 1%0% – 1%
  • 1% – 10%0% to the next whole percent above the max
  • 10% – 100%0% to the next multiple of 10 above the max

The avg reference line value is included in the bracket pick, so the dashed avg line is always inside the visible range (previously it could fall outside and be hidden).

Examples:

Max value Old upper New upper
0.4% 10% 1%
3.2% 10% 4%
9.2% 10% 10%
28% 30% 30%
36% 40% 40%

Country names in Web analytics

The Locations card used to render the official ISO country names from i18n-iso-countries ("Russian Federation", "Taiwan, Province of China", "Korea, Republic of"…), which read awkwardly. We now ask the library for the short/common form via getName(code, 'en', {select: 'alias'}) and add a few manual overrides for countries where the library has no alias. Net result:

  • Russian Federation → Russia
  • People's Republic of China → China
  • Taiwan, Province of China → Taiwan
  • Islamic Republic of Iran → Iran
  • Korea, Republic of → South Korea
  • United States of America → United States
  • United Kingdom → UK
  • Viet Nam → Vietnam
  • Czech Republic → Czechia
  • Lao People's Democratic Republic → Laos
  • Moldova, Republic of → Moldova
  • Syrian Arab Republic → Syria
  • …plus a handful of similar tidy-ups

ref https://linear.app/tryghost/issue/NY-1365/

Test plan

  • Open Analytics → Newsletters on a site with a sub-1% avg click rate; verify the y-axis runs 0%–1% and bars are visible
  • Confirm the Avg. open rate chart still looks right at typical 20–40% values (0%–30%, 0%–40%)
  • Hover bars and confirm the tooltip still shows the right numbers
  • Confirm the dashed avg line is visible and lands at the correct height
  • Open Analytics → Web traffic and check the Locations card / country filter — names should be the short form (Russia, China, Taiwan, South Korea, etc.)

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20c6ee1a-b1e3-4fab-beb9-c731a6a603c5

📥 Commits

Reviewing files that changed from the base of the PR and between 5be0c82 and 79a8c4e.

📒 Files selected for processing (3)
  • apps/posts/src/utils/constants.ts
  • apps/posts/src/views/PostAnalytics/Web/components/locations.tsx
  • apps/posts/src/views/PostAnalytics/components/stats-filter.tsx
✅ Files skipped from review due to trivial changes (1)
  • apps/posts/src/utils/constants.ts

Walkthrough

Two parallel display fixes across the stats and posts apps, plus a newsletter chart refinement. The STATS_LABEL_MAPPINGS country override section in both apps removes US, TWN, TW, and CN entries and adds GB, KR, LA, MD, and SY. All getCountryName helper functions (in stats locations-card.tsx, stats-filter.tsx, posts Web locations.tsx, and posts PostAnalytics stats-filter.tsx) now pass {select: 'alias'} to countries.getName, changing which display name is returned for a given country code. Separately, the newsletter bar chart y-axis calculation is updated to include the active tab's average reference line value (avgOpenRate or avgClickRate) when computing the maximum bound, then applies threshold-based bucketing to derive finalMax, replacing the previous min/max rounding approach.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the two main changes: improved y-axis scaling for newsletter charts and improved country name display in analytics.
Description check ✅ Passed The description provides detailed context for both changes, including specific examples, rationale, and testing instructions that align with the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch NY-1365/analytics-ui-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 18, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit d98794b

Command Status Duration Result
nx build @tryghost/activitypub ✅ Succeeded 1s View ↗
nx build @tryghost/announcement-bar ✅ Succeeded <1s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/sodo-search ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
nx run-many -t test:unit -p @tryghost/posts,@tr... ✅ Succeeded 2m 54s View ↗
Additional runs (5) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-22 15:54:12 UTC

@peterzimon peterzimon force-pushed the NY-1365/analytics-ui-improvements branch from 24c00a6 to 5bcbe42 Compare June 22, 2026 08:05
ref https://linear.app/tryghost/issue/NY-1365/

- the Avg. click rate chart used a fixed-step rounding that snapped the upper bound up to 10%, making sub-1% rates render as invisible bars
- bracket the y-axis to the data: <1% → 0–1%, 1–10% → 0 to the next whole percent, 10%+ → 0 to the next multiple of 10
- include the avg reference line in the bracket pick so it's always inside the visible range
ref https://linear.app/tryghost/issue/NY-1365/

- the Locations card and country filter showed the official ISO names from i18n-iso-countries ("Russian Federation", "Taiwan, Province of China", "Korea, Republic of", etc.), which read awkwardly
- switched the library lookup to {select: 'alias'} so the short/common form is returned when one exists (Russia, China, Taiwan, Iran, Vietnam, Czechia, United States, …)
- added explicit overrides for entries where i18n-iso-countries has no alias or its alias picks the wrong form: GB → United Kingdom, KR → South Korea, LA → Laos, MD → Moldova, SY → Syria
- dropped the now-redundant US/TW/TWN entries from STATS_LABEL_MAPPINGS
@peterzimon peterzimon force-pushed the NY-1365/analytics-ui-improvements branch from 5bcbe42 to 5be0c82 Compare June 22, 2026 08:06
@peterzimon peterzimon changed the title 🎨 Improved y-axis scaling on Newsletter analytics charts 🎨 Improved y-axis scaling and country names in Analytics Jun 22, 2026
@peterzimon peterzimon marked this pull request as ready for review June 22, 2026 08:10
peterzimon and others added 2 commits June 22, 2026 17:32
ref https://linear.app/tryghost/issue/NY-1365/

- mirrored the cleanup from the Web analytics PR (#28708) in the Post analytics web tab: the Locations card and the country filter showed the official ISO names from i18n-iso-countries ("Russian Federation", "Taiwan, Province of China", …)
- switched the library lookup to {select: 'alias'} so the short/common form is returned when one exists
- added the same explicit overrides for entries where i18n-iso-countries has no alias or picks the wrong form: GB → United Kingdom, KR → South Korea, LA → Laos, MD → Moldova, SY → Syria
- dropped the now-redundant US/TW/TWN/CN entries from the posts app's STATS_LABEL_MAPPINGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants