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
All queries should use runQuery.
Mike Caoe79199075028
diff --git a/lib/queries.js b/lib/queries.jsindex 204b545bb..5b30c0a9c 100644--- a/lib/queries.js+++ b/lib/queries.js@@ -252,8 +252,9 @@ export function getMetrics(website_id, start_at, end_at) {const db = getDatabase();if (db === POSTGRESQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select sum(t.c) as "pageviews",count(distinct t.session_id) as "uniques",sum(case when t.c = 1 then 1 else 0 end) as "bounces",@@ -269,15 +270,17 @@ export function getMetrics(website_id, start_at, end_at) {group by 1, 2) t`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}if (db === MYSQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select sum(t.c) as "pageviews",count(distinct t.session_id) as "uniques",sum(case when t.c = 1 then 1 else 0 end) as "bounces",@@ -293,9 +296,10 @@ export function getMetrics(website_id, start_at, end_at) {group by 1, 2) t`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}@@ -313,8 +317,9 @@ export function getPageviews(const db = getDatabase();if (db === POSTGRESQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select ${getDateQuery(db, 'created_at', unit, timezone)} t,count(${count}) yfrom pageview@@ -323,15 +328,17 @@ export function getPageviews(group by 1order by 1`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}if (db === MYSQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select ${getDateQuery(db, 'created_at', unit, timezone)} t,count(${count}) yfrom pageview@@ -340,9 +347,10 @@ export function getPageviews(group by 1order by 1`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}@@ -355,8 +363,9 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {const filter = domain ? `and ${type} not like '%${domain}%'` : '';if (db === POSTGRESQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select distinct ${type} x, count(*) yfrom ${table}where website_id=$1@@ -365,15 +374,17 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {group by 1order by 2 desc`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}if (db === MYSQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select distinct ${type} x, count(*) yfrom ${table}where website_id=?@@ -382,9 +393,10 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {group by 1order by 2 desc`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}@@ -396,28 +408,32 @@ export function getActiveVisitors(website_id) {const date = subMinutes(new Date(), 5);if (db === POSTGRESQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select count(distinct session_id) xfrom pageviewwhere website_id=$1and created_at >= $2`,- website_id,- date,+ website_id,+ date,+ ),);}if (db === MYSQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `select count(distinct session_id) xfrom pageviewwhere website_id=?and created_at >= ?`,- website_id,- date,+ website_id,+ date,+ ),);}@@ -428,8 +444,9 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =const db = getDatabase();if (db === POSTGRESQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `selectevent_value x,${getDateQuery(db, 'created_at', unit, timezone)} t,@@ -440,15 +457,17 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =group by 1, 2order by 2`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}if (db === MYSQL) {- return prisma.$queryRaw(- `+ return runQuery(+ prisma.$queryRaw(+ `selectevent_value x,${getDateQuery(db, 'created_at', unit, timezone)} t,@@ -459,9 +478,10 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =group by 1, 2order by 2`,- website_id,- start_at,- end_at,+ website_id,+ start_at,+ end_at,+ ),);}