Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor analytics API endpoints to remove unused query parameters, streamlining request handling for error events, journeys, user sessions, and outbound links. Update related types to enhance consistency in filter handling.

Bill Yangfaeae21712f2
diff --git a/server/src/api/analytics/events/getOutboundLinks.ts b/server/src/api/analytics/events/getOutboundLinks.ts
index 3f503292d..2d1af82b4 100644
--- a/server/src/api/analytics/events/getOutboundLinks.ts
+++ b/server/src/api/analytics/events/getOutboundLinks.ts
@@ -17,7 +17,7 @@ export interface GetOutboundLinksRequest {
}
export async function getOutboundLinks(req: FastifyRequest<GetOutboundLinksRequest>, res: FastifyReply) {
- const { startDate, endDate, timeZone, filters, pastMinutesStart, pastMinutesEnd } = req.query;
+ const { filters } = req.query;
const site = req.params.site;
const timeStatement = getTimeStatement(req.query);
diff --git a/server/src/api/analytics/getErrorEvents.ts b/server/src/api/analytics/getErrorEvents.ts
index af424faef..21c7ddfae 100644
--- a/server/src/api/analytics/getErrorEvents.ts
+++ b/server/src/api/analytics/getErrorEvents.ts
@@ -46,8 +46,7 @@ type ErrorEventsPaginatedResponse = {
};
const getErrorEventsQuery = (request: FastifyRequest<GetErrorEventsRequest>, isCountQuery: boolean = false) => {
- const { startDate, endDate, timeZone, filters, errorMessage, limit, page, pastMinutesStart, pastMinutesEnd } =
- request.query;
+ const { filters, limit, page } = request.query;
const timeStatement = getTimeStatement(request.query);
const filterStatement = getFilterStatement(filters, Number(request.params.site), timeStatement);
diff --git a/server/src/api/analytics/getJourneys.ts b/server/src/api/analytics/getJourneys.ts
index eae40ee25..72f31c897 100644
--- a/server/src/api/analytics/getJourneys.ts
+++ b/server/src/api/analytics/getJourneys.ts
@@ -17,7 +17,7 @@ export const getJourneys = async (
) => {
try {
const { site } = request.params;
- const { steps = "3", startDate, endDate, timeZone = "UTC", limit = "100", filters, stepFilters } = request.query;
+ const { steps = "3", limit = "100", filters, stepFilters } = request.query;
const maxSteps = parseInt(steps, 10);
const journeyLimit = parseInt(limit, 10);
diff --git a/server/src/api/analytics/getUserSessions.ts b/server/src/api/analytics/getUserSessions.ts
index 0aef680e3..16f68676f 100644
--- a/server/src/api/analytics/getUserSessions.ts
+++ b/server/src/api/analytics/getUserSessions.ts
@@ -1,3 +1,4 @@
+import { FilterParams } from "@rybbit/shared";
import { FastifyReply, FastifyRequest } from "fastify";
import { clickhouse } from "../../db/clickhouse/clickhouse.js";
import { getFilterStatement, getTimeStatement, processResults } from "./utils.js";
@@ -36,20 +37,16 @@ type GroupedSession = {
};
export interface GetUserSessionsRequest {
- Querystring: {
- startDate: string;
- endDate: string;
- timeZone: string;
+ Querystring: FilterParams<{
site: string;
- filters: string;
- };
+ }>;
Params: {
userId: string;
};
}
export async function getUserSessions(req: FastifyRequest<GetUserSessionsRequest>, res: FastifyReply) {
- const { startDate, endDate, timeZone, site, filters } = req.query;
+ const { site, filters } = req.query;
const userId = req.params.userId;
const timeStatement = getTimeStatement(req.query);
diff --git a/server/src/services/replay/sessionReplayQueryService.ts b/server/src/services/replay/sessionReplayQueryService.ts
index c3f1f4fd5..fdd04997c 100644
--- a/server/src/services/replay/sessionReplayQueryService.ts
+++ b/server/src/services/replay/sessionReplayQueryService.ts
@@ -15,12 +15,12 @@ import { r2Storage } from "../storage/r2StorageService.js";
export class SessionReplayQueryService {
async getSessionReplayList(
siteId: number,
- options: {
+ options: FilterParams<{
limit?: number;
offset?: number;
userId?: string;
minDuration?: number;
- } & Pick<FilterParams, "startDate" | "endDate" | "timeZone" | "pastMinutesStart" | "pastMinutesEnd" | "filters">
+ }>
): Promise<SessionReplayListItem[]> {
const { limit = 50, offset = 0, userId, minDuration } = options;