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.

remove dropoff calc from db query

Francis Cao711ad2bbcfdb
diff --git a/components/metrics/DataTable.js b/components/metrics/DataTable.js
index 9c5fb5590..e2e9462df 100644
--- a/components/metrics/DataTable.js
+++ b/components/metrics/DataTable.js
@@ -78,7 +78,7 @@ const AnimatedRow = ({
showPercentage = true,
}) => {
const props = useSpring({
- width: Number(percent),
+ width: percent,
y: value,
from: { width: 0, y: 0 },
config: animate ? config.default : { duration: 0 },
diff --git a/lib/prisma.ts b/lib/prisma.ts
index 722535c2c..85dc25b89 100644
--- a/lib/prisma.ts
+++ b/lib/prisma.ts
@@ -44,18 +44,6 @@ function getAddMinutesQuery(field: string, minutes: number) {
}
}
-function getDropoffQuery() {
- const db = getDatabaseType(process.env.DATABASE_URL);
-
- if (db === POSTGRESQL) {
- return `round((1.0 - count::numeric/lag(nullif(count, 0), 1) over ()),2) * 100`;
- }
-
- if (db === MYSQL) {
- return `round((1.0 - count/LAG(nullif(count, 0), 1) OVER (ORDER BY level)),2) * 100`;
- }
-}
-
function getDateQuery(field: string, unit: string, timezone?: string): string {
const db = getDatabaseType(process.env.DATABASE_URL);
@@ -217,15 +205,12 @@ async function rawQuery(query: string, params: never[] = []): Promise<any> {
const sql = db === MYSQL ? query.replace(/\$[0-9]+/g, '?') : query;
- // console.log(sql);
- // console.log(params);
return prisma.rawQuery(sql, params);
}
export default {
...prisma,
getAddMinutesQuery,
- getDropoffQuery,
getDateQuery,
getTimestampInterval,
getFilterQuery,
diff --git a/queries/analytics/pageview/getPageviewFunnel.ts b/queries/analytics/pageview/getPageviewFunnel.ts
index b7d918b92..422338da1 100644
--- a/queries/analytics/pageview/getPageviewFunnel.ts
+++ b/queries/analytics/pageview/getPageviewFunnel.ts
@@ -35,7 +35,7 @@ async function relationalQuery(
}[]
> {
const { windowMinutes, startDate, endDate, urls } = criteria;
- const { rawQuery, getFunnelQuery, toUuid, getDropoffQuery } = prisma;
+ const { rawQuery, getFunnelQuery, toUuid } = prisma;
const { levelQuery, sumQuery, urlFilterQuery } = getFunnelQuery(urls, windowMinutes);
const params: any = [websiteId, startDate, endDate, ...urls];
@@ -47,25 +47,19 @@ async function relationalQuery(
where url_path in (${urlFilterQuery})
and website_id = $1${toUuid()}
and created_at between $2 and $3
- ),level1 AS (
- select distinct session_id, created_at
- from level0
- where url_path = $4
- )${levelQuery}, levelCount as (
- ${sumQuery}
- order by level)
- select
- level,
- count,
- ${getDropoffQuery()} as drop_off
- from levelCount;
- `,
+ ),level1 AS (
+ select distinct session_id, created_at
+ from level0
+ where url_path = $4
+ )${levelQuery}
+ ${sumQuery}
+ ORDER BY level;`,
params,
).then(results => {
return urls.map((a, i) => ({
x: a,
y: results[i]?.count || 0,
- z: results[i]?.drop_off || 0,
+ z: (1 - (Number(results[i]?.count) * 1.0) / Number(results[i - 1]?.count)) * 100 || 0, // drop off
}));
});
}
@@ -96,7 +90,7 @@ async function clickhouseQuery(
return rawQuery<{ level: number; count: number }[]>(
`
- select level,
+ WITH funnel as (select level,
count(*) AS count
from (
select session_id,
@@ -111,13 +105,15 @@ async function clickhouseQuery(
group by 1
)
group by level
- order by level asc;
+ order by level asc)
+ select * from funnel where level > 0;
`,
params,
).then(results => {
return urls.map((a, i) => ({
x: a,
- y: results[i + 1]?.count || 0,
+ y: results[i]?.count || 0,
+ z: (1 - (Number(results[i]?.count) * 1.0) / Number(results[i - 1]?.count)) * 100 || 0, // drop off
}));
});
}