Skip to content

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

support embeds

Bill Yang6a0c0267be33
diff --git a/client/src/app/[site]/components/Sidebar/MobileSidebar.tsx b/client/src/app/[site]/components/Sidebar/MobileSidebar.tsx
index 68d5edd88..d41b97ed7 100644
--- a/client/src/app/[site]/components/Sidebar/MobileSidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/MobileSidebar.tsx
@@ -10,11 +10,15 @@ import { Menu } from "lucide-react";
import { VisuallyHidden } from "radix-ui";
import { Favicon } from "../../../../components/Favicon";
import { AppSidebar } from "../../../../components/AppSidebar";
+import { useEmbedablePage } from "../../utils";
export function MobileSidebar() {
const pathname = usePathname();
const { data: site } = useGetSite(Number(pathname.split("/")[1]));
+ const embed = useEmbedablePage();
+ if (embed) return null;
+
return (
<div className="md:hidden flex items-center gap-2">
<Sheet>
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index c203a2bfc..72f702f2d 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -24,16 +24,18 @@ import { SiteSettings } from "../../../../components/SiteSettings/SiteSettings";
import { authClient } from "../../../../lib/auth";
import { IS_CLOUD } from "../../../../lib/const";
import { SiteSelector } from "./SiteSelector";
+import { useEmbedablePage } from "../../utils";
export function Sidebar() {
const session = authClient.useSession();
const pathname = usePathname();
+ const embed = useEmbedablePage();
const { data: site } = useGetSite(Number(pathname.split("/")[1]));
// Check which tab is active based on the current path
const getTabPath = (tabName: string) => {
- return `/${pathname.split("/")[1]}/${tabName.toLowerCase()}`;
+ return `/${pathname.split("/")[1]}/${tabName.toLowerCase()}${embed ? "?embed=true" : ""}`;
};
const isActiveTab = (tabName: string) => {
@@ -148,7 +150,7 @@ export function Sidebar() {
href={getTabPath("reports")}
icon={<ChartBarDecreasing className="w-4 h-4" />}
/> */}
- {session.data && (
+ {session.data && !embed && (
<>
<SidebarComponents.SectionHeader>Settings</SidebarComponents.SectionHeader>
<SiteSettings
diff --git a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
index 66e230b06..203ed46ca 100644
--- a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
+++ b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
@@ -10,10 +10,13 @@ import { resetStore, useStore } from "../../../../lib/store";
import { userStore } from "../../../../lib/userStore";
import { cn, formatter } from "../../../../lib/utils";
import { AddSite } from "../../../components/AddSite";
+import { useEmbedablePage } from "../../utils";
function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {
const { data: activeOrganization } = authClient.useActiveOrganization();
const { data: sites } = useGetSitesFromOrg(activeOrganization?.id);
+ const embed = useEmbedablePage();
+
const { setSite } = useStore();
const pathname = usePathname();
@@ -23,6 +26,8 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {
const { user } = userStore();
+ if (embed) return null;
+
if (typeof window !== "undefined" && globalThis.location.hostname === "demo.rybbit.io") {
return (
<PopoverContent align="start" className="w-52 p-2">
@@ -149,6 +154,7 @@ export function SiteSelector() {
const { site: currentSite } = useStore();
const { data: site } = useGetSite(currentSite);
const [open, setOpen] = useState(false);
+ const embed = useEmbedablePage();
return (
<Popover open={open} onOpenChange={setOpen}>
@@ -157,13 +163,13 @@ export function SiteSelector() {
<button className="flex gap-2 items-center border border-neutral-800 rounded-lg py-1.5 px-3 justify-start cursor-pointer hover:bg-neutral-800/50 transition-colors h-[36px] w-full">
<Favicon domain={site.domain} className="w-5 h-5" />
<div className="text-white truncate text-sm flex-1 text-left">{site.domain}</div>
- <ChevronDown className="w-4 h-4 text-neutral-400" />
+ {!embed && <ChevronDown className="w-4 h-4 text-neutral-400" />}
</button>
) : (
<button className="flex gap-2 border border-neutral-800 rounded-lg py-1.5 px-3 justify-start items-center h-[36px] w-full animate-pulse">
<div className="w-5 h-5 bg-neutral-800 rounded"></div>
<div className="h-4 bg-neutral-800 rounded w-24 flex-1"></div>
- <ChevronDown className="w-4 h-4 text-neutral-400" />
+ {!embed && <ChevronDown className="w-4 h-4 text-neutral-400" />}
</button>
)}
</PopoverTrigger>
diff --git a/client/src/app/[site]/utils.ts b/client/src/app/[site]/utils.ts
new file mode 100644
index 000000000..62df40354
--- /dev/null
+++ b/client/src/app/[site]/utils.ts
@@ -0,0 +1,17 @@
+"use client";
+
+import { useSearchParams } from "next/navigation";
+import { useCurrentSite } from "../../api/admin/sites";
+
+export const useEmbedablePage = () => {
+ const searchParams = useSearchParams();
+ const embed = searchParams.get("embed");
+
+ const { subscription } = useCurrentSite();
+
+ if (embed === "true" && subscription?.planName !== "free") {
+ return true;
+ }
+
+ return false;
+};
diff --git a/client/src/components/AppSidebar.tsx b/client/src/components/AppSidebar.tsx
index 777ca6732..69f242cf3 100644
--- a/client/src/components/AppSidebar.tsx
+++ b/client/src/components/AppSidebar.tsx
@@ -7,11 +7,15 @@ import { usePathname } from "next/navigation";
import { useState } from "react";
import { useAdminPermission } from "../app/admin/hooks/useAdminPermission";
import { cn } from "../lib/utils";
+import { useEmbedablePage } from "../app/[site]/utils";
export function AppSidebar() {
const pathname = usePathname();
const { isAdmin } = useAdminPermission();
const [isExpanded, setIsExpanded] = useState(false);
+ const embed = useEmbedablePage();
+
+ if (embed) return null;
return (
<div
diff --git a/client/src/lib/urlParams.ts b/client/src/lib/urlParams.ts
index c2e4ff6b2..66ea3be74 100644
--- a/client/src/lib/urlParams.ts
+++ b/client/src/lib/urlParams.ts
@@ -165,17 +165,7 @@ export const useSyncStateWithUrl = () => {
const searchParams = useSearchParams();
const pathname = usePathname();
const router = useRouter();
- const {
- time,
- bucket,
- selectedStat,
- filters,
- setTime,
- setBucket,
- setSelectedStat,
- setFilters,
- site,
- } = useStore();
+ const { time, bucket, selectedStat, filters, setTime, setBucket, setSelectedStat, setFilters, site } = useStore();
// Use a ref to track if we've already loaded from URL
// This prevents overriding user changes if the effect re-runs
@@ -243,19 +233,19 @@ export const useSyncStateWithUrl = () => {
const newSearch = params.toString();
// Only update if the search params have changed to avoid infinite loops
- const currentSearch = searchParams.toString();
+ // Create a copy of current search params without the embed param for comparison
+ const currentParamsForComparison = new URLSearchParams(searchParams);
+ currentParamsForComparison.delete("embed");
+ const currentSearch = currentParamsForComparison.toString();
+
if (newSearch !== currentSearch) {
+ // Preserve the embed param if it exists
+ const embedParam = searchParams.get("embed");
+ if (embedParam) {
+ params.set("embed", embedParam);
+ }
// Replace the current URL with the new one to avoid adding to history
- router.replace(`${pathname}?${newSearch}`);
+ router.replace(`${pathname}?${params.toString()}`);
}
- }, [
- time,
- bucket,
- selectedStat,
- filters,
- pathname,
- router,
- site,
- searchParams,
- ]); // Added searchParams
+ }, [time, bucket, selectedStat, filters, pathname, router, site, searchParams]); // Added searchParams
};