Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Add 'collapsed' option to dashboard embedded mode

Blue Mouseebf668d388d2
diff --git a/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx b/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx
index e860991ea..e0beab4c8 100644
--- a/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx
+++ b/docs/content/docs/sitesettings/embed-your-analytics-dashboard-into-your-website.mdx
@@ -45,4 +45,5 @@ Here is a list of all available options:
- `tab`: `traffic`, `seo`, `performance`, `profiles`, `funnels`, `sessions`, `errors`, `goals`, `experiments`, `featureFlags`, `captcha`, `ai` - the default tab to show. By default, the traffic tab is shown.
- `tabs`: `traffic`, `seo`, `performance`, `profiles`, `funnels`, `sessions`, `errors`, `goals`, `experiments`, `featureFlags`, `captcha`, `ai` - a comma-separated list of tabs that should be accessible in dashboard. Example: `tabs=traffic,performance,sessions` will only show the traffic, performance and sessions tabs. By default, all tabs are shown.
- `embedded` - if set to `true`, header, footer and any marketing CTAs will be hidden.
+- `collapsed`: `true` or `false` - if set to `true`, the sidebar will be collapsed by default in embedded dashboards. Defaults to `false`.
- `password` - if your dashboard is password-protected, you can pass the password as a query parameter. Example: `password=yourpassword`, this way the dashboard will be unlocked without the need to enter the password.
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index a9ef664b0..0667202a2 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -1412,6 +1412,7 @@ const ViewProjectContent = () => {
dataLoading={dataLoading}
searchParams={searchParams}
allowedToManage={allowedToManage}
+ isEmbedded={isEmbedded}
isMobileOpen={isMobileSidebarOpen}
onMobileClose={closeMobileSidebar}
/>
@@ -1496,6 +1497,7 @@ const ViewProjectContent = () => {
dataLoading={dataLoading}
searchParams={searchParams}
allowedToManage={allowedToManage}
+ isEmbedded={isEmbedded}
isMobileOpen={isMobileSidebarOpen}
onMobileClose={closeMobileSidebar}
/>
diff --git a/web/app/pages/Project/View/components/ProjectSidebar.tsx b/web/app/pages/Project/View/components/ProjectSidebar.tsx
index fd2d8a328..0d80ff01c 100644
--- a/web/app/pages/Project/View/components/ProjectSidebar.tsx
+++ b/web/app/pages/Project/View/components/ProjectSidebar.tsx
@@ -341,6 +341,10 @@ const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
)
const { t } = useTranslation('common')
const [isCollapsed, setIsCollapsed] = useState(() => {
+ if (isEmbedded) {
+ return searchParams.get('collapsed') === 'true'
+ }
+
if (typeof window !== 'undefined') {
return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === 'true'
}
@@ -363,10 +367,12 @@ const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
const toggleCollapsed = useCallback(() => {
setIsCollapsed((prev) => {
const newValue = !prev
- localStorage.setItem(SIDEBAR_COLLAPSED_KEY, String(newValue))
+ if (!isEmbedded) {
+ localStorage.setItem(SIDEBAR_COLLAPSED_KEY, String(newValue))
+ }
return newValue
})
- }, [])
+ }, [isEmbedded])
useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {