mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
add subdivision1/2, cities to query logic
This commit is contained in:
parent
6bacfa5892
commit
55a586fe27
16 changed files with 184 additions and 57 deletions
|
|
@ -115,6 +115,9 @@ function getFilterQuery(filters = {}, params = {}) {
|
|||
case 'os':
|
||||
case 'browser':
|
||||
case 'device':
|
||||
case 'subdivision1':
|
||||
case 'subdivision2':
|
||||
case 'city':
|
||||
case 'country':
|
||||
arr.push(`and ${key} = {${key}:String}`);
|
||||
params[key] = filter;
|
||||
|
|
@ -147,11 +150,24 @@ function getFilterQuery(filters = {}, params = {}) {
|
|||
}
|
||||
|
||||
function parseFilters(filters: any = {}, params: any = {}) {
|
||||
const { domain, url, eventUrl, referrer, os, browser, device, country, eventName, query } =
|
||||
filters;
|
||||
const {
|
||||
domain,
|
||||
url,
|
||||
eventUrl,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city,
|
||||
eventName,
|
||||
query,
|
||||
} = filters;
|
||||
|
||||
const pageviewFilters = { domain, url, referrer, query };
|
||||
const sessionFilters = { os, browser, device, country };
|
||||
const sessionFilters = { os, browser, device, country, subdivision1, subdivision2, city };
|
||||
const eventFilters = { url: eventUrl, eventName };
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -68,17 +68,17 @@ export async function getLocation(ip) {
|
|||
|
||||
const result = lookup.get(ip);
|
||||
const country = result?.country?.iso_code ?? result?.registered_country?.iso_code;
|
||||
const subdivision1 = result?.subdivisions[0].iso_code;
|
||||
const subdivision2 = result?.subdivisions[1].iso_code;
|
||||
const subdivision1 = result?.subdivisions[0]?.iso_code;
|
||||
const subdivision2 = result?.subdivisions[1]?.iso_code;
|
||||
const city = result?.city?.names?.en;
|
||||
|
||||
return { country, subdivision1, subdivision2, city };
|
||||
}
|
||||
|
||||
export async function getClientInfo(req, { screen }) {
|
||||
const location = await getLocation(ip);
|
||||
const userAgent = req.headers['user-agent'];
|
||||
const ip = getIpAddress(req);
|
||||
const location = await getLocation(ip);
|
||||
const country = location.country;
|
||||
const subdivision1 = location.subdivision1;
|
||||
const subdivision2 = location.subdivision2;
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ function getFilterQuery(filters = {}, params = []): string {
|
|||
case 'os':
|
||||
case 'browser':
|
||||
case 'device':
|
||||
case 'subdivision1':
|
||||
case 'subdivision2':
|
||||
case 'city':
|
||||
case 'country':
|
||||
arr.push(`and ${key}=$${params.length + 1}`);
|
||||
params.push(decodeURIComponent(filter));
|
||||
|
|
@ -171,11 +174,24 @@ function parseFilters(
|
|||
params = [],
|
||||
sessionKey = 'session_id',
|
||||
) {
|
||||
const { domain, url, eventUrl, referrer, os, browser, device, country, eventName, query } =
|
||||
filters;
|
||||
const {
|
||||
domain,
|
||||
url,
|
||||
eventUrl,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city,
|
||||
eventName,
|
||||
query,
|
||||
} = filters;
|
||||
|
||||
const pageviewFilters = { domain, url, referrer, query };
|
||||
const sessionFilters = { os, browser, device, country };
|
||||
const sessionFilters = { os, browser, device, country, subdivision1, subdivision2, city };
|
||||
const eventFilters = { url: eventUrl, eventName };
|
||||
|
||||
return {
|
||||
|
|
@ -184,7 +200,7 @@ function parseFilters(
|
|||
eventFilters,
|
||||
event: { eventName },
|
||||
joinSession:
|
||||
os || browser || device || country
|
||||
os || browser || device || country || subdivision1 || subdivision2 || city
|
||||
? `inner join session on website_event.${sessionKey} = session.${sessionKey}`
|
||||
: '',
|
||||
filterQuery: getFilterQuery(filters, params),
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ export async function findSession(req) {
|
|||
throw new Error(`Website not found: ${websiteId}`);
|
||||
}
|
||||
|
||||
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
||||
const { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device } =
|
||||
await getClientInfo(req, payload);
|
||||
const sessionId = uuid(websiteId, hostname, ip, userAgent);
|
||||
|
||||
// Clickhouse does not require session lookup
|
||||
|
|
@ -59,6 +60,9 @@ export async function findSession(req) {
|
|||
screen,
|
||||
language,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -84,6 +88,9 @@ export async function findSession(req) {
|
|||
screen,
|
||||
language,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city,
|
||||
});
|
||||
} catch (e) {
|
||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue