Skip to content
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

feat(web-analytics): Display visits by language #26432

Merged
merged 7 commits into from
Nov 27, 2024

Conversation

rafaeelaudibert
Copy link
Member

@rafaeelaudibert rafaeelaudibert commented Nov 26, 2024

Warning

We need to wait for #26409 because I've fixed some sorting issues during tests in that PR

This is doing some magic to filter by language. It's taking the browser language and then moving on to get just the language from the locale (i.e. pt from pt-BR). Because we want to be smart with the flags, however, we are collecting the country with the most views out of them. This should guarantee that people will see a British flag for en if most of their userbase is in the UK or an American flag if it's in America (or India, Nigeria, Australia, etc.)

Closes #26376

Changes

image

Does this work well for both Cloud and self-hosted?

Yep

How did you test this code?

Manually + unit tests on the new language code.

const parsedCountryCode = countryCode?.match(/([A-Z]{2})/)?.[0] ?? ''
return (
<>
{countryCodeToFlag(parsedCountryCode)}&nbsp;
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a fallbackFlag(language), it doesn't need many entries, but would have nl

Copy link
Member Author

Choose a reason for hiding this comment

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

I've only added nl because it's probably the most impactful one that hasn't got any followups (Germany would be too, but there's de-DE and de-AT, and Poland seems to always be pl-PL)

Copy link
Member Author

Choose a reason for hiding this comment

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

Once we have this running in prod I can go back and check if there's any obvious offender here

This is doing some magic to filter by language. It's taking the browser language and then moving on to get just the language from the locale (i.e. pt from pt-BR). Because we want to be smart with the flags, however, we are collecting the country with the most views out of them. This should guarantee that people will see a British flag for en if most of their userbase is in the UK or an American flag if it's in America (or India, Nigeria, Australia, etc.)

There's still a small bug where filtering won't work if you simply click on the row, that needs to be updated.

See #26376
@rafaeelaudibert rafaeelaudibert force-pushed the 26376-add-filter-by-language branch from 6ad1fc1 to 30b9a1e Compare November 26, 2024 16:29
@rafaeelaudibert rafaeelaudibert changed the title feat(web-analytics) Display visits by language feat(web-analytics): Display visits by language Nov 26, 2024
Copy link
Contributor

github-actions bot commented Nov 26, 2024

Size Change: 0 B

Total Size: 1.16 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.16 MB

compressed-size-action

# which is causing this to be flaky (en-GB happens sometimes),
# we'll instead assert on a reduced form where we're
# not counting the country, but only the locale
# assert results == [["en-US", 1.0, 3.0], ["pt-BR", 1.0, 2.0], ["nl-", 1.0, 1.0]]
Copy link
Member Author

Choose a reason for hiding this comment

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

@rafaeelaudibert rafaeelaudibert enabled auto-merge (squash) November 26, 2024 17:50
@rafaeelaudibert rafaeelaudibert merged commit 1a8fd27 into master Nov 27, 2024
100 checks passed
@rafaeelaudibert rafaeelaudibert deleted the 26376-add-filter-by-language branch November 27, 2024 12:13
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.

Add language and timezone to the web analytics Geo tab
2 participants