🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance BaseStandardSectionDialog and getSingleCol API for improved data metrics
Bill Yangc99068508c9a
diff --git a/client/src/app/[site]/components/shared/StandardSection/BaseStandardSectionDialog.tsx b/client/src/app/[site]/components/shared/StandardSection/BaseStandardSectionDialog.tsxindex dac960351..c2da692d7 100644--- a/client/src/app/[site]/components/shared/StandardSection/BaseStandardSectionDialog.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/BaseStandardSectionDialog.tsx@@ -106,13 +106,23 @@ export function BaseStandardSectionDialog({header: "Sessions",cell: (info) => (<div className="text-left flex flex-row gap-1 items-center">- {info.getValue().toLocaleString()} ({info.row.original.percentage}%)+ {info.getValue().toLocaleString()}+ </div>+ ),+ }),+ columnHelper.accessor("percentage", {+ header: "Session %",+ cell: (info) => (+ <div className="text-left flex flex-row gap-1 items-center">+ {info.getValue().toFixed(1)}%</div>),}),];- const hasPageviews = data?.[0]?.pageviews !== undefined;+ const hasPageviews =+ data?.[0]?.pageviews !== undefined &&+ data?.[0]?.pageviews_percentage !== undefined;if (hasPageviews) {cols.push(columnHelper.accessor("pageviews", {@@ -120,9 +130,16 @@ export function BaseStandardSectionDialog({cell: (info) => (<div className="text-left flex flex-row gap-1 items-center">{info.getValue()?.toLocaleString()}- <span className="text-xs text-neutral-400">- ({info.row.original.pageviews_percentage}%)- </span>+ </div>+ ),+ }) as any+ );+ cols.push(+ columnHelper.accessor("pageviews_percentage", {+ header: "Pageviews %",+ cell: (info) => (+ <div className="text-left flex flex-row gap-1 items-center">+ {info.getValue()?.toFixed(1)}%</div>),}) as anydiff --git a/server/src/api/analytics/getSingleCol.ts b/server/src/api/analytics/getSingleCol.tsindex e51816694..1f29f1b81 100644--- a/server/src/api/analytics/getSingleCol.ts+++ b/server/src/api/analytics/getSingleCol.ts@@ -195,19 +195,29 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {}return `+ WITH PageStats AS (+ SELECT+ ${geSqlParam(parameter)} as value,+ COUNT(distinct(session_id)) as unique_sessions,+ COUNT() as pageviews+ FROM events+ WHERE+ site_id = ${site}+ AND ${geSqlParam(parameter)} IS NOT NULL+ AND ${geSqlParam(parameter)} <> ''+ ${filterStatement}+ ${timeStatement}+ // AND type = 'pageview'+ GROUP BY value+ )SELECT- ${geSqlParam(parameter)} as value,- COUNT(distinct(session_id)) as count,- ${percentageStatement}- FROM events- WHERE- site_id = ${site}- AND ${geSqlParam(parameter)} IS NOT NULL- AND ${geSqlParam(parameter)} <> ''- ${filterStatement}- ${timeStatement}- // AND type = 'pageview'- GROUP BY value ORDER BY count desc+ value,+ unique_sessions as count,+ round((unique_sessions / sum(unique_sessions) OVER ()) * 100, 2) as percentage,+ pageviews,+ round((pageviews / sum(pageviews) OVER ()) * 100, 2) as pageviews_percentage+ FROM PageStats+ ORDER BY count desc${limit ? `LIMIT ${limit}` : ""};`;};