Skip to content

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

Enhance user analytics by adding 'referrer' and 'channel' fields to UserInfo type, and update related session handling by restructuring API endpoints for better organization. Remove deprecated session-related files to streamline the analytics module.

Bill Yangc1ac56661f27
diff --git a/client/src/api/analytics/endpoints/users.ts b/client/src/api/analytics/endpoints/users.ts
index ad572e772..d08911922 100644
--- a/client/src/api/analytics/endpoints/users.ts
+++ b/client/src/api/analytics/endpoints/users.ts
@@ -46,6 +46,8 @@ export type UserInfo = {
operating_system_version: string;
screen_height: number;
screen_width: number;
+ referrer: string;
+ channel: string;
last_seen: string;
first_seen: string;
pageviews: number;
diff --git a/docs/src/app/[locale]/(home)/terms-and-conditions/page.tsx b/docs/src/app/[locale]/(home)/terms-and-conditions/page.tsx
index da3ebce9d..e1234beb9 100644
--- a/docs/src/app/[locale]/(home)/terms-and-conditions/page.tsx
+++ b/docs/src/app/[locale]/(home)/terms-and-conditions/page.tsx
@@ -83,14 +83,6 @@ export default function TermsAndConditions() {
constitutes acceptance of the new pricing.
</p>
- <h3 className="text-xl font-semibold mt-6 mb-3">Refund Policy</h3>
- <p>
- We offer a 60-day money-back guarantee for new paid subscriptions. Refund requests must be submitted within 60
- days of your initial payment. After this period, payments are non-refundable. We do not provide prorated
- refunds for mid-cycle cancellations, but you retain access to the service through the end of your paid billing
- period.
- </p>
-
<h3 className="text-xl font-semibold mt-6 mb-3">Usage Quotas and Overages</h3>
<p>
Each plan includes specific usage limits. If you exceed your plan&apos;s page view limit, you may be required
diff --git a/server/src/api/analytics/funnels/getFunnelStepSessions.ts b/server/src/api/analytics/funnels/getFunnelStepSessions.ts
index 18308679b..df6d146b8 100644
--- a/server/src/api/analytics/funnels/getFunnelStepSessions.ts
+++ b/server/src/api/analytics/funnels/getFunnelStepSessions.ts
@@ -3,7 +3,7 @@ import { FastifyReply, FastifyRequest } from "fastify";
import SqlString from "sqlstring";
import { clickhouse } from "../../../db/clickhouse/clickhouse.js";
import { getTimeStatement, patternToRegex, processResults } from "../utils/utils.js";
-import { GetSessionsResponse } from "../getSessions.js";
+import { GetSessionsResponse } from "../sessions/getSessions.js";
import { getFilterStatement } from "../utils/getFilterStatement.js";
type FunnelStep = {
diff --git a/server/src/api/analytics/goals/getGoalSessions.ts b/server/src/api/analytics/goals/getGoalSessions.ts
index 535e5a98c..a64051621 100644
--- a/server/src/api/analytics/goals/getGoalSessions.ts
+++ b/server/src/api/analytics/goals/getGoalSessions.ts
@@ -5,7 +5,7 @@ import { goals } from "../../../db/postgres/schema.js";
import { eq } from "drizzle-orm";
import { getTimeStatement, processResults, patternToRegex } from "../utils/utils.js";
import { FilterParams } from "@rybbit/shared";
-import { GetSessionsResponse } from "../getSessions.js";
+import { GetSessionsResponse } from "../sessions/getSessions.js";
import SqlString from "sqlstring";
export interface GetGoalSessionsRequest {
diff --git a/server/src/api/analytics/index.ts b/server/src/api/analytics/index.ts
index 4e6f99aff..066b353e3 100644
--- a/server/src/api/analytics/index.ts
+++ b/server/src/api/analytics/index.ts
@@ -41,9 +41,9 @@ export { getOverview } from "./getOverview.js";
export { getOverviewBucketed } from "./getOverviewBucketed.js";
export { getPageTitles } from "./getPageTitles.js";
export { getRetention } from "./getRetention.js";
-export { getSession } from "./getSession.js";
-export { getSessionLocations } from "./getSessionLocations.js";
-export { getSessions } from "./getSessions.js";
+export { getSession } from "./sessions/getSession.js";
+export { getSessionLocations } from "./sessions/getSessionLocations.js";
+export { getSessions } from "./sessions/getSessions.js";
export { getUserInfo } from "./users/getUserInfo.js";
export { getUserSessionCount } from "./users/getUserSessionCount.js";
export { getUsers } from "./users/getUsers.js";
diff --git a/server/src/api/analytics/getSession.ts b/server/src/api/analytics/sessions/getSession.ts
similarity index 96%
rename from server/src/api/analytics/getSession.ts
rename to server/src/api/analytics/sessions/getSession.ts
index bb1ef635c..e0d115b29 100644
--- a/server/src/api/analytics/getSession.ts
+++ b/server/src/api/analytics/sessions/getSession.ts
@@ -1,6 +1,6 @@
import { FastifyReply, FastifyRequest } from "fastify";
-import { clickhouse } from "../../db/clickhouse/clickhouse.js";
-import { processResults } from "./utils/utils.js";
+import { clickhouse } from "../../../db/clickhouse/clickhouse.js";
+import { processResults } from "../utils/utils.js";
export interface SessionDetails {
session_id: string;
@@ -92,8 +92,8 @@ SELECT
any(operating_system_version) as operating_system_version,
any(screen_width) as screen_width,
any(screen_height) as screen_height,
- any(referrer) as referrer,
- any(channel) as channel,
+ argMin(referrer, timestamp) as referrer,
+ argMin(channel, timestamp) as channel,
min(timestamp) as session_start,
max(timestamp) as session_end,
dateDiff('second', min(timestamp), max(timestamp)) as session_duration,
diff --git a/server/src/api/analytics/getSessionLocations.ts b/server/src/api/analytics/sessions/getSessionLocations.ts
similarity index 85%
rename from server/src/api/analytics/getSessionLocations.ts
rename to server/src/api/analytics/sessions/getSessionLocations.ts
index 893ec6935..459ecb3a5 100644
--- a/server/src/api/analytics/getSessionLocations.ts
+++ b/server/src/api/analytics/sessions/getSessionLocations.ts
@@ -1,8 +1,8 @@
import { FilterParams } from "@rybbit/shared";
import { FastifyReply, FastifyRequest } from "fastify";
-import { clickhouse } from "../../db/clickhouse/clickhouse.js";
-import { getTimeStatement, processResults } from "./utils/utils.js";
-import { getFilterStatement } from "./utils/getFilterStatement.js";
+import { clickhouse } from "../../../db/clickhouse/clickhouse.js";
+import { getTimeStatement, processResults } from "../utils/utils.js";
+import { getFilterStatement } from "../utils/getFilterStatement.js";
export async function getSessionLocations(
req: FastifyRequest<{
diff --git a/server/src/api/analytics/getSessions.ts b/server/src/api/analytics/sessions/getSessions.ts
similarity index 97%
rename from server/src/api/analytics/getSessions.ts
rename to server/src/api/analytics/sessions/getSessions.ts
index 746493d05..8649d850e 100644
--- a/server/src/api/analytics/getSessions.ts
+++ b/server/src/api/analytics/sessions/getSessions.ts
@@ -1,8 +1,8 @@
import { FastifyReply, FastifyRequest } from "fastify";
-import { clickhouse } from "../../db/clickhouse/clickhouse.js";
-import { enrichWithTraits, getTimeStatement, processResults } from "./utils/utils.js";
+import { clickhouse } from "../../../db/clickhouse/clickhouse.js";
+import { enrichWithTraits, getTimeStatement, processResults } from "../utils/utils.js";
import { FilterParams } from "@rybbit/shared";
-import { getFilterStatement } from "./utils/getFilterStatement.js";
+import { getFilterStatement } from "../utils/getFilterStatement.js";
export type GetSessionsResponse = {
session_id: string;
diff --git a/server/src/api/analytics/users/getUserInfo.ts b/server/src/api/analytics/users/getUserInfo.ts
index cac24beb4..abcb32b39 100644
--- a/server/src/api/analytics/users/getUserInfo.ts
+++ b/server/src/api/analytics/users/getUserInfo.ts
@@ -74,6 +74,7 @@ export async function getUserInfo(
argMax(screen_width, timestamp) AS screen_width,
argMax(screen_height, timestamp) AS screen_height,
argMin(referrer, timestamp) AS referrer,
+ argMin(channel, timestamp) AS channel,
MAX(timestamp) AS session_end,
MIN(timestamp) AS session_start,
dateDiff('second', MIN(timestamp), MAX(timestamp)) AS session_duration,
diff --git a/server/src/api/analytics/users/getUsers.ts b/server/src/api/analytics/users/getUsers.ts
index 0531316a7..9d0c69d39 100644
--- a/server/src/api/analytics/users/getUsers.ts
+++ b/server/src/api/analytics/users/getUsers.ts
@@ -119,7 +119,7 @@ WITH AggregatedUsers AS (
argMax(screen_width, timestamp) AS screen_width,
argMax(screen_height, timestamp) AS screen_height,
argMin(referrer, timestamp) AS referrer,
- argMax(channel, timestamp) AS channel,
+ argMin(channel, timestamp) AS channel,
argMin(hostname, timestamp) AS hostname,
countIf(type = 'pageview') AS pageviews,
countIf(type = 'custom_event') AS events,