@@ -16,7 +16,7 @@ export class FunnelService {
1616
1717 private getFunnelGroup ( group ?: string ) {
1818 return group === 'profile_id'
19- ? [ `COALESCE(nullIf(s.profile_id , ''), profile_id)` , 'profile_id' ]
19+ ? [ `COALESCE(nullIf(s.pid , ''), profile_id)` , 'profile_id' ]
2020 : [ 'session_id' , 'session_id' ] ;
2121 }
2222
@@ -159,15 +159,16 @@ export class FunnelService {
159159 funnelCte . leftJoin (
160160 `(SELECT id, ${ uniq ( profileFilters . map ( ( f ) => f . split ( '.' ) [ 0 ] ) ) } FROM ${ TABLE_NAMES . profiles } FINAL
161161 WHERE project_id = ${ sqlstring . escape ( projectId ) } ) as profile` ,
162- 'profile.id = profile_id' ,
162+ 'profile.id = events. profile_id' ,
163163 ) ;
164164 }
165165
166166 // Create the sessions CTE if needed
167167 const sessionsCte =
168168 group [ 0 ] !== 'session_id'
169169 ? clix ( this . client , timezone )
170- . select ( [ 'profile_id' , 'id' ] )
170+ // Important to have unique field names to avoid ambiguity in the main query
171+ . select ( [ 'profile_id as pid' , 'id as sid' ] )
171172 . from ( TABLE_NAMES . sessions )
172173 . where ( 'project_id' , '=' , projectId )
173174 . where ( 'created_at' , 'BETWEEN' , [
@@ -180,7 +181,7 @@ export class FunnelService {
180181 const funnelQuery = clix ( this . client , timezone ) ;
181182
182183 if ( sessionsCte ) {
183- funnelCte . leftJoin ( 'sessions s' , 's.id = session_id' ) ;
184+ funnelCte . leftJoin ( 'sessions s' , 's.sid = events. session_id' ) ;
184185 funnelQuery . with ( 'sessions' , sessionsCte ) ;
185186 }
186187
0 commit comments