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.

3.1 relational bug fixes

Francis Cao04eb4b675e5a
diff --git a/src/app/(main)/websites/[websiteId]/WebsiteControls.tsx b/src/app/(main)/websites/[websiteId]/WebsiteControls.tsx
index 80b9024f8..bab23bc5b 100644
--- a/src/app/(main)/websites/[websiteId]/WebsiteControls.tsx
+++ b/src/app/(main)/websites/[websiteId]/WebsiteControls.tsx
@@ -8,6 +8,7 @@ import { WebsiteFilterButton } from '@/components/input/WebsiteFilterButton';
export function WebsiteControls({
websiteId,
allowFilter = true,
+ allowBounceFilter = false,
allowDateFilter = true,
allowMonthFilter,
allowDownload = false,
@@ -25,7 +26,7 @@ export function WebsiteControls({
<Column gap>
<Grid columns={{ base: '1fr', md: 'auto 1fr' }} gap>
<Row alignItems="center" justifyContent="flex-start" gap="4">
- {allowFilter && <WebsiteFilterButton websiteId={websiteId} />}
+ {allowFilter && <WebsiteFilterButton websiteId={websiteId} allowBounceFilter={allowBounceFilter} />}
</Row>
<Row alignItems="center" justifyContent={{ base: 'flex-start', md: 'flex-end' }}>
{allowDateFilter && (
diff --git a/src/app/share/[slug]/[[...path]]/ShareNav.tsx b/src/app/share/[slug]/[[...path]]/ShareNav.tsx
index 3dd743444..1ad22926e 100644
--- a/src/app/share/[slug]/[[...path]]/ShareNav.tsx
+++ b/src/app/share/[slug]/[[...path]]/ShareNav.tsx
@@ -4,6 +4,7 @@ import { AlignEndHorizontal, Clock, Eye, PanelLeft, Sheet, Tag, User } from '@/c
import { LanguageButton } from '@/components/input/LanguageButton';
import { PreferencesButton } from '@/components/input/PreferencesButton';
import { Funnel, Gauge, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg';
+import { buildPath } from '@/lib/url';
import {
Button,
Column,
@@ -29,10 +30,18 @@ export function ShareNav({
}) {
const share = useShare();
const { t, labels } = useMessages();
- const { pathname } = useNavigation();
+ const { pathname, query } = useNavigation();
const { slug, parameters } = share;
- const renderPath = (path: string) => `/share/${slug}${path}`;
+ const renderPath = (path: string) =>
+ buildPath(`/share/${slug}${path}`, {
+ ...query,
+ event: undefined,
+ compare: undefined,
+ view: undefined,
+ unit: undefined,
+ excludeBounce: undefined,
+ });
const allItems = [
{
diff --git a/src/components/input/WebsiteFilterButton.tsx b/src/components/input/WebsiteFilterButton.tsx
index ef6f54361..95bb0ba2f 100644
--- a/src/components/input/WebsiteFilterButton.tsx
+++ b/src/components/input/WebsiteFilterButton.tsx
@@ -8,8 +8,10 @@ import { filtersArrayToObject } from '@/lib/params';
export function WebsiteFilterButton({
websiteId,
+ allowBounceFilter,
}: {
websiteId?: string;
+ allowBounceFilter?: boolean;
position?: 'bottom' | 'top' | 'left' | 'right';
alignment?: 'end' | 'center' | 'start';
}) {
@@ -41,7 +43,7 @@ export function WebsiteFilterButton({
{({ close }) => {
return (
<>
- {isOverview && (
+ {(isOverview || allowBounceFilter) && (
<Row position="absolute" top="30px" right="30px">
<Checkbox
value={excludeBounce ? 'true' : ''}
diff --git a/src/lib/clickhouse.ts b/src/lib/clickhouse.ts
index ef134a0cb..98784d4c9 100644
--- a/src/lib/clickhouse.ts
+++ b/src/lib/clickhouse.ts
@@ -90,9 +90,9 @@ function mapFilter(
case OPERATORS.doesNotContain:
return `positionCaseInsensitive(${column}, ${value}) = 0`;
case OPERATORS.regex:
- return `match(${column}, ${value})`;
+ return `match(${column}, concat('(?i)', ${value}))`;
case OPERATORS.notRegex:
- return `not match(${column}, ${value})`;
+ return `not match(${column}, concat('(?i)', ${value}))`;
default:
return '';
}
@@ -161,7 +161,7 @@ function getCohortQuery(filters: Record<string, any>) {
}
function getExcludeBounceQuery(filters: Record<string, any>) {
- if (!filters.excludeBounce === true) {
+ if (filters.excludeBounce !== true) {
return '';
}
diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts
index 19fd421ec..435ea812a 100644
--- a/src/lib/prisma.ts
+++ b/src/lib/prisma.ts
@@ -97,9 +97,9 @@ function mapFilter(
case OPERATORS.doesNotContain:
return `${table}.${column} not ilike ${value}`;
case OPERATORS.regex:
- return `${table}.${column} ~ ${value}`;
+ return `${table}.${column} ~* ${value}`;
case OPERATORS.notRegex:
- return `${table}.${column} !~ ${value}`;
+ return `${table}.${column} !~* ${value}`;
default:
return '';
}
@@ -173,7 +173,7 @@ function getCohortQuery(filters: QueryFilters = {}) {
}
function getExcludeBounceQuery(filters: Record<string, any>) {
- if (!filters.excludeBounce === true) {
+ if (filters.excludeBounce !== true) {
return '';
}
@@ -278,7 +278,7 @@ async function rawQuery(sql: string, data: Record<string, any>, name?: string):
if (process.env.DATABASE_REPLICA_URL && '$replica' in client) {
return client.$replica().$queryRawUnsafe(query, ...params);
}
-
+ console.log(query, params);
return client.$queryRawUnsafe(query, ...params);
}
diff --git a/src/queries/sql/pageviews/getPageviewMetrics.ts b/src/queries/sql/pageviews/getPageviewMetrics.ts
index 3edb25282..a7a705f1d 100644
--- a/src/queries/sql/pageviews/getPageviewMetrics.ts
+++ b/src/queries/sql/pageviews/getPageviewMetrics.ts
@@ -82,6 +82,7 @@ async function relationalQuery(
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type NOT IN (2, 5)
+ and ${column} != ''
${excludeDomain}
${filterQuery}
group by 1
@@ -142,6 +143,7 @@ async function clickhouseQuery(
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type NOT IN (2, 5)
+ and ${column} != ''
${excludeDomain}
${filterQuery}
group by x
diff --git a/src/queries/sql/replays/getSessionReplays.ts b/src/queries/sql/replays/getSessionReplays.ts
index ee9775b62..d7e1535b6 100644
--- a/src/queries/sql/replays/getSessionReplays.ts
+++ b/src/queries/sql/replays/getSessionReplays.ts
@@ -25,11 +25,11 @@ async function relationalQuery(websiteId: string, filters: QueryFilters, session
const joinQuery =
filterQuery || cohortQuery
- ? `join (select distinct website_id, session_id, visit_id
+ ? `join (select distinct website_event.website_id, website_event.session_id, website_event.visit_id
from website_event
${cohortQuery}
- where website_id = {{websiteId::uuid}}
- and created_at between {{startDate}} and {{endDate}}
+ where website_event.website_id = {{websiteId::uuid}}
+ and website_event.created_at between {{startDate}} and {{endDate}}
${filterQuery}) website_event
on website_event.website_id = sr.website_id
and website_event.session_id = sr.session_id
diff --git a/src/queries/sql/sessions/getSessionMetrics.ts b/src/queries/sql/sessions/getSessionMetrics.ts
index 59b2ebf82..2a5716bc1 100644
--- a/src/queries/sql/sessions/getSessionMetrics.ts
+++ b/src/queries/sql/sessions/getSessionMetrics.ts
@@ -58,8 +58,9 @@ async function relationalQuery(
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and website_event.event_type NOT IN (2, 5)
+ and ${column} != ''
${filterQuery}
- group by 1
+ group by 1
${includeCountry ? ', 3' : ''}
order by 2 desc
limit ${limit}
@@ -102,8 +103,9 @@ async function clickhouseQuery(
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type NOT IN (2, 5)
+ and ${column} != ''
${filterQuery}
- group by x
+ group by x
${includeCountry ? ', country' : ''}
order by y desc
limit ${limit}
@@ -121,6 +123,7 @@ async function clickhouseQuery(
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type NOT IN (2, 5)
+ and ${column} != ''
${filterQuery}
group by x
${includeCountry ? ', country' : ''}