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)}>
{country && (
<img
src={`${basePath}/images/flags/${
country?.split?.('-')?.[0]?.toLowerCase() || 'xx'
}.png`}
src={`${basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
alt={country}
/>
)}

View File

@ -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>
);
};

View File

@ -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
`,