🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Update TopBar component to include an image and enhance UTM parameter tracking in the backend
Bill Yangb234a72f06dd
diff --git a/client/public/frog.png b/client/public/frog.pngindex c25f0e904..49c8235fa 100644Binary files a/client/public/frog.png and b/client/public/frog.png differdiff --git a/client/src/components/TopBar.tsx b/client/src/components/TopBar.tsxindex dd304d90c..4d4df9005 100644--- a/client/src/components/TopBar.tsx+++ b/client/src/components/TopBar.tsx@@ -12,7 +12,7 @@ import {} from "./ui/dropdown-menu";import { User } from "lucide-react";import { Button } from "./ui/button";-+import Image from "next/image";export function TopBar() {const session = authClient.useSession();const router = useRouter();@@ -22,8 +22,12 @@ export function TopBar() {<div className="flex py-2 px-3 items-center w-full bg-neutral-950 justify-center border-b border-neutral-750"><div className="flex items-center justify-between flex-1"><div className="flex items-center space-x-4">- <Link href="/" className="text-base font-semibold">- 🐸 Rybbit+ <Link+ href="/"+ className="text-base font-semibold flex items-center gap-2"+ >+ <Image src="/frog.png" alt="Rybbit" width={24} height={24} />+ Rybbit</Link></div>{session.data ? (diff --git a/server/src/db/clickhouse/clickhouse.ts b/server/src/db/clickhouse/clickhouse.tsindex 530366f30..794c98c50 100644--- a/server/src/db/clickhouse/clickhouse.ts+++ b/server/src/db/clickhouse/clickhouse.ts@@ -20,6 +20,11 @@ export const initializeClickhouse = async () => {querystring String,page_title String,referrer String,+ utm_source LowCardinality(String),+ utm_medium LowCardinality(String),+ utm_campaign String,+ utm_term String,+ utm_content String,channel String,browser LowCardinality(String),browser_version LowCardinality(String),diff --git a/server/src/tracker/getChannel.ts b/server/src/tracker/getChannel.tsindex 72073d8a5..a436b0c23 100644--- a/server/src/tracker/getChannel.ts+++ b/server/src/tracker/getChannel.ts@@ -24,6 +24,7 @@ import {videoMediums,videoSources,} from "./const.js";+import { getUTMParams } from "./trackingUtils.js";// Categorize mobile app by its bundle ID/package namefunction getMobileAppCategory(@@ -55,28 +56,6 @@ function getMobileAppCategory(return null;}-// UTM and URL parameter parsing utilities-function getUTMParams(querystring: string): Record<string, string> {- const params: Record<string, string> = {};-- if (!querystring) return params;-- try {- const searchParams = new URLSearchParams(querystring);-- // Extract UTM parameters- for (const [key, value] of searchParams.entries()) {- if (key.startsWith("utm_") || key === "gclid" || key === "gad_source") {- params[key.toLowerCase()] = value.toLowerCase();- }- }- } catch (e) {- console.error("Error parsing query string:", e);- }-- return params;-}-function getDomainFromReferrer(referrer: string): string {if (!referrer) return "$direct";diff --git a/server/src/tracker/pageviewQueue.ts b/server/src/tracker/pageviewQueue.tsindex 2cce30653..35bbda799 100644--- a/server/src/tracker/pageviewQueue.ts+++ b/server/src/tracker/pageviewQueue.ts@@ -3,7 +3,7 @@ import clickhouse from "../db/clickhouse/clickhouse.js";import { TrackingPayload } from "../types.js";import { getDeviceType } from "../utils.js";import { getChannel } from "./getChannel.js";-import { clearSelfReferrer } from "./trackingUtils.js";+import { clearSelfReferrer, getUTMParams } from "./trackingUtils.js";type TotalPayload = TrackingPayload & {userId: string;@@ -71,6 +71,9 @@ class PageviewQueue {// Check if referrer is from the same domain and clear it if solet referrer = clearSelfReferrer(pv.referrer || "", pv.hostname || "");+ // Get UTM parameters+ const utmParams = getUTMParams(pv.querystring || "");+return {site_id: pv.site_id,timestamp: DateTime.fromISO(pv.timestamp).toFormat(@@ -101,6 +104,11 @@ class PageviewQueue {type: pv.type || "pageview",event_name: pv.event_name || "",properties: pv.properties,+ utm_source: utmParams["utm_source"] || "",+ utm_medium: utmParams["utm_medium"] || "",+ utm_campaign: utmParams["utm_campaign"] || "",+ utm_term: utmParams["utm_term"] || "",+ utm_content: utmParams["utm_content"] || "",};});diff --git a/server/src/tracker/trackingUtils.ts b/server/src/tracker/trackingUtils.tsindex 0642990b0..61b8f14b9 100644--- a/server/src/tracker/trackingUtils.ts+++ b/server/src/tracker/trackingUtils.ts@@ -45,6 +45,28 @@ export type ActiveSession = {referrer: string | null;};+// UTM and URL parameter parsing utilities+export function getUTMParams(querystring: string): Record<string, string> {+ const params: Record<string, string> = {};++ if (!querystring) return params;++ try {+ const searchParams = new URLSearchParams(querystring);++ // Extract UTM parameters+ for (const [key, value] of searchParams.entries()) {+ if (key.startsWith("utm_") || key === "gclid" || key === "gad_source") {+ params[key.toLowerCase()] = value.toLowerCase();+ }+ }+ } catch (e) {+ console.error("Error parsing query string:", e);+ }++ return params;+}+// Clear referrer if it's from the same domainexport function clearSelfReferrer(referrer: string, hostname: string): string {if (!referrer || !hostname) return referrer;