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.

Support wildcard for goals report Closes #4086

Francis Cao54dbfe1ca9f7
diff --git a/src/queries/sql/reports/getGoal.ts b/src/queries/sql/reports/getGoal.ts
index 4901bb28c..e6f425519 100644
--- a/src/queries/sql/reports/getGoal.ts
+++ b/src/queries/sql/reports/getGoal.ts
@@ -29,10 +29,18 @@ async function relationalQuery(
const { rawQuery, parseFilters } = prisma;
const eventType = type === 'path' ? EVENT_TYPE.pageView : EVENT_TYPE.customEvent;
const column = type === 'path' ? 'url_path' : 'event_name';
+
+ let operator = '=';
+ let paramValue = value;
+ if (value.startsWith('*') || value.endsWith('*')) {
+ operator = 'like';
+ paramValue = value.replace(/^\*|\*$/g, '%');
+ }
+
const { filterQuery, dateQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
- value,
+ value: paramValue,
startDate,
endDate,
eventType,
@@ -60,7 +68,7 @@ async function relationalQuery(
${cohortQuery}
${joinSessionQuery}
where website_event.website_id = {{websiteId::uuid}}
- and ${column} = {{value}}
+ and ${column} ${operator} {{value}}
${dateQuery}
${filterQuery}
`,
@@ -77,10 +85,18 @@ async function clickhouseQuery(
const { rawQuery, parseFilters } = clickhouse;
const eventType = type === 'path' ? EVENT_TYPE.pageView : EVENT_TYPE.customEvent;
const column = type === 'path' ? 'url_path' : 'event_name';
+
+ let operator = '=';
+ let paramValue = value;
+ if (value.startsWith('*') || value.endsWith('*')) {
+ operator = 'like';
+ paramValue = value.replace(/^\*|\*$/g, '%');
+ }
+
const { filterQuery, dateQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
- value,
+ value: paramValue,
startDate,
endDate,
eventType,
@@ -106,7 +122,7 @@ async function clickhouseQuery(
from website_event
${cohortQuery}
where website_id = {websiteId:UUID}
- and ${column} = {value:String}
+ and ${column} ${operator} {value:String}
${dateQuery}
${filterQuery}
`,