📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Navigation fixes
Blue Mouse006656474f94
diff --git a/web/app/components/ToolsNav.tsx b/web/app/components/ToolsNav.tsxindex 557a68946..49d176a84 100644--- a/web/app/components/ToolsNav.tsx+++ b/web/app/components/ToolsNav.tsx@@ -139,6 +139,7 @@ interface ToolsNavProps {export function ToolsNav({ className }: ToolsNavProps) {const location = useLocation()+ const strippedPath = stripLangFromPath(location.pathname)return (<nav@@ -148,7 +149,7 @@ export function ToolsNav({ className }: ToolsNavProps) {)}>{TOOLS.map((tool, index) => {- const isActive = stripLangFromPath(location.pathname) === tool.href+ const isActive = strippedPath === tool.hrefconst Icon = tool.iconreturn (@@ -194,10 +195,9 @@ export function ToolsNav({ className }: ToolsNavProps) {export function ToolsNavMobile({ className }: ToolsNavProps) {const location = useLocation()const [isOpen, setIsOpen] = useState(false)+ const strippedPath = stripLangFromPath(location.pathname)- const currentTool = TOOLS.find(- (tool) => tool.href === stripLangFromPath(location.pathname),- )+ const currentTool = TOOLS.find((tool) => tool.href === strippedPath)const CurrentIcon = currentTool?.iconreturn (@@ -235,33 +235,33 @@ export function ToolsNavMobile({ className }: ToolsNavProps) {{isOpen && (<div className='border-t border-gray-100 dark:border-slate-700'>- {TOOLS.filter(- (tool) => tool.href !== stripLangFromPath(location.pathname),- ).map((tool, index) => {- const Icon = tool.icon+ {TOOLS.filter((tool) => tool.href !== strippedPath).map(+ (tool, index) => {+ const Icon = tool.icon- return (- <Link- key={tool.id}- to={tool.href}- className={cn(- 'flex items-start gap-3 px-4 py-3 transition-colors hover:bg-gray-50 dark:hover:bg-slate-700/30',- index !== 0 &&- 'border-t border-gray-100 dark:border-slate-700',- )}- >- <Icon className='mt-0.5 h-5 w-5 shrink-0 text-gray-400 dark:text-gray-500' />- <div className='min-w-0'>- <Text as='p' size='sm' weight='medium' colour='muted'>- {tool.title}- </Text>- <Text as='p' size='xs' colour='muted'>- {tool.description}- </Text>- </div>- </Link>- )- })}+ return (+ <Link+ key={tool.id}+ to={tool.href}+ className={cn(+ 'flex items-start gap-3 px-4 py-3 transition-colors hover:bg-gray-50 dark:hover:bg-slate-700/30',+ index !== 0 &&+ 'border-t border-gray-100 dark:border-slate-700',+ )}+ >+ <Icon className='mt-0.5 h-5 w-5 shrink-0 text-gray-400 dark:text-gray-500' />+ <div className='min-w-0'>+ <Text as='p' size='sm' weight='medium' colour='muted'>+ {tool.title}+ </Text>+ <Text as='p' size='xs' colour='muted'>+ {tool.description}+ </Text>+ </div>+ </Link>+ )+ },+ )}</div>)}</div>diff --git a/web/app/pages/Auth/Signin/Signin.tsx b/web/app/pages/Auth/Signin/Signin.tsxindex 4738f9ad7..3080dcad3 100644--- a/web/app/pages/Auth/Signin/Signin.tsx+++ b/web/app/pages/Auth/Signin/Signin.tsx@@ -27,6 +27,7 @@ import Input from '~/ui/Input'import { Text } from '~/ui/Text'import Tooltip from '~/ui/Tooltip'import { cn, delay, openBrowserWindow } from '~/utils/generic'+import { localiseTo } from '~/utils/i18nHref'import routes from '~/utils/routes'import { MIN_PASSWORD_CHARS } from '~/utils/validator'@@ -45,7 +46,7 @@ const Signin = () => {const actionData = useActionData<LoginActionData>()const twoFAFetcher = useFetcher<LoginActionData>()const [searchParams] = useSearchParams()- const { t } = useTranslation('common')+ const { t, i18n } = useTranslation('common')const { theme } = useTheme()const [dontRemember, setDontRemember] = useState(false)@@ -226,7 +227,7 @@ const Signin = () => {setIsAuthenticated(true)setTotalMonthlyEvents(totalMonthlyEvents)- navigate(decidePostAuthRedirect(user))+ navigate(localiseTo(decidePostAuthRedirect(user), i18n.language))return} catch {@@ -298,7 +299,7 @@ const Signin = () => {}),)- navigate(decidePostAuthRedirect(user))+ navigate(localiseTo(decidePostAuthRedirect(user), i18n.language))} catch (error) {setLinkingError(error instanceof Errordiff --git a/web/app/pages/Auth/Signup/Signup.tsx b/web/app/pages/Auth/Signup/Signup.tsxindex 20f2ce5f3..50c1298d9 100644--- a/web/app/pages/Auth/Signup/Signup.tsx+++ b/web/app/pages/Auth/Signup/Signup.tsx@@ -31,6 +31,7 @@ import PasswordStrength from '~/ui/PasswordStrength'import { Text } from '~/ui/Text'import Tooltip from '~/ui/Tooltip'import { cn, delay, openBrowserWindow } from '~/utils/generic'+import { localiseTo } from '~/utils/i18nHref'import routes from '~/utils/routes'import { MIN_PASSWORD_CHARS } from '~/utils/validator'@@ -51,7 +52,7 @@ const featureKeys = [] as constconst Signup = () => {- const { t } = useTranslation('common')+ const { t, i18n } = useTranslation('common')const { theme } = useTheme()const navigate = useNavigate()const navigation = useNavigation()@@ -179,7 +180,7 @@ const Signup = () => {'An account with this email already exists. Please sign in to link your account.',)setIsSsoLoading(false)- navigate(routes.signin)+ navigate(localiseTo(routes.signin, i18n.language))return}@@ -188,7 +189,12 @@ const Signup = () => {if (user.isTwoFactorAuthenticationEnabled) {setUser(user)- navigate(`${routes.signin}?show_2fa_screen=true`)+ navigate(+ localiseTo(+ `${routes.signin}?show_2fa_screen=true`,+ i18n.language,+ ),+ )setIsSsoLoading(false)return}@@ -198,9 +204,9 @@ const Signup = () => {setTotalMonthlyEvents(totalMonthlyEvents)if (!user.hasCompletedOnboarding) {- navigate(routes.onboarding)+ navigate(localiseTo(routes.onboarding, i18n.language))} else {- navigate(routes.dashboard)+ navigate(localiseTo(routes.dashboard, i18n.language))}returndiff --git a/web/app/pages/OpenStartup/index.tsx b/web/app/pages/OpenStartup/index.tsxindex a00d51d92..10e588acb 100644--- a/web/app/pages/OpenStartup/index.tsx+++ b/web/app/pages/OpenStartup/index.tsx@@ -2,7 +2,6 @@import billboard, { bar, line } from 'billboard.js'import { useEffect } from 'react'import { useTranslation, Trans } from 'react-i18next'-import { Link } from '~/ui/Link'import { LIVE_DEMO_URL } from '~/lib/constants'import { Stats } from '~/lib/models/Stats'@@ -482,8 +481,10 @@ const OpenStartup = ({ stats }: OpenStartupProps) => {i18nKey='open.usage.live'components={{livedemo: (- <Link- to={LIVE_DEMO_URL}+ <a+ href={LIVE_DEMO_URL}+ target='_blank'+ rel='noopener noreferrer'className='font-medium underline decoration-dashed hover:decoration-solid'/>),diff --git a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsxindex 429c34afa..f5328d63d 100644--- a/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx+++ b/web/app/pages/Project/View/components/LiveVisitorsDropdown.tsx@@ -2,6 +2,7 @@ import { CaretDownIcon, XIcon } from '@phosphor-icons/react'import _map from 'lodash/map'import React, { useState } from 'react'import { useTranslation } from 'react-i18next'+import { useLocation } from 'react-router'import { Link } from '~/ui/Link'import type { LiveVisitorInfo } from '~/api/api.server'@@ -18,6 +19,7 @@ import { useCurrentProject } from '../../../../providers/CurrentProjectProvider'const LiveVisitorsDropdown = () => {const { id, liveVisitors, updateLiveVisitors } = useCurrentProject()const { t } = useTranslation()+ const location = useLocation()const [isDropdownVisible, setIsDropdownVisible] = useState(false)const [isLoading, setIsLoading] = useState(true)const [liveInfo, setLiveInfo] = useState<LiveVisitorInfo[]>([])@@ -118,16 +120,15 @@ const LiveVisitorsDropdown = () => {<div className='table w-full border-separate border-spacing-y-2'><div className='table-row-group'>{_map(liveInfo, ({ psid, dv, br, os, cc }) => {- const psidUrl = new URL(window.location.href)- psidUrl.searchParams.set('psid', psid)- psidUrl.searchParams.set('tab', PROJECT_TABS.sessions)- const stringifiedUrl = psidUrl.toString()+ const params = new URLSearchParams(location.search)+ params.set('psid', psid)+ params.set('tab', PROJECT_TABS.sessions)return (<Linkkey={psid}className='group table-row cursor-pointer text-sm text-gray-900 dark:text-gray-50'- to={stringifiedUrl}+ to={{ search: params.toString() }}><div className='table-cell rounded-l-lg bg-gray-100 pr-2 align-middle transition-colors group-hover:bg-gray-200 dark:bg-slate-900 dark:group-hover:bg-slate-700'><Flagdiff --git a/web/app/root.tsx b/web/app/root.tsxindex eec3baf0d..654ccc105 100644--- a/web/app/root.tsx+++ b/web/app/root.tsx@@ -281,8 +281,26 @@ const removeMultipleLngParams = (url: string): string => {const readCookieLang = (request: Request): string | null => {const cookie = request.headers.get('Cookie')- const match = cookie?.match(/(?<=i18next=)[^;]*/)?.[0]- return match && whitelist.includes(match) ? match : null+ if (!cookie) return null++ for (const segment of cookie.split(';')) {+ const trimmed = segment.trim()+ const eqIdx = trimmed.indexOf('=')+ if (eqIdx === -1) continue+ const name = trimmed.slice(0, eqIdx)+ if (name !== 'i18next') continue++ const rawValue = trimmed.slice(eqIdx + 1)+ let value: string+ try {+ value = decodeURIComponent(rawValue)+ } catch {+ value = rawValue+ }+ return whitelist.includes(value) ? value : null+ }++ return null}// Decides whether to redirect an unprefixed URL to its localised counterpart@@ -383,7 +401,6 @@ export async function loader({ request }: LoaderFunctionArgs) {const loaderData = {locale,- url,theme,REMIX_ENV,isAuthed: !!user,diff --git a/web/app/routes.ts b/web/app/routes.tsindex 07eddce55..525433181 100644--- a/web/app/routes.ts+++ b/web/app/routes.ts@@ -1,26 +1,21 @@import { flatRoutes } from '@react-router/fs-routes'import type { RouteConfigEntry } from '@react-router/dev/routes'-import { localisedLanguages } from './lib/constants'+import { isUnlocalisedPath, localisedLanguages } from './lib/constants'// Routes that should always stay unprefixed (no /{lang}/... variant).// Blog content (and the catch-all that powers blog-style pages such as// /imprint, /comparisons/* etc. through routes/$.tsx) keeps its canonical// English URL so we don't fragment the SEO of long-form content.// API and internal endpoints obviously have no localisation either.-const UNPREFIXED_PATH_PATTERNS: RegExp[] = [- /^blog(\/|$)/,- /^api(\/|$)/,- /^backend(\/|$)/,- /^_internal_data/,- /^ping$/,- /\.txt$/,- /\.xml$/,-]-+//+// The canonical allowlist lives in lib/constants (UNLOCALISED_PATH_PATTERNS).+// Route file paths arrive here without a leading slash, so we add one before+// delegating to the shared helper to keep both lists in sync.const isUnprefixedPath = (path: string | undefined): boolean => {- if (path === '*' || path === undefined) return path === '*'- return UNPREFIXED_PATH_PATTERNS.some((re) => re.test(path))+ if (path === undefined) return false+ if (path === '*') return true+ return isUnlocalisedPath(`/${path}`)}const cloneSubtreeIds = (diff --git a/web/app/routes/$.tsx b/web/app/routes/$.tsxindex a90f9fecf..34d005c22 100644--- a/web/app/routes/$.tsx+++ b/web/app/routes/$.tsx@@ -3,7 +3,11 @@ import type { LoaderFunctionArgs, MetaFunction } from 'react-router'import { data, redirect, useLoaderData } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'-import { getLangFromPath, getOgImageUrl } from '~/lib/constants'+import {+ defaultLanguage,+ getLangFromPath,+ getOgImageUrl,+} from '~/lib/constants'import Post from '~/pages/Blog/Post'import NotFound from '~/pages/NotFound'import { getPost } from '~/utils/getPosts.server'@@ -53,6 +57,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const url = new URL(request.url)return redirect(`/${stripped}${url.search}`, 301)}+ } else if (catchAllPath.startsWith(`${defaultLanguage}/`)) {+ // /en/imprint → /imprint (default language is never present in the path)+ const stripped = catchAllPath.slice(`${defaultLanguage}/`.length)+ if (stripped) {+ const url = new URL(request.url)+ return redirect(`/${stripped}${url.search}`, 301)+ }}const post = await getPost(request, catchAllPath, undefined, true)diff --git a/web/app/routes/_index.tsx b/web/app/routes/_index.tsxindex 98d9f3703..28efb7c63 100644--- a/web/app/routes/_index.tsx+++ b/web/app/routes/_index.tsx@@ -25,9 +25,9 @@ import MarketingPricing from '~/components/pricing/MarketingPricing'import useBreakpoint from '~/hooks/useBreakpoint'import {LIVE_DEMO_URL,- defaultLanguage,isSelfhosted,isDisableMarketingPages,+ localisePath,} from '~/lib/constants'import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'import { Stats } from '~/lib/models/Stats'@@ -312,11 +312,13 @@ const LiveDemoPreview = () => {)}+ const localisedDemoPath = localisePath('/projects/STEzHcB1rALV', language)+return (<div className='group relative -mr-6 ml-auto w-[140%] overflow-hidden rounded-2xl bg-gray-50 shadow-lg ring-1 ring-black/5 transition-shadow ease-out will-change-transform sm:-mr-12 sm:w-[160%] lg:-mr-16 lg:w-[180%] xl:-mr-24 2xl:-mr-32 dark:bg-slate-950 dark:ring-white/10'><div className='pointer-events-none relative h-[580px] lg:h-[640px] xl:h-[700px]'><iframe- src={`https://swetrix.com${language === defaultLanguage ? '' : `/${language}`}/projects/STEzHcB1rALV?tab=traffic&theme=${theme}&embedded=true`}+ src={`https://swetrix.com${localisedDemoPath}?tab=traffic&theme=${theme}&embedded=true`}className='size-full'title='Swetrix Analytics Live Demo'style={{ pointerEvents: 'none' }}diff --git a/web/app/routes/google-analytics-alternative.tsx b/web/app/routes/google-analytics-alternative.tsxindex 8558d9fd2..3a3b28235 100644--- a/web/app/routes/google-analytics-alternative.tsx+++ b/web/app/routes/google-analytics-alternative.tsx@@ -25,6 +25,7 @@ import {TRIAL_DAYS,isDisableMarketingPages,isSelfhosted,+ localisePath,} from '~/lib/constants'import { useTheme } from '~/providers/ThemeProvider'import { cn } from '~/utils/generic'@@ -146,10 +147,15 @@ const Testimonials = ({ className }: { className?: string }) => {}const LiveDemoPreview = () => {- const { t } = useTranslation('common')+ const {+ t,+ i18n: { language },+ } = useTranslation('common')const { theme } = useTheme()const isUpToLg = !useBreakpoint('lg')+ const localisedDemoPath = localisePath('/projects/STEzHcB1rALV', language)+if (isUpToLg) {return (<div className='relative z-20 mx-auto mt-10 overflow-hidden rounded-xl ring-2 ring-gray-900/10 dark:ring-white/10'>@@ -186,7 +192,7 @@ const LiveDemoPreview = () => {<div className='group relative -mr-6 ml-auto w-[140%] overflow-hidden rounded-2xl bg-white shadow-lg ring-1 ring-black/5 transition-shadow ease-out sm:-mr-12 sm:w-[160%] lg:-mr-16 lg:w-[180%] xl:-mr-24 2xl:-mr-32 dark:bg-slate-800 dark:ring-white/10'><div className='pointer-events-none relative h-[580px] lg:h-[640px] xl:h-[700px]'><iframe- src={`https://swetrix.com/projects/STEzHcB1rALV?tab=traffic&theme=${theme}&embedded=true&lng=en`}+ src={`https://swetrix.com${localisedDemoPath}?tab=traffic&theme=${theme}&embedded=true`}className='size-full'title='Swetrix Analytics Live Demo'style={{ pointerEvents: 'none' }}