Skip to content

armgit / umami

Public Imported from GitHub
0

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.

Get properties for sessions within date range.

Mike Cao020cfdc646e5
diff --git a/src/components/hooks/queries/useSessionDataProperties.ts b/src/components/hooks/queries/useSessionDataProperties.ts
index 45590b390..ca3798f02 100644
--- a/src/components/hooks/queries/useSessionDataProperties.ts
+++ b/src/components/hooks/queries/useSessionDataProperties.ts
@@ -10,7 +10,7 @@ export function useSessionDataProperties(
const params = useFilterParams(websiteId);
return useQuery<any>({
- queryKey: ['websites:event-data:properties', { websiteId, ...params }],
+ queryKey: ['websites:session-data:properties', { websiteId, ...params }],
queryFn: () => get(`/websites/${websiteId}/session-data/properties`, { ...params }),
enabled: !!websiteId,
...options,
diff --git a/src/queries/sql/sessions/getSessionDataProperties.ts b/src/queries/sql/sessions/getSessionDataProperties.ts
index da02c97e2..bfa6a2699 100644
--- a/src/queries/sql/sessions/getSessionDataProperties.ts
+++ b/src/queries/sql/sessions/getSessionDataProperties.ts
@@ -24,13 +24,16 @@ async function relationalQuery(
return rawQuery(
`
select
- data_key as "propertyName",
- count(*) as "total"
- from session_data
- where website_id = {{websiteId::uuid}}
- and created_at between {{startDate}} and {{endDate}}
- ${filterQuery}
- group by data_key
+ data_key as "propertyName",
+ count(*) as "total"
+ from website_event e
+ left join session_data d
+ on d.session_id = e.session_id
+ where e.website_id = {{websiteId:uuid}}
+ and e.created_at between {{startDate}} and {{endDate}}
+ and d.data_key is not null
+ ${filterQuery}
+ group by 1
order by 2 desc
limit 500
`,
@@ -52,11 +55,14 @@ async function clickhouseQuery(
select
data_key as propertyName,
count(*) as total
- from session_data final
- where website_id = {websiteId:UUID}
- and created_at between {startDate:DateTime64} and {endDate:DateTime64}
+ from website_event e
+ left join session_data d
+ on d.session_id = e.session_id
+ where e.website_id = {websiteId:UUID}
+ and e.created_at between {startDate:DateTime64} and {endDate:DateTime64}
+ and d.data_key != ''
${filterQuery}
- group by data_key
+ group by 1
order by 2 desc
limit 500
`,