Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: join profiles on getFunnelProfiles

Carl-Gerhard Lindesvärd4e4268911585
diff --git a/packages/trpc/src/routers/chart.ts b/packages/trpc/src/routers/chart.ts
index 0debd31fe..ccecf3d7c 100644
--- a/packages/trpc/src/routers/chart.ts
+++ b/packages/trpc/src/routers/chart.ts
@@ -696,6 +696,20 @@ export const chartRouter = createTRPCRouter({
additionalGroupBy: ['profile_id'],
});
+ // Check for profile filters and add profile join if needed
+ const profileFilters = funnelService.getProfileFilters(
+ eventSeries as IChartEvent[],
+ );
+ if (profileFilters.length > 0) {
+ const fieldsToSelect = uniq(
+ profileFilters.map((f) => f.split('.')[0]),
+ ).join(', ');
+ funnelCte.leftJoin(
+ `(SELECT id, ${fieldsToSelect} FROM ${TABLE_NAMES.profiles} FINAL WHERE project_id = ${sqlstring.escape(projectId)}) as profile`,
+ 'profile.id = events.profile_id',
+ );
+ }
+
// Build main query
const query = clix(ch, timezone);