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!

Make collapsed mode work without embedded

Blue Mouse29f8a298305f
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 e0beab4c8..db0bcdb77 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
@@ -19,7 +19,7 @@ Now you need to write the HTML code for the iframe. You can do this in any text
```html
<iframe
- src="https://swetrix.com/projects/YOUR_PROJECT_ID?tab=traffic&theme=dark"
+ src="https://swetrix.com/projects/YOUR_PROJECT_ID?tab=traffic&theme=dark&embedded=true"
width="1200"
height="700"
title="Test"
@@ -45,5 +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`.
+- `collapsed`: if set to `true`, the sidebar will be collapsed by default.
- `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/components/ProjectSidebar.tsx b/web/app/pages/Project/View/components/ProjectSidebar.tsx
index 0d80ff01c..742691dc5 100644
--- a/web/app/pages/Project/View/components/ProjectSidebar.tsx
+++ b/web/app/pages/Project/View/components/ProjectSidebar.tsx
@@ -340,19 +340,27 @@ const ProjectSidebar: React.FC<ProjectSidebarProps> = ({
[websiteUrl],
)
const { t } = useTranslation('common')
+ const shouldCollapseByDefault = searchParams.get('collapsed') === 'true'
const [isCollapsed, setIsCollapsed] = useState(() => {
- if (isEmbedded) {
- return searchParams.get('collapsed') === 'true'
+ if (shouldCollapseByDefault) {
+ return true
}
- if (typeof window !== 'undefined') {
+ if (!isEmbedded && typeof window !== 'undefined') {
return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === 'true'
}
+
return false
})
const [isScrolled, setIsScrolled] = useState(false)
+ useEffect(() => {
+ if (shouldCollapseByDefault) {
+ setIsCollapsed(true)
+ }
+ }, [shouldCollapseByDefault])
+
useEffect(() => {
if (isEmbedded) return undefined
diff --git a/web/app/providers/CurrentProjectProvider.tsx b/web/app/providers/CurrentProjectProvider.tsx
index 26f5ae0d6..f3798739f 100644
--- a/web/app/providers/CurrentProjectProvider.tsx
+++ b/web/app/providers/CurrentProjectProvider.tsx
@@ -126,8 +126,8 @@ const useProject = (id: string) => {
const [isPasswordRequired, setIsPasswordRequired] = useState(
() => loaderData?.isPasswordRequired || false,
)
- const [isCheckingStoredPassword, setIsCheckingStoredPassword] = useState(
- () => Boolean(loaderData?.isPasswordRequired && storedPassword),
+ const [isCheckingStoredPassword, setIsCheckingStoredPassword] = useState(() =>
+ Boolean(loaderData?.isPasswordRequired && storedPassword),
)
const passwordFetcher = useFetcher<ProjectViewActionData>()