🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance analytics filters and user ID handling
Bill Yang4042d3a646c0
diff --git a/client/src/app/[site]/components/shared/Filters/const.tsx b/client/src/app/[site]/components/shared/Filters/const.tsxindex edf34a737..0fbe7c6ea 100644--- a/client/src/app/[site]/components/shared/Filters/const.tsx+++ b/client/src/app/[site]/components/shared/Filters/const.tsx@@ -22,6 +22,7 @@ import {TabletSmartphone,Tag,Target,+ User,} from "lucide-react";import React from "react";@@ -50,6 +51,11 @@ export const FilterOptions: {value: "hostname",icon: <Server className="h-4 w-4" />,},+ {+ label: "User ID",+ value: "user_id",+ icon: <User className="h-4 w-4" />,+ },{label: "Event Name",value: "event_name",diff --git a/server/src/api/analytics/query-validation.ts b/server/src/api/analytics/query-validation.tsindex cf5cab206..e72543536 100644--- a/server/src/api/analytics/query-validation.ts+++ b/server/src/api/analytics/query-validation.ts@@ -250,6 +250,7 @@ export const filterParamSchema = z.enum(["dimensions","browser_version","operating_system_version",+ "user_id",]);/**diff --git a/server/src/services/userId/userIdService.ts b/server/src/services/userId/userIdService.tsindex 0c28e4013..a2e3cfb0d 100644--- a/server/src/services/userId/userIdService.ts+++ b/server/src/services/userId/userIdService.ts@@ -45,7 +45,7 @@ class UserIdService {* @param ip User's IP address* @param userAgent User's user agent string* @param siteId The site ID to check for salting configuration- * @returns A sha256 hash to identify the user+ * @returns A truncated sha256 hash (12 chars) to identify the user*/async generateUserId(ip: string, userAgent: string, siteId: number): Promise<string> {// Only apply salt if the site has salting enabled@@ -55,14 +55,16 @@ class UserIdService {return crypto.createHash("sha256").update(ip + userAgent + dailySalt)- .digest("hex");+ .digest("hex")+ .substring(0, 12);}// Otherwise, just hash IP and user agentreturn crypto.createHash("sha256").update(ip + userAgent)- .digest("hex");+ .digest("hex")+ .substring(0, 12);}}diff --git a/shared/src/filters.ts b/shared/src/filters.tsindex 431762811..babbe8885 100644--- a/shared/src/filters.ts+++ b/shared/src/filters.ts@@ -24,10 +24,11 @@ export type FilterParameter =| "exit_page"| "dimensions"| "browser_version"- | "operating_system_version";+ | "operating_system_version"+ | "user_id";export interface Filter {parameter: FilterParameter;value: string[];type: FilterType;-}\ No newline at end of file+}