Skip to content

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

Refactor session replay components and enhance functionality

Bill Yanga174a05d543b
diff --git a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
index 45945cdbf..144feb9b0 100644
--- a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
+++ b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
@@ -83,12 +83,7 @@ export function ReplayBreadcrumbs() {
currentGroup.type === eventTypeStr &&
currentGroup.subType === subType &&
// Only group incremental events (type 3) and certain subtypes
- eventTypeStr === "3" &&
- (subType === 0 || // Mutation
- subType === 1 || // Mouse move
- subType === 2 || // Mouse interaction (click, etc.)
- subType === 3 || // Scroll
- subType === 5); // Input
+ eventTypeStr === "3";
if (shouldGroup && currentGroup) {
// Add to current group
diff --git a/client/src/app/[site]/replay/components/ReplayPlayer.tsx b/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
similarity index 96%
rename from client/src/app/[site]/replay/components/ReplayPlayer.tsx
rename to client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
index 742b02944..a0b12d977 100644
--- a/client/src/app/[site]/replay/components/ReplayPlayer.tsx
+++ b/client/src/app/[site]/replay/components/player/ReplayPlayer.tsx
@@ -3,18 +3,18 @@ import { useParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import rrwebPlayer from "rrweb-player";
import "rrweb-player/dist/style.css";
-import { useGetSessionReplayEvents } from "../../../../api/analytics/sessionReplay/useGetSessionReplayEvents";
-import { ThreeDotLoader } from "../../../../components/Loaders";
-import { ActivitySlider } from "../../../../components/ui/activity-slider";
-import { Button } from "../../../../components/ui/button";
+import { useGetSessionReplayEvents } from "../../../../../api/analytics/sessionReplay/useGetSessionReplayEvents";
+import { ThreeDotLoader } from "../../../../../components/Loaders";
+import { ActivitySlider } from "../../../../../components/ui/activity-slider";
+import { Button } from "../../../../../components/ui/button";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
-} from "../../../../components/ui/select";
-import { useReplayStore } from "./replayStore";
+} from "../../../../../components/ui/select";
+import { useReplayStore } from "../replayStore";
export function ReplayPlayer({
width,
diff --git a/client/src/app/[site]/replay/page.tsx b/client/src/app/[site]/replay/page.tsx
index 1b5d756ce..22fa586a9 100644
--- a/client/src/app/[site]/replay/page.tsx
+++ b/client/src/app/[site]/replay/page.tsx
@@ -8,7 +8,7 @@ import { SESSION_REPLAY_PAGE_FILTERS } from "../../../lib/store";
import { SubHeader } from "../components/SubHeader/SubHeader";
import { EnableSessionReplay } from "./components/EnableSessionReplay";
import { ReplayList } from "./components/ReplayList";
-import { ReplayPlayer } from "./components/ReplayPlayer";
+import { ReplayPlayer } from "./components/player/ReplayPlayer";
import { NothingFound } from "../../../components/NothingFound";
import { ReplayBreadcrumbs } from "./components/ReplayBreadcrumbs";
diff --git a/server/src/lib/const.ts b/server/src/lib/const.ts
index 45d485924..39dafad8b 100644
--- a/server/src/lib/const.ts
+++ b/server/src/lib/const.ts
@@ -18,6 +18,7 @@ export interface StripePlan {
interval: "month" | "year";
limits: {
events: number;
+ replays: number;
};
annualDiscountPriceId?: string; // Make this optional
}
@@ -29,6 +30,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 100_000,
+ replays: 10_000,
},
},
{
@@ -37,6 +39,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 100_000,
+ replays: 10_000,
},
},
{
@@ -45,6 +48,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 250_000,
+ replays: 25_000,
},
},
{
@@ -53,6 +57,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 250_000,
+ replays: 25_000,
},
},
{
@@ -61,6 +66,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 500_000,
+ replays: 50_000,
},
},
{
@@ -69,6 +75,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 500_000,
+ replays: 50_000,
},
},
{
@@ -77,6 +84,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 1_000_000,
+ replays: 100_000,
},
},
{
@@ -85,6 +93,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 1_000_000,
+ replays: 100_000,
},
},
{
@@ -93,6 +102,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 2_000_000,
+ replays: 200_000,
},
},
{
@@ -101,6 +111,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 2_000_000,
+ replays: 200_000,
},
},
{
@@ -109,6 +120,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 5_000_000,
+ replays: 500_000,
},
},
{
@@ -117,6 +129,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 5_000_000,
+ replays: 500_000,
},
},
{
@@ -125,6 +138,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "month",
limits: {
events: 10_000_000,
+ replays: 1_000_000,
},
},
{
@@ -133,6 +147,7 @@ const STRIPE_PRICES: StripePlan[] = [
interval: "year",
limits: {
events: 10_000_000,
+ replays: 1_000_000,
},
},
];
diff --git a/server/src/services/usageCheckerService.ts b/server/src/services/usageService.ts
similarity index 97%
rename from server/src/services/usageCheckerService.ts
rename to server/src/services/usageService.ts
index 9c0334bb5..faaba16ef 100644
--- a/server/src/services/usageCheckerService.ts
+++ b/server/src/services/usageService.ts
@@ -14,7 +14,7 @@ import {
} from "../lib/const.js";
import { stripe } from "../lib/stripe.js";
-export class UsageCheckerService {
+export class UsageService {
private sitesOverLimit = new Set<number>();
private usageCheckTask: cron.ScheduledTask | null = null;
@@ -32,7 +32,10 @@ export class UsageCheckerService {
try {
await this.updateOrganizationsMonthlyUsage();
} catch (error) {
- console.error("[UsageCheckerService] Error during usage check:", error);
+ console.error(
+ "[UsageCheckerService] Error during usage check:",
+ error
+ );
}
});
@@ -247,7 +250,10 @@ export class UsageCheckerService {
await this.getOrganizationSubscriptionInfo(orgData);
// Get monthly pageview count from ClickHouse using the billing period start date
- const pageviewCount = await this.getMonthlyPageviews(siteIds, periodStart);
+ const pageviewCount = await this.getMonthlyPageviews(
+ siteIds,
+ periodStart
+ );
// Check if over limit and update global set
const isOverLimit = pageviewCount > eventLimit;
@@ -316,4 +322,4 @@ export class UsageCheckerService {
}
// Create a singleton instance
-export const usageCheckerService = new UsageCheckerService();
\ No newline at end of file
+export const usageService = new UsageService();
diff --git a/server/src/tracker/utils.ts b/server/src/tracker/utils.ts
index cb4d2dba1..a744a2e62 100644
--- a/server/src/tracker/utils.ts
+++ b/server/src/tracker/utils.ts
@@ -1,7 +1,7 @@
import { FastifyRequest } from "fastify";
import UAParser, { UAParser as userAgentParser } from "ua-parser-js";
import { z } from "zod";
-import { usageCheckerService } from "../services/usageCheckerService.js";
+import { usageService } from "../services/usageService.js";
import { userIdService } from "../services/userId/userIdService.js";
import { trackingPayloadSchema } from "./trackEvent.js";
import { TrackingPayload } from "./types.js";
@@ -85,7 +85,7 @@ export function clearSelfReferrer(referrer: string, hostname: string): string {
// Check if site is over the monthly limit
export function isSiteOverLimit(siteId: number | string): boolean {
- return usageCheckerService.getSitesOverLimit().has(Number(siteId));
+ return usageService.getSitesOverLimit().has(Number(siteId));
}
// Create base tracking payload from request