diff --git a/src/components/metrics/CitiesTable.js b/src/components/metrics/CitiesTable.js index 86b7f07a..ee11e676 100644 --- a/src/components/metrics/CitiesTable.js +++ b/src/components/metrics/CitiesTable.js @@ -22,9 +22,7 @@ export function CitiesTable({ websiteId, ...props }) { {country && ( {country} )} diff --git a/src/components/metrics/RegionsTable.js b/src/components/metrics/RegionsTable.js index 2e260e41..c2ee9b3f 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 ( - - {code} + + {code} ); }; diff --git a/src/queries/analytics/sessions/getSessionMetrics.ts b/src/queries/analytics/sessions/getSessionMetrics.ts index 1aad5c89..af358c52 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: Query joinSession: 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: Query and website_event.event_type = {{eventType}} ${filterQuery} group by 1 - ${column === 'city' ? ', 3' : ''} + ${includeCountry ? ', 3' : ''} order by 2 desc limit 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_event where 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 desc limit 100 `,