🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
2.3.0 (#795)
Bill Yangef631074634b
diff --git a/client/package-lock.json b/client/package-lock.jsonindex 85bd0a36a..0bcfdd307 100644--- a/client/package-lock.json+++ b/client/package-lock.json@@ -1,12 +1,12 @@{"name": "client",- "version": "2.2.4",+ "version": "2.3.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "client",- "version": "2.2.4",+ "version": "2.3.0","dependencies": {"@hookform/resolvers": "5.0.1","@icons-pack/react-simple-icons": "^13.6.0",@@ -2049,6 +2049,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/annotations/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/annotations/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/axes": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/axes/-/axes-0.96.0.tgz",@@ -2129,6 +2153,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/axes/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/axes/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/bar": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/bar/-/bar-0.96.0.tgz",@@ -2216,6 +2264,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/bar/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/bar/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/calendar": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/calendar/-/calendar-0.96.0.tgz",@@ -2358,6 +2430,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/core/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/core/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/legends": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/legends/-/legends-0.96.0.tgz",@@ -2458,6 +2554,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/line/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/line/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/scales": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/scales/-/scales-0.96.0.tgz",@@ -2555,6 +2675,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/text/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/text/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/theming": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/theming/-/theming-0.96.0.tgz",@@ -2641,6 +2785,30 @@"react": "^16.8.0 || ^17.0.0 || ^18.0.0"}},+ "node_modules/@nivo/tooltip/node_modules/react-dom": {+ "version": "18.3.1",+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0",+ "scheduler": "^0.23.2"+ },+ "peerDependencies": {+ "react": "^18.3.1"+ }+ },+ "node_modules/@nivo/tooltip/node_modules/scheduler": {+ "version": "0.23.2",+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "loose-envify": "^1.1.0"+ }+ },"node_modules/@nivo/voronoi": {"version": "0.96.0","resolved": "https://registry.npmjs.org/@nivo/voronoi/-/voronoi-0.96.0.tgz",@@ -5676,7 +5844,6 @@"version": "19.2.7","resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.7.tgz","integrity": "sha512-MWtvHrGZLFttgeEj28VXHxpmwYbor/ATPYbBfSFZEIRK0ecCFLl2Qo55z52Hss+UV9CRN7trSeq1zbgx7YDWWg==",- "dev": true,"license": "MIT","dependencies": {"csstype": "^3.2.2"diff --git a/client/package.json b/client/package.jsonindex 3be08bbc7..b02c60cd9 100644--- a/client/package.json+++ b/client/package.json@@ -1,6 +1,6 @@{"name": "client",- "version": "2.2.4",+ "version": "2.3.0","private": true,"scripts": {"dev": "next dev -p 3002 --turbopack",diff --git a/client/src/api/analytics/endpoints/sessionReplay.ts b/client/src/api/analytics/endpoints/sessionReplay.tsindex ce0c44c5d..7dc2446df 100644--- a/client/src/api/analytics/endpoints/sessionReplay.ts+++ b/client/src/api/analytics/endpoints/sessionReplay.ts@@ -95,7 +95,7 @@ export async function fetchSessionReplays(...toQueryParams(params),limit: params.limit,offset: params.offset,- min_duration: params.minDuration,+ minDuration: params.minDuration,};const response = await authedFetch<SessionReplayListResponse>(`/sites/${site}/session-replay/list`, queryParams);diff --git a/client/src/app/[site]/api-playground/utils/endpointConfig.ts b/client/src/app/[site]/api-playground/utils/endpointConfig.tsindex 41bae7512..55346606c 100644--- a/client/src/app/[site]/api-playground/utils/endpointConfig.ts+++ b/client/src/app/[site]/api-playground/utils/endpointConfig.ts@@ -93,14 +93,6 @@ export const endpointCategories: EndpointCategory[] = [description: "Returns all organizations the authenticated user is a member of, including all members for each organization",hasCommonParams: false,},- {- method: "GET",- path: "/organizations/:organizationId/sites",- name: "Get Organization Sites",- description: "Returns all sites within an organization with session counts and subscription info",- hasCommonParams: false,- pathParams: ["organizationId"],- },{method: "POST",path: "/organizations/:organizationId/sites",diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsxindex 8465e2f44..e9ad72330 100644--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx@@ -105,16 +105,14 @@ function SidebarContent() {href={getTabPath("goals")}icon={<Target className="w-4 h-4" />}/>- {IS_CLOUD && (- <div className="hidden md:block">- <SidebarComponents.Item- label="API Playground"- active={isActiveTab("api-playground")}- href={getTabPath("api-playground")}- icon={<Code className="w-4 h-4" />}- />- </div>- )}+ <div className="hidden md:block">+ <SidebarComponents.Item+ label="API Playground"+ active={isActiveTab("api-playground")}+ href={getTabPath("api-playground")}+ icon={<Code className="w-4 h-4" />}+ />+ </div><SidebarComponents.SectionHeader>Product Analytics</SidebarComponents.SectionHeader><div className="hidden md:block">{!subscription?.planName?.startsWith("appsumo") && !isSubscriptionLoading && (diff --git a/client/src/app/[site]/events/components/EventLog.tsx b/client/src/app/[site]/events/components/EventLog.tsxindex 60ed8e5fd..b9b5dce01 100644--- a/client/src/app/[site]/events/components/EventLog.tsx+++ b/client/src/app/[site]/events/components/EventLog.tsx@@ -1,6 +1,7 @@"use client";-import { useCallback, useEffect, useRef } from "react";+import { useIntersectionObserver } from "@uidotdev/usehooks";+import { useEffect } from "react";import { useGetEventsInfinite } from "../../../../api/analytics/hooks/events/useGetEvents";import { NothingFound } from "../../../../components/NothingFound";import { formatter } from "../../../../lib/utils";@@ -9,41 +10,24 @@ import { ErrorState } from "../../../../components/ErrorState";import { ScrollArea } from "../../../../components/ui/scroll-area";export function EventLog() {- const containerRef = useRef<HTMLDivElement>(null);- const loadMoreRef = useRef<HTMLDivElement>(null);-// Fetch events with infinite scrollingconst { data, isLoading, isError, fetchNextPage, hasNextPage, isFetchingNextPage } = useGetEventsInfinite({pageSize: 100,});- // Handle scroll for infinite loading- const handleScroll = useCallback(() => {- if (!loadMoreRef.current || !containerRef.current || !hasNextPage || isFetchingNextPage) {- return;- }-- const container = containerRef.current;- const loadMoreElement = loadMoreRef.current;- const containerRect = container.getBoundingClientRect();- const loadMoreRect = loadMoreElement.getBoundingClientRect();+ // Use the intersection observer hook+ const [ref, entry] = useIntersectionObserver({+ threshold: 0,+ root: null,+ rootMargin: "0px 0px 100px 0px",+ });- // Check if the load more element is visible in the viewport- if (loadMoreRect.top <= containerRect.bottom + 100) {+ // Fetch next page when intersection observer detects the target is visible+ useEffect(() => {+ if (entry?.isIntersecting && hasNextPage && !isFetchingNextPage && !isLoading) {fetchNextPage();}- }, [fetchNextPage, hasNextPage, isFetchingNextPage]);-- // Set up scroll event listener- useEffect(() => {- const container = containerRef.current;- if (!container) return;-- container.addEventListener("scroll", handleScroll);- return () => {- container.removeEventListener("scroll", handleScroll);- };- }, [handleScroll]);+ }, [entry?.isIntersecting, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading]);// Flatten all pages of dataconst allEvents = data?.pages.flatMap(page => page.data) || [];@@ -73,22 +57,19 @@ export function EventLog() {return (<ScrollArea className="h-[80vh]">- <div ref={containerRef} className="h-full pr-2 overflow-x-hidden">+ <div className="h-full pr-2 overflow-x-hidden">{allEvents.map((event, index) => (<EventLogItem key={`${event.timestamp}-${index}`} event={event} />))}- {/* Loading state for next page */}- {hasNextPage && (- <div className="py-2">- {Array.from({ length: 3 }).map((_, index) => (+ {/* Infinite scroll sentinel */}+ <div ref={ref} className="py-2">+ {isFetchingNextPage && (+ Array.from({ length: 3 }).map((_, index) => (<EventLogItemSkeleton key={`next-page-${index}`} />- ))}- </div>- )}-- {/* Invisible element for scroll detection */}- {hasNextPage && <div ref={loadMoreRef} className="h-1" />}+ ))+ )}+ </div></div>{/* Pagination info */}{data?.pages[0]?.pagination && (diff --git a/client/src/app/[site]/main/components/sections/Weekdays.tsx b/client/src/app/[site]/main/components/sections/Weekdays.tsxindex d66b45100..f329e22e8 100644--- a/client/src/app/[site]/main/components/sections/Weekdays.tsx+++ b/client/src/app/[site]/main/components/sections/Weekdays.tsx@@ -208,7 +208,7 @@ export function Weekdays() {heatmapData[day].length > hour? heatmapData[day][hour]: 0;- const colorClass = value > 0 ? getColorIntensity(value) : "bg-neutral-200 dark:bg-neutral-800";+ const colorClass = value > 0 ? getColorIntensity(value) : "bg-neutral-50 dark:bg-neutral-850";return (<Tooltip key={day}><TooltipTrigger asChild>diff --git a/client/src/app/components/Footer.tsx b/client/src/app/components/Footer.tsxindex 618a2c6d2..adaf71290 100644--- a/client/src/app/components/Footer.tsx+++ b/client/src/app/components/Footer.tsx@@ -3,6 +3,7 @@ import Link from "next/link";import { IS_CLOUD } from "../../lib/const";import { useWhiteLabel } from "../../hooks/useIsWhiteLabel";import { HeartIcon } from "lucide-react";+import { Button } from "../../components/ui/button";export function Footer() {const APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION;@@ -24,14 +25,11 @@ export function Footer() {<div className="text-sm text-neutral-600 dark:text-neutral-200">Liking Rybbit? Consider sponsoring the project!</div>- <a- href="https://github.com/sponsors/goldflag"- target="_blank"- rel="noopener noreferrer"- className="inline-flex items-center gap-2 px-4 py-2 bg-neutral-200 hover:bg-neutral-300 text-neutral-800 dark:bg-neutral-800 dark:hover:bg-neutral-700 dark:text-neutral-200 rounded-lg transition-colors text-sm"- >- <HeartIcon className="w-5 h-5 text-red-500" strokeWidth={3} />- Sponsor us+ <a href="https://github.com/sponsors/goldflag" target="_blank" rel="noopener noreferrer">+ <Button>+ <HeartIcon className="w-5 h-5 text-red-500" strokeWidth={3} />+ Sponsor us+ </Button></a></div>)}diff --git a/client/src/components/SpinningGlobe.tsx b/client/src/components/SpinningGlobe.tsxindex ae24e62ea..6265d868f 100644--- a/client/src/components/SpinningGlobe.tsx+++ b/client/src/components/SpinningGlobe.tsx@@ -130,7 +130,7 @@ export function SpinningGlobe() {queryKey: ["demo-sessions"],queryFn: async () => {const response = await fetch(- "https://demo.rybbit.com/api/sessions/1?past_minutes_start=120&past_minutes_end=0&filters=[]&page=1&limit=100"+ "https://demo.rybbit.com/api/sites/1/sessions?past_minutes_start=120&past_minutes_end=0&filters=[]&page=1&limit=100");return response.json();},diff --git a/docs/content/docs/api/organizations.mdx b/docs/content/docs/api/organizations.mdxindex 22c669b01..07fbe7a16 100644--- a/docs/content/docs/api/organizations.mdx+++ b/docs/content/docs/api/organizations.mdx@@ -16,10 +16,6 @@ See the [API Reference](/docs/api/getting-started) for authentication details.<span className="px-2 py-1 text-xs font-bold rounded bg-green-500/20 text-green-600 dark:text-green-400">GET</span><code className="text-sm">/api/organizations</code></a>- <a href="#get-organization-sites" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline">- <span className="px-2 py-1 text-xs font-bold rounded bg-green-500/20 text-green-600 dark:text-green-400">GET</span>- <code className="text-sm">/api/organizations/:organizationId/sites</code>- </a><a href="#create-site" className="flex items-center gap-3 p-3 rounded-lg bg-fd-secondary/50 hover:bg-fd-secondary transition-colors no-underline"><span className="px-2 py-1 text-xs font-bold rounded bg-blue-500/20 text-blue-600 dark:text-blue-400">POST</span><code className="text-sm">/api/organizations/:organizationId/sites</code>@@ -83,6 +79,10 @@ Returns an array of organization objects.description: 'Array of organization members',type: 'array',},+ sites: {+ description: 'Array of sites in the organization',+ type: 'array',+ },}}/>@@ -136,6 +136,52 @@ Each member in the `members` array contains:}}/>+#### Site Object++Each site in the `sites` array contains:++<TypeTable+ type={{+ id: {+ description: 'Site ID',+ type: 'string',+ },+ domain: {+ description: 'Site domain',+ type: 'string',+ },+ name: {+ description: 'Site name',+ type: 'string',+ },+ organizationId: {+ description: 'Organization ID',+ type: 'string',+ },+ createdBy: {+ description: 'User ID who created the site',+ type: 'string',+ },+ public: {+ description: 'Whether analytics are publicly accessible',+ type: 'boolean',+ },+ saltUserIds: {+ description: 'Whether user IDs are salted',+ type: 'boolean',+ },+ blockBots: {+ description: 'Whether bot traffic is blocked',+ type: 'boolean',+ },+ createdAt: {+ description: 'Site creation timestamp',+ type: 'string',+ typeDescription: 'ISO 8601 datetime',+ },+ }}+/>+</div><div className="flex flex-col gap-4">@@ -282,6 +328,19 @@ var data = await response.Content.ReadAsStringAsync();"email": "[email protected]"}}+ ],+ "sites": [+ {+ "id": "456",+ "domain": "example.com",+ "name": "My Website",+ "organizationId": "org_123",+ "createdBy": "user_xyz789",+ "public": false,+ "saltUserIds": false,+ "blockBots": true,+ "createdAt": "2024-01-15T10:30:00.000Z"+ }]},{@@ -314,6 +373,19 @@ var data = await response.Content.ReadAsStringAsync();"email": "[email protected]"}}+ ],+ "sites": [+ {+ "id": "789",+ "domain": "techstartup.com",+ "name": "Tech Startup Website",+ "organizationId": "org_456",+ "createdBy": "user_owner123",+ "public": true,+ "saltUserIds": false,+ "blockBots": true,+ "createdAt": "2024-03-10T08:00:00.000Z"+ }]}]@@ -324,291 +396,6 @@ var data = await response.Content.ReadAsStringAsync();----## Get Organization Sites--<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">-<div>--```-GET /api/organizations/:organizationId/sites-```--Returns all sites within an organization along with session counts from the last 24 hours and subscription information. Requires membership in the organization.--### Path Parameters--<TypeTable- type={{- organizationId: {- description: 'Organization ID',- type: 'string',- required: true,- },- }}-/>--### Response--<TypeTable- type={{- organization: {- description: 'Organization details',- type: 'object | null',- },- sites: {- description: 'Array of sites in the organization',- type: 'array',- },- subscription: {- description: 'Subscription and usage information',- type: 'object',- },- }}-/>--#### Site Object--Each site in the `sites` array contains:--<TypeTable- type={{- siteId: {- description: 'Numeric site ID',- type: 'number',- },- id: {- description: 'Site UUID',- type: 'string',- },- domain: {- description: 'Site domain',- type: 'string',- },- name: {- description: 'Site name',- type: 'string',- },- organizationId: {- description: 'Organization ID',- type: 'string',- },- createdBy: {- description: 'User ID who created the site',- type: 'string',- },- public: {- description: 'Whether analytics are publicly accessible',- type: 'boolean',- },- saltUserIds: {- description: 'Whether user IDs are salted',- type: 'boolean',- },- blockBots: {- description: 'Whether bot traffic is blocked',- type: 'boolean',- },- sessionsLast24Hours: {- description: 'Number of unique sessions in the last 24 hours',- type: 'number',- },- isOwner: {- description: 'Whether the current user has admin/owner role',- type: 'boolean',- },- }}-/>--#### Subscription Object--<TypeTable- type={{- monthlyEventCount: {- description: 'Total events used this month',- type: 'number',- },- eventLimit: {- description: 'Monthly event limit for the subscription',- type: 'number',- },- overMonthlyLimit: {- description: 'Whether the event limit has been exceeded',- type: 'boolean',- },- planName: {- description: 'Subscription plan name',- type: 'string',- },- status: {- description: 'Subscription status',- type: 'string',- },- isPro: {- description: 'Whether this is a pro plan',- type: 'boolean',- },- }}-/>--</div>-<div className="flex flex-col gap-4">--<Tabs items={['cURL', 'JavaScript', 'Python', 'PHP', 'Ruby', 'Go', 'Rust', 'Java', '.NET']}>- <Tab value="cURL">-```bash title="Request"-curl -X GET "https://api.rybbit.io/api/organizations/org_123/sites" \- -H "Authorization: Bearer your_api_key_here"-```- </Tab>- <Tab value="JavaScript">-```javascript title="Request"-const organizationId = 'org_123';-const response = await fetch(- `https://api.rybbit.io/api/organizations/${organizationId}/sites`,- {- headers: {- 'Authorization': 'Bearer your_api_key_here'- }- }-);--const data = await response.json();-```- </Tab>- <Tab value="Python">-```python title="Request"-import requests--organization_id = 'org_123'-response = requests.get(- f'https://api.rybbit.io/api/organizations/{organization_id}/sites',- headers={- 'Authorization': 'Bearer your_api_key_here'- }-)--data = response.json()-```- </Tab>- <Tab value="PHP">-```php title="Request"-$organizationId = 'org_123';-$ch = curl_init();-curl_setopt($ch, CURLOPT_URL, "https://api.rybbit.io/api/organizations/{$organizationId}/sites");-curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);-curl_setopt($ch, CURLOPT_HTTPHEADER, [- 'Authorization: Bearer your_api_key_here'-]);--$response = curl_exec($ch);-curl_close($ch);--$data = json_decode($response, true);-```- </Tab>- <Tab value="Ruby">-```ruby title="Request"-require 'net/http'-require 'json'--organization_id = 'org_123'-uri = URI("https://api.rybbit.io/api/organizations/#{organization_id}/sites")-req = Net::HTTP::Get.new(uri)-req['Authorization'] = 'Bearer your_api_key_here'--res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }-data = JSON.parse(res.body)-```- </Tab>- <Tab value="Go">-```go title="Request"-organizationId := "org_123"-req, _ := http.NewRequest("GET", "https://api.rybbit.io/api/organizations/"+organizationId+"/sites", nil)-req.Header.Set("Authorization", "Bearer your_api_key_here")--client := &http.Client{}-resp, _ := client.Do(req)-defer resp.Body.Close()--var data map[string]interface{}-json.NewDecoder(resp.Body).Decode(&data)-```- </Tab>- <Tab value="Rust">-```rust title="Request"-let organization_id = "org_123";-let client = reqwest::Client::new();-let res = client- .get(format!("https://api.rybbit.io/api/organizations/{}/sites", organization_id))- .header("Authorization", "Bearer your_api_key_here")- .send()- .await?;--let data: serde_json::Value = res.json().await?;-```- </Tab>- <Tab value="Java">-```java title="Request"-String organizationId = "org_123";-HttpClient client = HttpClient.newHttpClient();-HttpRequest request = HttpRequest.newBuilder()- .uri(URI.create("https://api.rybbit.io/api/organizations/" + organizationId + "/sites"))- .header("Authorization", "Bearer your_api_key_here")- .GET()- .build();--HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());-```- </Tab>- <Tab value=".NET">-```csharp title="Request"-var organizationId = "org_123";-using var client = new HttpClient();-client.DefaultRequestHeaders.Add("Authorization", "Bearer your_api_key_here");--var response = await client.GetAsync($"https://api.rybbit.io/api/organizations/{organizationId}/sites");-var data = await response.Content.ReadAsStringAsync();-```- </Tab>-</Tabs>--```json title="Response"-{- "organization": {- "id": "org_123",- "name": "Acme Inc"- },- "sites": [- {- "siteId": 456,- "id": "site_abc123",- "domain": "example.com",- "name": "My Website",- "organizationId": "org_123",- "createdBy": "user_xyz789",- "public": false,- "saltUserIds": false,- "blockBots": true,- "sessionsLast24Hours": 1247,- "isOwner": true- }- ],- "subscription": {- "monthlyEventCount": 45230,- "eventLimit": 100000,- "overMonthlyLimit": false,- "planName": "pro",- "status": "active",- "isPro": true- }-}-```--</div>-</div>------## Create Site<div className="grid grid-cols-1 xl:grid-cols-2 gap-8">diff --git a/docs/src/components/SpinningGlobe.tsx b/docs/src/components/SpinningGlobe.tsxindex 955b6ac3a..237166ccf 100644--- a/docs/src/components/SpinningGlobe.tsx+++ b/docs/src/components/SpinningGlobe.tsx@@ -602,7 +602,7 @@ export function SpinningGlobe() {const fetchSessions = async () => {try {const response = await fetch(- "https://demo.rybbit.com/api/sessions/1?past_minutes_start=120&past_minutes_end=0&filters=[]&page=1&limit=100"+ "https://demo.rybbit.com/api/sites/1/sessions?past_minutes_start=120&past_minutes_end=0&filters=[]&page=1&limit=100");const data = await response.json();setSessions(data.data || []);diff --git a/server/package-lock.json b/server/package-lock.jsonindex f29927c05..49ca57e70 100644--- a/server/package-lock.json+++ b/server/package-lock.json@@ -1,12 +1,12 @@{"name": "rybbit-backend",- "version": "2.2.4",+ "version": "2.3.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "rybbit-backend",- "version": "2.2.4",+ "version": "2.3.0","dependencies": {"@aws-sdk/client-s3": "^3.842.0","@axiomhq/pino": "^1.3.1",diff --git a/server/package.json b/server/package.jsonindex da336b3aa..9b1dfc5a8 100644--- a/server/package.json+++ b/server/package.json@@ -1,6 +1,6 @@{"name": "rybbit-backend",- "version": "2.2.4",+ "version": "2.3.0","description": "Rybbit backend","main": "dist/index.js","type": "module",diff --git a/server/src/api/user/getMyOrganizations.ts b/server/src/api/user/getMyOrganizations.tsindex 682c40db1..bf3a19919 100644--- a/server/src/api/user/getMyOrganizations.ts+++ b/server/src/api/user/getMyOrganizations.ts@@ -1,7 +1,7 @@import { FastifyRequest, FastifyReply } from "fastify";import { db } from "../../db/postgres/postgres.js";import { eq } from "drizzle-orm";-import { member, organization, user } from "../../db/postgres/schema.js";+import { member, organization, sites, user } from "../../db/postgres/schema.js";import { getUserIdFromRequest } from "../../lib/auth-utils.js";export const getMyOrganizations = async (request: FastifyRequest, reply: FastifyReply) => {@@ -25,24 +25,41 @@ export const getMyOrganizations = async (request: FastifyRequest, reply: Fastify.innerJoin(organization, eq(member.organizationId, organization.id)).where(eq(member.userId, userId));- // For each organization, get all members with user details- const organizationsWithMembers = await Promise.all(+ // For each organization, get all members with user details and sites+ const organizationsWithMembersAndSites = await Promise.all(userOrganizations.map(async org => {- const organizationMembers = await db- .select({- id: member.id,- role: member.role,- userId: member.userId,- organizationId: member.organizationId,- createdAt: member.createdAt,- // User fields- userName: user.name,- userEmail: user.email,- userActualId: user.id,- })- .from(member)- .leftJoin(user, eq(member.userId, user.id))- .where(eq(member.organizationId, org.id));+ const [organizationMembers, organizationSites] = await Promise.all([+ db+ .select({+ id: member.id,+ role: member.role,+ userId: member.userId,+ organizationId: member.organizationId,+ createdAt: member.createdAt,+ // User fields+ userName: user.name,+ userEmail: user.email,+ userActualId: user.id,+ })+ .from(member)+ .leftJoin(user, eq(member.userId, user.id))+ .where(eq(member.organizationId, org.id)),+ db+ .select({+ siteId: sites.siteId,+ siteUuid: sites.id,+ domain: sites.domain,+ name: sites.name,+ organizationId: sites.organizationId,+ createdBy: sites.createdBy,+ public: sites.public,+ saltUserIds: sites.saltUserIds,+ blockBots: sites.blockBots,+ createdAt: sites.createdAt,+ })+ .from(sites)+ .where(eq(sites.organizationId, org.id)),+ ]);return {id: org.id,@@ -62,11 +79,22 @@ export const getMyOrganizations = async (request: FastifyRequest, reply: Fastifyemail: m.userEmail,},})),+ sites: organizationSites.map(site => ({+ id: String(site.siteId ?? site.siteUuid),+ domain: site.domain,+ name: site.name,+ organizationId: site.organizationId,+ createdBy: site.createdBy,+ public: site.public,+ saltUserIds: site.saltUserIds,+ blockBots: site.blockBots,+ createdAt: site.createdAt,+ })),};}));- return reply.send(organizationsWithMembers);+ return reply.send(organizationsWithMembersAndSites);} catch (error) {console.error("Error fetching organizations with members:", error);return reply.status(500).send({ error: "Failed to fetch organizations" });diff --git a/server/src/index.ts b/server/src/index.tsindex 02400b108..1bf907a1c 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -287,7 +287,7 @@ async function analyticsRoutes(fastify: FastifyInstance) {async function sessionReplayRoutes(fastify: FastifyInstance) {// Session Replay- fastify.post("/sites/:siteId/session-replay/record", recordSessionReplay); // Public - tracking endpoint+ fastify.post("/session-replay/record/:siteId", recordSessionReplay); // Public - tracking endpointfastify.get("/sites/:siteId/session-replay/list", publicSite, getSessionReplays);fastify.get("/sites/:siteId/session-replay/:sessionId", publicSite, getSessionReplayEvents);fastify.delete("/sites/:siteId/session-replay/:sessionId", authSite, deleteSessionReplay);