implement exclude bounces feature
This commit is contained in:
1 parent
4a3190b2da
commit
ee698b636a
21 files changed
+189
-69
No files matched your search
@@ -131,6 +131,25 @@ function getCohortQuery(filters: Record<string, any>) {
|
||||
`;
|
||||
}
|
||||
|
||||
function getExcludeBounceQuery(filters: Record<string, any>) {
|
||||
if (!filters.excludeBounce === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `join
|
||||
(select distinct session_id, visit_id
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and event_type = 1
|
||||
group by session_id, visit_id
|
||||
having count(*) > 1
|
||||
) excludeBounce
|
||||
on excludeBounce.session_id = website_event.session_id
|
||||
and excludeBounce.visit_id = website_event.visit_id
|
||||
`;
|
||||
}
|
||||
|
||||
function getDateQuery(filters: Record<string, any>) {
|
||||
const { startDate, endDate, timezone } = filters;
|
||||
|
||||
@@ -174,6 +193,7 @@ function parseFilters(filters: Record<string, any>, options?: QueryOptions) {
|
||||
dateQuery: getDateQuery(filters),
|
||||
queryParams: getQueryParams(filters),
|
||||
cohortQuery: getCohortQuery(cohortFilters),
|
||||
excludeBounceQuery: getExcludeBounceQuery(filters),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,25 @@ function getCohortQuery(filters: QueryFilters = {}) {
|
||||
`;
|
||||
}
|
||||
|
||||
function getExcludeBounceQuery(filters: Record<string, any>) {
|
||||
if (!filters.excludeBounce === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `join
|
||||
(select distinct session_id, visit_id
|
||||
from website_event
|
||||
where website_id = {{websiteId}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and event_type = 1
|
||||
group by session_id, visit_id
|
||||
having count(*) > 1
|
||||
) excludeBounce
|
||||
on excludeBounce.session_id = website_event.session_id
|
||||
and excludeBounce.visit_id = website_event.visit_id
|
||||
`;
|
||||
}
|
||||
|
||||
function getDateQuery(filters: Record<string, any>) {
|
||||
const { startDate, endDate } = filters;
|
||||
|
||||
@@ -186,6 +205,7 @@ function parseFilters(filters: Record<string, any>, options?: QueryOptions) {
|
||||
filterQuery: getFilterQuery(filters, options),
|
||||
queryParams: getQueryParams(filters),
|
||||
cohortQuery: getCohortQuery(cohortFilters),
|
||||
excludeBounceQuery: getExcludeBounceQuery(filters),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,10 @@ export async function getQueryFilters(
|
||||
cohort_endDate: endDate,
|
||||
});
|
||||
}
|
||||
|
||||
if (params.excludeBounce) {
|
||||
Object.assign(filters, { excludeBounce: true });
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -42,6 +42,7 @@ export const filterParams = {
|
||||
segment: z.uuid().optional(),
|
||||
cohort: z.uuid().optional(),
|
||||
eventType: z.coerce.number().int().positive().optional(),
|
||||
excludeBounce: z.string().optional(),
|
||||
};
|
||||
|
||||
export const searchParams = {
|
||||
|
||||
@@ -90,6 +90,7 @@ export interface FilterParams {
|
||||
segment?: string;
|
||||
cohort?: string;
|
||||
compare?: string;
|
||||
excludeBounce?: boolean;
|
||||
}
|
||||
|
||||
export interface SortParams {
|
||||
|
||||
Reference in new issue
Block a user