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.

convert attribution report

Francis Cao9cc717f0546f
diff --git a/db/clickhouse/schema.sql b/db/clickhouse/schema.sql
index ff85112ba..396d300aa 100644
--- a/db/clickhouse/schema.sql
+++ b/db/clickhouse/schema.sql
@@ -277,7 +277,7 @@ SELECT DISTINCT
ed.created_at
FROM umami.event_data ed
JOIN (SELECT event_id, string_value as currency
- FROM event_data
+ FROM umami.event_data
WHERE positionCaseInsensitive(data_key, 'currency') > 0) c
ON c.event_id = ed.event_id
WHERE positionCaseInsensitive(data_key, 'revenue') > 0;
diff --git a/src/queries/sql/reports/getAttribution.ts b/src/queries/sql/reports/getAttribution.ts
index 0c3d447a3..f224eb5ce 100644
--- a/src/queries/sql/reports/getAttribution.ts
+++ b/src/queries/sql/reports/getAttribution.ts
@@ -311,21 +311,14 @@ async function clickhouseQuery(
const revenueEventQuery = `WITH events AS (
select
- ed.session_id,
- max(ed.created_at) max_dt,
- sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as value
- from event_data ed
- join (select event_id
- from event_data
- where website_id = {websiteId:UUID}
- and created_at between {startDate:DateTime64} and {endDate:DateTime64}
- and positionCaseInsensitive(data_key, 'currency') > 0
- and string_value = {currency:String}) c
- on c.event_id = ed.event_id
+ session_id,
+ max(created_at) max_dt,
+ sum(revenue) as value
+ from website_revenue
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
- and ${column} = {conversionStep:String}
- and positionCaseInsensitive(ed.data_key, 'revenue') > 0
+ and ${column} = {conversionStep:String}
+ and currency = {currency:String}
group by 1),`;
function getModelQuery(model: string) {