Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Handle country data for regions and cities.
Mike Cao684587f94589
diff --git a/src/components/metrics/CitiesTable.js b/src/components/metrics/CitiesTable.jsindex 86b7f07a7..ee11e6765 100644--- a/src/components/metrics/CitiesTable.js+++ b/src/components/metrics/CitiesTable.js@@ -22,9 +22,7 @@ export function CitiesTable({ websiteId, ...props }) {<FilterLink id="city" value={city} label={renderLabel(city, country)}>{country && (<img- src={`${basePath}/images/flags/${- country?.split?.('-')?.[0]?.toLowerCase() || 'xx'- }.png`}+ src={`${basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}alt={country}/>)}diff --git a/src/components/metrics/RegionsTable.js b/src/components/metrics/RegionsTable.jsindex 2e260e41d..c2ee9b3f8 100644--- a/src/components/metrics/RegionsTable.js+++ b/src/components/metrics/RegionsTable.js@@ -13,17 +13,15 @@ export function RegionsTable({ websiteId, ...props }) {const countryNames = useCountryNames(locale);const { basePath } = useRouter();- const renderLabel = x => {- return regions[x] ? `${regions[x]}, ${countryNames[x.split('-')[0]]}` : x;+ const renderLabel = (code, country) => {+ const region = code.includes('-') ? code : `${country}-${code}`;+ return regions[region] ? `${regions[region]}, ${countryNames[country]}` : region;};- const renderLink = ({ x: code }) => {+ const renderLink = ({ x: code, country }) => {return (- <FilterLink id="region" className={locale} value={code} label={renderLabel(code)}>- <img- src={`${basePath}/images/flags/${code?.split('-')?.[0]?.toLowerCase() || 'xx'}.png`}- alt={code}- />+ <FilterLink id="region" className={locale} value={code} label={renderLabel(code, country)}>+ <img src={`${basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`} alt={code} /></FilterLink>);};diff --git a/src/queries/analytics/sessions/getSessionMetrics.ts b/src/queries/analytics/sessions/getSessionMetrics.tsindex 1aad5c899..af358c525 100644--- a/src/queries/analytics/sessions/getSessionMetrics.ts+++ b/src/queries/analytics/sessions/getSessionMetrics.ts@@ -25,13 +25,14 @@ async function relationalQuery(websiteId: string, column: string, filters: QueryjoinSession: SESSION_COLUMNS.includes(column),},);+ const includeCountry = column === 'city' || column === 'subdivision1';return rawQuery(`select${column} x,count(*) y- ${column === 'city' ? ', country' : ''}+ ${includeCountry ? ', country' : ''}from website_event${joinSession}where website_event.website_id = {{websiteId::uuid}}@@ -39,7 +40,7 @@ async function relationalQuery(websiteId: string, column: string, filters: Queryand website_event.event_type = {{eventType}}${filterQuery}group by 1- ${column === 'city' ? ', 3' : ''}+ ${includeCountry ? ', 3' : ''}order by 2 desclimit 100`,params,@@ -52,20 +53,21 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query...filters,eventType: EVENT_TYPE.pageView,});+ const includeCountry = column === 'city' || column === 'subdivision1';return rawQuery(`select${column} x,count(distinct session_id) y- ${column === 'city' ? ', country' : ''}+ ${includeCountry ? ', country' : ''}from website_eventwhere website_id = {websiteId:UUID}and created_at between {startDate:DateTime} and {endDate:DateTime}and event_type = {eventType:UInt32}${filterQuery}group by x- ${column === 'city' ? ', country' : ''}+ ${includeCountry ? ', country' : ''}order by y desclimit 100`,