({
projectId,
startDate,
endDate,
steps = 5,
mode,
startEvent,
endEvent,
exclude = [],
include,
timezone,
}: IGetSankeyInput)
| 338 | } |
| 339 | |
| 340 | async getSankey({ |
| 341 | projectId, |
| 342 | startDate, |
| 343 | endDate, |
| 344 | steps = 5, |
| 345 | mode, |
| 346 | startEvent, |
| 347 | endEvent, |
| 348 | exclude = [], |
| 349 | include, |
| 350 | timezone, |
| 351 | }: IGetSankeyInput): Promise<{ |
| 352 | nodes: Array<{ |
| 353 | id: string; |
| 354 | label: string; |
| 355 | nodeColor: string; |
| 356 | percentage?: number; |
| 357 | value?: number; |
| 358 | step?: number; |
| 359 | }>; |
| 360 | links: Array<{ source: string; target: string; value: number }>; |
| 361 | }> { |
| 362 | const COLORS = chartColors.map((color) => color.main); |
| 363 | |
| 364 | // 1. Build event name filter |
| 365 | const eventNameFilter = this.buildEventNameFilter( |
| 366 | include, |
| 367 | exclude, |
| 368 | startEvent?.name, |
| 369 | endEvent?.name, |
| 370 | ); |
| 371 | |
| 372 | // 2. Build ordered events query |
| 373 | // For screen_view events, use the path instead of the event name for more meaningful flow visualization |
| 374 | const orderedEventsQuery = clix(this.client, timezone) |
| 375 | .select<{ |
| 376 | session_id: string; |
| 377 | event_name: string; |
| 378 | created_at: string; |
| 379 | }>([ |
| 380 | 'session_id', |
| 381 | // "if(name = 'screen_view', path, name) as event_name", |
| 382 | 'name as event_name', |
| 383 | 'created_at', |
| 384 | ]) |
| 385 | .from(TABLE_NAMES.events) |
| 386 | .where('project_id', '=', projectId) |
| 387 | .where('created_at', 'BETWEEN', [ |
| 388 | clix.datetime(startDate, 'toDateTime'), |
| 389 | clix.datetime(endDate, 'toDateTime'), |
| 390 | ]) |
| 391 | .orderBy('session_id', 'ASC') |
| 392 | .orderBy('created_at', 'ASC'); |
| 393 | |
| 394 | if (eventNameFilter) { |
| 395 | orderedEventsQuery.rawWhere(eventNameFilter); |
| 396 | } |
| 397 |
no test coverage detected