Skip to content

Commit 54dbfe1

Browse files
committed
Support wildcard for goals report Closes #4086
1 parent 9c8f770 commit 54dbfe1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/queries/sql/reports/getGoal.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ async function relationalQuery(
2929
const { rawQuery, parseFilters } = prisma;
3030
const eventType = type === 'path' ? EVENT_TYPE.pageView : EVENT_TYPE.customEvent;
3131
const column = type === 'path' ? 'url_path' : 'event_name';
32+
33+
let operator = '=';
34+
let paramValue = value;
35+
if (value.startsWith('*') || value.endsWith('*')) {
36+
operator = 'like';
37+
paramValue = value.replace(/^\*|\*$/g, '%');
38+
}
39+
3240
const { filterQuery, dateQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
3341
...filters,
3442
websiteId,
35-
value,
43+
value: paramValue,
3644
startDate,
3745
endDate,
3846
eventType,
@@ -60,7 +68,7 @@ async function relationalQuery(
6068
${cohortQuery}
6169
${joinSessionQuery}
6270
where website_event.website_id = {{websiteId::uuid}}
63-
and ${column} = {{value}}
71+
and ${column} ${operator} {{value}}
6472
${dateQuery}
6573
${filterQuery}
6674
`,
@@ -77,10 +85,18 @@ async function clickhouseQuery(
7785
const { rawQuery, parseFilters } = clickhouse;
7886
const eventType = type === 'path' ? EVENT_TYPE.pageView : EVENT_TYPE.customEvent;
7987
const column = type === 'path' ? 'url_path' : 'event_name';
88+
89+
let operator = '=';
90+
let paramValue = value;
91+
if (value.startsWith('*') || value.endsWith('*')) {
92+
operator = 'like';
93+
paramValue = value.replace(/^\*|\*$/g, '%');
94+
}
95+
8096
const { filterQuery, dateQuery, cohortQuery, queryParams } = parseFilters({
8197
...filters,
8298
websiteId,
83-
value,
99+
value: paramValue,
84100
startDate,
85101
endDate,
86102
eventType,
@@ -106,7 +122,7 @@ async function clickhouseQuery(
106122
from website_event
107123
${cohortQuery}
108124
where website_id = {websiteId:UUID}
109-
and ${column} = {value:String}
125+
and ${column} ${operator} {value:String}
110126
${dateQuery}
111127
${filterQuery}
112128
`,

0 commit comments

Comments
 (0)