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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Merge branch 'dev' into jajaja
Mike Caob2aa37a3df7f
diff --cc db/postgresql/schema.prismaindex 6733bca6a,cf824f79a..67889196f--- a/db/postgresql/schema.prisma+++ b/db/postgresql/schema.prisma@@@ -249,3 -249,23 +252,23 @@@ model Segment@@index([websiteId])@@map("segment")}++ model Revenue {+ id String @id() @unique() @map("revenue_id") @db.Uuid+ websiteId String @map("website_id") @db.Uuid+ sessionId String @map("session_id") @db.Uuid+ eventId String @map("event_id") @db.Uuid+ eventName String @map("event_name") @db.VarChar(50)+ currency String @db.VarChar(100)+ revenue Decimal? @db.Decimal(19, 4)+ createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)++ website Website @relation(fields: [websiteId], references: [id])+ session Session @relation(fields: [sessionId], references: [id])++ @@index([websiteId])+ @@index([sessionId])+ @@index([websiteId, createdAt])+ @@index([websiteId, sessionId, createdAt])+ @@map("revenue")-}++}diff --cc src/queries/sql/reports/getRevenue.tsindex 49d46a1f8,8f4855cce..ae9670f6b--- a/src/queries/sql/reports/getRevenue.ts+++ b/src/queries/sql/reports/getRevenue.ts@@@ -38,22 -48,13 +38,13 @@@ async function relationalQueryconst chartRes = await rawQuery(`select- we.event_name x,- ${getDateSQL('ed.created_at', unit)} t,- sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) y- from event_data ed- join website_event we- on we.event_id = ed.website_event_id- join (select website_event_id- from event_data- where website_id = {{websiteId::uuid}}- and created_at between {{startDate}} and {{endDate}}- and data_key ${like} '%currency%'- and string_value = {{currency}}) currency- on currency.website_event_id = ed.website_event_id- where ed.website_id = {{websiteId::uuid}}- and ed.created_at between {{startDate}} and {{endDate}}- and ed.data_key ${like} '%revenue%'+ event_name x,- ${getDateSQL('created_at', unit, timezone)} t,++ ${getDateSQL('created_at', unit)} t,+ sum(revenue) y+ from revenue+ where website_id = {{websiteId::uuid}}+ and created_at between {{startDate}} and {{endDate}}+ and currency ${like} {{currency}}group by x, torder by t`,@@@ -111,26 -94,17 +84,17 @@@const tableRes = await rawQuery(`select- c.currency,- sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,- count(distinct ed.website_event_id) as count,- count(distinct we.session_id) as unique_count- from event_data ed- join website_event we- on we.event_id = ed.website_event_id- join (select website_event_id, string_value as currency- from event_data- where website_id = {{websiteId::uuid}}- and created_at between {{startDate}} and {{endDate}}- and data_key ${like} '%currency%') c- on c.website_event_id = ed.website_event_id- where ed.website_id = {{websiteId::uuid}}- and ed.created_at between {{startDate}} and {{endDate}}- and ed.data_key ${like} '%revenue%'- group by c.currency- order by sum desc;+ currency,+ sum(revenue) as sum,+ count(distinct event_id) as count,+ count(distinct session_id) as unique_count+ from revenue r+ where website_id = {{websiteId::uuid}}+ and created_at between {{startDate}} and {{endDate}}+ group by currency+ order by sum desc`,- { websiteId, startDate, endDate, unit, timezone, currency },+ { websiteId, startDate, endDate, unit, currency },);return { chart: chartRes, country: countryRes, total: totalRes, table: tableRes };