Merge branch 'dev' into analytics

This commit is contained in:
Mike Cao 2023-08-27 23:31:19 -07:00
commit ff0dc45c0d
3 changed files with 13 additions and 15 deletions

View File

@ -22,9 +22,7 @@ export function CitiesTable({ websiteId, ...props }) {
<FilterLink id="city" value={city} label={renderLabel(city, country)}> <FilterLink id="city" value={city} label={renderLabel(city, country)}>
{country && ( {country && (
<img <img
src={`${basePath}/images/flags/${ src={`${basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
country?.split?.('-')?.[0]?.toLowerCase() || 'xx'
}.png`}
alt={country} alt={country}
/> />
)} )}

View File

@ -13,17 +13,15 @@ export function RegionsTable({ websiteId, ...props }) {
const countryNames = useCountryNames(locale); const countryNames = useCountryNames(locale);
const { basePath } = useRouter(); const { basePath } = useRouter();
const renderLabel = x => { const renderLabel = (code, country) => {
return regions[x] ? `${regions[x]}, ${countryNames[x.split('-')[0]]}` : x; 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 ( return (
<FilterLink id="region" className={locale} value={code} label={renderLabel(code)}> <FilterLink id="region" className={locale} value={code} label={renderLabel(code, country)}>
<img <img src={`${basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`} alt={code} />
src={`${basePath}/images/flags/${code?.split('-')?.[0]?.toLowerCase() || 'xx'}.png`}
alt={code}
/>
</FilterLink> </FilterLink>
); );
}; };

View File

@ -25,13 +25,14 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
joinSession: SESSION_COLUMNS.includes(column), joinSession: SESSION_COLUMNS.includes(column),
}, },
); );
const includeCountry = column === 'city' || column === 'subdivision1';
return rawQuery( return rawQuery(
` `
select select
${column} x, ${column} x,
count(*) y count(*) y
${column === 'city' ? ', country' : ''} ${includeCountry ? ', country' : ''}
from website_event from website_event
${joinSession} ${joinSession}
where website_event.website_id = {{websiteId::uuid}} 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}} and website_event.event_type = {{eventType}}
${filterQuery} ${filterQuery}
group by 1 group by 1
${column === 'city' ? ', 3' : ''} ${includeCountry ? ', 3' : ''}
order by 2 desc order by 2 desc
limit 100`, limit 100`,
params, params,
@ -52,20 +53,21 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query
...filters, ...filters,
eventType: EVENT_TYPE.pageView, eventType: EVENT_TYPE.pageView,
}); });
const includeCountry = column === 'city' || column === 'subdivision1';
return rawQuery( return rawQuery(
` `
select select
${column} x, ${column} x,
count(distinct session_id) y count(distinct session_id) y
${column === 'city' ? ', country' : ''} ${includeCountry ? ', country' : ''}
from website_event from website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime} and {endDate:DateTime} and created_at between {startDate:DateTime} and {endDate:DateTime}
and event_type = {eventType:UInt32} and event_type = {eventType:UInt32}
${filterQuery} ${filterQuery}
group by x group by x
${column === 'city' ? ', country' : ''} ${includeCountry ? ', country' : ''}
order by y desc order by y desc
limit 100 limit 100
`, `,