This commit is contained in:
Mike Cao committed 2026-03-15 18:03:55 -07:00
commit 4aa5f8411e
23 files changed
+311 -216

No files matched your search

+3
View File
@@ -10,6 +10,7 @@ import {
TooltipTrigger,
} from '@umami/react-zen';
import Link from 'next/link';
import { AdminNav } from '@/app/(main)/admin/AdminNav';
import { SettingsNav } from '@/app/(main)/settings/SettingsNav';
import { WebsiteNav } from '@/app/(main)/websites/[websiteId]/WebsiteNav';
import { IconLabel } from '@/components/common/IconLabel';
@@ -103,6 +104,8 @@ export function SideNav(props: any) {
<WebsiteNav websiteId={websiteId} isCollapsed={isCollapsed} />
) : pathname.includes('/settings') ? (
<SettingsNav isCollapsed={isCollapsed} />
) : pathname.includes('/admin') ? (
<AdminNav />
) : (
<Column gap="2">
{links.map(({ id, path, label, icon }) => {
+1 -19
View File
@@ -1,9 +1,7 @@
'use client';
import { Column, Grid } from '@umami/react-zen';
import type { ReactNode } from 'react';
import { PageBody } from '@/components/common/PageBody';
import { useLoginQuery } from '@/components/hooks';
import { AdminNav } from './AdminNav';
export function AdminLayout({ children }: { children: ReactNode }) {
const { user } = useLoginQuery();
@@ -12,21 +10,5 @@ export function AdminLayout({ children }: { children: ReactNode }) {
return null;
}
return (
<Grid columns={{ base: '1fr', lg: 'auto 1fr' }} width="100%" height="100%">
<Column
display={{ base: 'none', lg: 'flex' }}
width="240px"
height="100%"
border="right"
marginRight="2"
padding="3"
>
<AdminNav />
</Column>
<Column gap="6" margin="2">
<PageBody>{children}</PageBody>
</Column>
</Grid>
);
return <PageBody>{children}</PageBody>;
}
+3 -4
View File
@@ -1,9 +1,9 @@
import { Column, Focusable, Row, Tooltip, TooltipTrigger } from '@umami/react-zen';
import Link from 'next/link';
import { IconLabel } from '@/components/common/IconLabel';
import { NavMenu } from '@/components/common/NavMenu';
import { useMessages, useNavigation } from '@/components/hooks';
import { ArrowLeft, Globe, User, Users } from '@/components/icons';
import { Column, Focusable, Row, Tooltip, TooltipTrigger } from '@umami/react-zen';
import Link from 'next/link';
export function AdminNav({ onItemClick }: { onItemClick?: () => void }) {
const { t, labels } = useMessages();
@@ -41,7 +41,7 @@ export function AdminNav({ onItemClick }: { onItemClick?: () => void }) {
return (
<Column gap="2">
<Link href={renderUrl('/boards', false)} role="button" onClick={onItemClick}>
<Link href={renderUrl('/websites', false)} role="button" onClick={onItemClick}>
<TooltipTrigger delay={0}>
<Focusable>
<Row
@@ -58,7 +58,6 @@ export function AdminNav({ onItemClick }: { onItemClick?: () => void }) {
</Link>
<NavMenu
items={items}
title={t(labels.admin)}
selectedKey={selectedKey}
allowMinimize={false}
onItemClick={onItemClick}
+18 -3
View File
@@ -1,12 +1,27 @@
import { Icon, Row, Text } from '@umami/react-zen';
import { Globe, Grid2x2, Link } from '@/components/icons';
import { Favicon } from '@/components/common/Favicon';
import { Grid2x2, Link } from '@/components/icons';
import type { BoardEntityType } from '@/lib/boards';
export function BoardEntityBadge({ type, name }: { type: BoardEntityType; name: string }) {
export function BoardEntityBadge({
type,
name,
domain,
}: {
type: BoardEntityType;
name: string;
domain?: string;
}) {
return (
<Row padding borderRadius="full" backgroundColor="surface-base" border gap="2">
<Icon>
{type === 'pixel' ? <Grid2x2 /> : type === 'link' ? <Link /> : <Globe />}
{type === 'pixel' ? (
<Grid2x2 />
) : type === 'link' ? (
<Link />
) : (
<Favicon domain={domain} />
)}
</Icon>
<Text size="sm">{name}</Text>
</Row>
@@ -6,9 +6,11 @@ import { getComponentDefinition } from '../boardComponentRegistry';
function BoardComponentRendererComponent({
config,
websiteId,
entityType,
}: {
config: BoardComponentConfig;
websiteId?: string;
entityType?: string;
}) {
const definition = getComponentDefinition(config.type);
@@ -20,7 +22,8 @@ function BoardComponentRendererComponent({
);
}
const Component = definition.component;
const Component =
(entityType && definition.componentByEntityType?.[entityType]) || definition.component;
if (!websiteId && definition.requiresWebsite !== false) {
return (
@@ -36,7 +39,9 @@ function BoardComponentRendererComponent({
export const BoardComponentRenderer = memo(
BoardComponentRendererComponent,
(prevProps, nextProps) =>
prevProps.websiteId === nextProps.websiteId && prevProps.config === nextProps.config,
prevProps.websiteId === nextProps.websiteId &&
prevProps.entityType === nextProps.entityType &&
prevProps.config === nextProps.config,
);
BoardComponentRenderer.displayName = 'BoardComponentRenderer';
@@ -177,14 +177,16 @@ export function BoardComponentSelect({
onSelect(config);
};
const previewConfig: BoardComponentConfig | null = selectedDef
? {
type: selectedDef.type,
title,
description,
props: { ...selectedDef.defaultProps, ...configValues },
}
: null;
const previewConfig: BoardComponentConfig | null = useMemo(
() =>
selectedDef
? {
type: selectedDef.type,
props: { ...selectedDef.defaultProps, ...configValues },
}
: null,
[selectedDef, configValues],
);
const canSave = !!selectedDef && isSelectedDefSupported && (!needsWebsite || !!resolvedEntityId);
const availableDefinitions = useMemo(
@@ -274,12 +276,16 @@ export function BoardComponentSelect({
<Select
value={String(configValues[field.name] ?? field.defaultValue ?? '')}
onChange={(value: string) => handleConfigChange(field.name, value)}
maxHeight={300}
popoverProps={{ style: { width: 220 } }}
>
{field.options?.map(option => (
<ListItem key={option.value} id={option.value}>
{option.label}
</ListItem>
))}
{(field.optionsByEntityType?.[activeEntityType] ?? field.options)?.map(
option => (
<ListItem key={option.value} id={option.value}>
{option.label}
</ListItem>
),
)}
</Select>
)}
@@ -364,7 +370,7 @@ export function BoardComponentSelect({
<Text weight="bold">Preview</Text>
<Column border="left" paddingLeft="4" height="100%" style={{ minWidth: 0 }}>
{hasSelectedEntity && previewConfig && (!needsWebsite || resolvedEntityId) ? (
<BoardComponentRenderer config={previewConfig} websiteId={resolvedEntityId} />
<BoardComponentRenderer config={previewConfig} websiteId={resolvedEntityId} entityType={resolvedEntityType} />
) : (
<Column alignItems="center" justifyContent="center" height="100%">
<Text color="muted">
@@ -1,3 +1,8 @@
import { Panel } from '@/components/common/Panel';
import { useBoard, useMessages, useNavigation } from '@/components/hooks';
import { Pencil, Plus, X } from '@/components/icons';
import { getBoardEntity, getBoardType, getResolvedComponentEntity } from '@/lib/boards';
import type { BoardComponentConfig } from '@/lib/types';
import {
Box,
Button,
@@ -10,11 +15,6 @@ import {
TooltipTrigger,
} from '@umami/react-zen';
import { useMemo, useState } from 'react';
import { Panel } from '@/components/common/Panel';
import { useBoard, useMessages, useNavigation } from '@/components/hooks';
import { Pencil, Plus, X } from '@/components/icons';
import { getBoardEntity, getBoardType, getResolvedComponentEntity } from '@/lib/boards';
import type { BoardComponentConfig } from '@/lib/types';
import { getComponentDefinition } from '../boardComponentRegistry';
import { BoardComponentRenderer } from './BoardComponentRenderer';
import { BoardComponentSelect } from './BoardComponentSelect';
@@ -42,14 +42,14 @@ export function BoardEditColumn({
const boardType = getBoardType(board);
const { entityType: boardEntityType, entityId: boardEntityId } = getBoardEntity(board);
const definition = component ? getComponentDefinition(component.type) : undefined;
const { entityId } = getResolvedComponentEntity(board, component);
const { entityType, entityId } = getResolvedComponentEntity(board, component);
const renderedComponent = useMemo(() => {
if (!component || (!entityId && definition?.requiresWebsite !== false)) {
return null;
}
return <BoardComponentRenderer config={component} websiteId={entityId} />;
}, [component, definition?.requiresWebsite, entityId]);
return <BoardComponentRenderer config={component} websiteId={entityId} entityType={entityType} />;
}, [component, definition?.requiresWebsite, entityId, entityType]);
const handleSelect = (config: BoardComponentConfig) => {
onSetComponent(id, config);
@@ -79,7 +79,7 @@ export function BoardEditColumn({
onMouseEnter={() => setShowActions(true)}
onMouseLeave={() => setShowActions(false)}
>
{canEdit && canRemoveAction && showActions && (
{canEdit && (showActions || !hasComponent) && (
<Box
position="absolute"
top="50%"
@@ -87,44 +87,39 @@ export function BoardEditColumn({
zIndex={100}
style={{ transform: 'translate(-50%, -50%)' }}
>
<Row gap="1" padding="2" borderRadius backgroundColor="surface-sunken">
{hasComponent && (
<TooltipTrigger delay={0}>
<Button variant="outline" onPress={() => setShowSelect(true)}>
<Icon size="sm">
<Pencil />
</Icon>
</Button>
<Tooltip>{t(labels.edit)}</Tooltip>
</TooltipTrigger>
)}
<Row
gap="1"
padding={hasComponent ? '2' : undefined}
borderRadius={hasComponent || undefined}
backgroundColor={hasComponent ? 'surface-sunken' : undefined}
>
<TooltipTrigger delay={0}>
<Button variant="outline" onPress={handleRemove} isDisabled={!canRemoveAction}>
<Button variant="outline" onPress={() => setShowSelect(true)}>
<Icon size="sm">
<X />
{hasComponent ? <Pencil /> : <Plus />}
</Icon>
</Button>
<Tooltip>{t(labels.remove)}</Tooltip>
<Tooltip>{t(hasComponent ? labels.edit : labels.selectComponent)}</Tooltip>
</TooltipTrigger>
{canRemoveAction && (
<TooltipTrigger delay={0}>
<Button variant="outline" onPress={handleRemove}>
<Icon size="sm">
<X />
</Icon>
</Button>
<Tooltip>{t(labels.remove)}</Tooltip>
</TooltipTrigger>
)}
</Row>
</Box>
)}
{renderedComponent ? (
{renderedComponent && (
<Column width="100%" height="100%" style={{ minHeight: 0 }}>
<Box width="100%" flexGrow={1} overflow="auto" style={{ minHeight: 0 }}>
{renderedComponent}
</Box>
</Column>
) : (
canEdit && (
<Column width="100%" height="100%" alignItems="center" justifyContent="center">
<Button variant="outline" onPress={() => setShowSelect(true)}>
<Icon>
<Plus />
</Icon>
</Button>
</Column>
)
)}
<Modal isOpen={showSelect} onOpenChange={setShowSelect}>
<Dialog
@@ -1,4 +1,4 @@
import { Box, Column } from '@umami/react-zen';
import { Column, Heading, Row, Text } from '@umami/react-zen';
import { Panel } from '@/components/common/Panel';
import { useBoard } from '@/components/hooks';
import { getBoardType, getResolvedComponentEntity, isOpenBoardType } from '@/lib/boards';
@@ -28,17 +28,23 @@ export function BoardViewColumn({
const title = component.title;
const description = component.description;
const showBadge = showEntityBadge && isOpenBoardType(boardType) && !!entityBadge;
return (
<Panel title={title} description={description} height="100%" position="relative">
{showEntityBadge && isOpenBoardType(boardType) && entityBadge && (
<Box position="absolute" top="12px" right="12px" zIndex={100}>
<Panel height="100%">
{showBadge ? (
<Row justifyContent={title ? 'space-between' : 'flex-end'} alignItems="center">
{title && <Heading>{title}</Heading>}
<BoardEntityBadge {...entityBadge} />
</Box>
</Row>
) : (
title && <Heading>{title}</Heading>
)}
{description && <Text color="muted">{description}</Text>}
<Column width="100%" height="100%" style={{ minHeight: 0 }}>
<Box width="100%" flexGrow={1} style={{ minHeight: 0 }}>
<BoardComponentRenderer config={component} websiteId={entityId} />
</Box>
<Column width="100%" flexGrow={1} style={{ minHeight: 0 }}>
<BoardComponentRenderer config={component} websiteId={entityId} entityType={entityType} />
</Column>
</Column>
</Panel>
);
@@ -1,5 +1,6 @@
import type { ComponentType } from 'react';
import { TextBlock } from '@/app/(main)/boards/TextBlock';
import { LinkMetricsBar } from '@/app/(main)/links/[linkId]/LinkMetricsBar';
import { PixelMetricsBar } from '@/app/(main)/pixels/[pixelId]/PixelMetricsBar';
import { WebsiteChart } from '@/app/(main)/websites/[websiteId]/WebsiteChart';
import { WebsiteMetricsBar } from '@/app/(main)/websites/[websiteId]/WebsiteMetricsBar';
import {
@@ -15,12 +16,14 @@ import { EventsChart } from '@/components/metrics/EventsChart';
import { MetricsTable } from '@/components/metrics/MetricsTable';
import { WeeklyTraffic } from '@/components/metrics/WeeklyTraffic';
import { WorldMap } from '@/components/metrics/WorldMap';
import type { ComponentType } from 'react';
export interface ConfigField {
name: string;
label: string;
type: 'select' | 'number' | 'text' | 'textarea';
options?: { label: string; value: string }[];
optionsByEntityType?: Record<string, { label: string; value: string }[]>;
defaultValue?: any;
}
@@ -31,6 +34,7 @@ export interface ComponentDefinition {
category: string;
icon: ComponentType<any>;
component: ComponentType<any>;
componentByEntityType?: Record<string, ComponentType<any>>;
defaultProps?: Record<string, any>;
configFields?: ConfigField[];
requiresWebsite?: boolean;
@@ -44,31 +48,60 @@ export const CATEGORIES = [
] as const;
const METRIC_TYPES = [
{ label: 'Pages', value: 'path' },
{ label: 'Entry pages', value: 'entry' },
{ label: 'Exit pages', value: 'exit' },
{ label: 'Referrers', value: 'referrer' },
{ label: 'Channels', value: 'channel' },
{ label: 'Browsers', value: 'browser' },
{ label: 'Path', value: 'path' },
{ label: 'Entry page', value: 'entry' },
{ label: 'Exit page', value: 'exit' },
{ label: 'Title', value: 'title' },
{ label: 'Query', value: 'query' },
{ label: 'Referrer', value: 'referrer' },
{ label: 'Channel', value: 'channel' },
{ label: 'Country', value: 'country' },
{ label: 'Region', value: 'region' },
{ label: 'City', value: 'city' },
{ label: 'Browser', value: 'browser' },
{ label: 'OS', value: 'os' },
{ label: 'Devices', value: 'device' },
{ label: 'Countries', value: 'country' },
{ label: 'Regions', value: 'region' },
{ label: 'Cities', value: 'city' },
{ label: 'Languages', value: 'language' },
{ label: 'Screens', value: 'screen' },
{ label: 'Query parameters', value: 'query' },
{ label: 'Page titles', value: 'title' },
{ label: 'Hosts', value: 'host' },
{ label: 'Events', value: 'event' },
{ label: 'Device', value: 'device' },
{ label: 'Language', value: 'language' },
{ label: 'Screen', value: 'screen' },
{ label: 'UTM Source', value: 'utmSource' },
{ label: 'UTM Medium', value: 'utmMedium' },
{ label: 'UTM Campaign', value: 'utmCampaign' },
{ label: 'UTM Content', value: 'utmContent' },
{ label: 'UTM Term', value: 'utmTerm' },
{ label: 'Event', value: 'event' },
{ label: 'Hostname', value: 'hostname' },
];
const PIXEL_LINK_METRIC_TYPES = METRIC_TYPES.filter(({ value }) =>
[
'referrer',
'country',
'region',
'city',
'browser',
'os',
'device',
'query',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
].includes(value),
);
const LIMIT_OPTIONS = [
{ label: '5', value: '5' },
{ label: '10', value: '10' },
{ label: '20', value: '20' },
];
const PixelMetricsBarAdapter = ({ websiteId }: { websiteId?: string }) =>
websiteId ? <PixelMetricsBar pixelId={websiteId} /> : null;
const LinkMetricsBarAdapter = ({ websiteId }: { websiteId?: string }) =>
websiteId ? <LinkMetricsBar linkId={websiteId} /> : null;
const componentDefinitions: ComponentDefinition[] = [
// Overview
{
@@ -78,6 +111,10 @@ const componentDefinitions: ComponentDefinition[] = [
category: 'overview',
icon: PanelTop,
component: WebsiteMetricsBar,
componentByEntityType: {
pixel: PixelMetricsBarAdapter,
link: LinkMetricsBarAdapter,
},
},
{
type: 'WebsiteChart',
@@ -103,6 +140,10 @@ const componentDefinitions: ComponentDefinition[] = [
label: 'Metric type',
type: 'select',
options: METRIC_TYPES,
optionsByEntityType: {
pixel: PIXEL_LINK_METRIC_TYPES,
link: PIXEL_LINK_METRIC_TYPES,
},
defaultValue: 'path',
},
{
@@ -13,7 +13,7 @@ export function useBoardEntityBadgeProps(
const { data: link } = useLinkQuery(enabled && entityType === 'link' ? entityId : undefined);
if (entityType === 'website' && website?.name) {
return { type: entityType, name: website.name };
return { type: entityType, name: website.name, domain: website.domain ?? undefined };
}
if (entityType === 'pixel' && pixel?.name) {
@@ -14,7 +14,7 @@ export function LinkMetricsBar({
}) {
const { isAllTime } = useDateRange();
const { t, labels } = useMessages();
const { data, isLoading, isFetching, error } = useWebsiteStatsQuery(linkId);
const { data, isLoading, isFetching, error } = useWebsiteStatsQuery({ websiteId: linkId });
const { pageviews, visitors, visits, comparison } = data || {};
@@ -14,7 +14,7 @@ export function PixelMetricsBar({
}) {
const { isAllTime } = useDateRange();
const { t, labels } = useMessages();
const { data, isLoading, isFetching, error } = useWebsiteStatsQuery(pixelId);
const { data, isLoading, isFetching, error } = useWebsiteStatsQuery({ websiteId: pixelId });
const { pageviews, visitors, visits, comparison } = data || {};
+1 -1
View File
@@ -51,7 +51,7 @@ export function SettingsNav({
return (
<Column gap="2">
<Link href={renderUrl('/boards', false)} role="button" onClick={onItemClick}>
<Link href={renderUrl('/websites', false)} role="button" onClick={onItemClick}>
<TooltipTrigger isDisabled={!isCollapsed} delay={0}>
<Focusable>
<Row
+1 -3
View File
@@ -1,8 +1,7 @@
import { z } from 'zod';
import { uuid } from '@/lib/crypto';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { createBoard, getBoard, updateBoard } from '@/queries/prisma';
import { z } from 'zod';
export async function GET(request: Request) {
const { auth, error } = await parseRequest(request);
@@ -55,7 +54,6 @@ export async function POST(request: Request) {
const result = await createBoard({
id: userId,
type: 'dashboard',
slug: uuid(),
userId,
...data,
});
+17 -40
View File
@@ -1,11 +1,11 @@
import { getBoardWebsiteIds } from '@/lib/boards';
import { ENTITY_TYPE, ROLES } from '@/lib/constants';
import { secret } from '@/lib/crypto';
import { createToken } from '@/lib/jwt';
import { getBoardWebsiteIds } from '@/lib/boards';
import prisma from '@/lib/prisma';
import redis from '@/lib/redis';
import { json, notFound } from '@/lib/response';
import type { WhiteLabel } from '@/lib/types';
import type { BoardParameters, WhiteLabel } from '@/lib/types';
import { getBoard, getLink, getPixel, getShareByCode, getWebsite } from '@/queries/prisma';
async function getAccountId(entity: { userId?: string; teamId?: string }): Promise<string | null> {
@@ -53,57 +53,35 @@ export async function GET(_request: Request, { params }: { params: Promise<{ slu
return notFound();
}
if (share.shareType === ENTITY_TYPE.board) {
const board = await getBoard(share.entityId);
if (!board) {
return notFound();
}
const data: Record<string, any> = {
shareId: share.id,
shareType: share.shareType,
boardId: share.entityId,
parameters: share.parameters,
websiteIds: getBoardWebsiteIds(board),
};
data.token = createToken(data, secret());
return json(data);
}
let entity: { userId?: string; teamId?: string } | null = null;
const data: Record<string, any> = {
shareId: share.id,
shareType: share.shareType,
parameters: share.parameters,
};
if (share.shareType === ENTITY_TYPE.website) {
let entity: { userId?: string; teamId?: string } | null = null;
if (share.shareType === ENTITY_TYPE.board) {
const board = await getBoard(share.entityId);
if (!board) return notFound();
entity = board;
data.boardId = share.entityId;
data.websiteIds = getBoardWebsiteIds({
type: board.type,
parameters: share.parameters as BoardParameters,
});
} else if (share.shareType === ENTITY_TYPE.website) {
entity = await getWebsite(share.entityId);
if (!entity) {
return notFound();
}
if (!entity) return notFound();
data.websiteId = share.entityId;
} else if (share.shareType === ENTITY_TYPE.pixel) {
entity = await getPixel(share.entityId);
if (!entity) {
return notFound();
}
if (!entity) return notFound();
data.websiteId = share.entityId;
data.pixelId = share.entityId;
} else if (share.shareType === ENTITY_TYPE.link) {
entity = await getLink(share.entityId);
if (!entity) {
return notFound();
}
if (!entity) return notFound();
data.websiteId = share.entityId;
data.linkId = share.entityId;
} else {
@@ -116,7 +94,6 @@ export async function GET(_request: Request, { params }: { params: Promise<{ slu
if (accountId) {
const whiteLabel = await getWhiteLabel(accountId);
if (whiteLabel) {
data.whiteLabel = whiteLabel;
}
@@ -0,0 +1,32 @@
'use client';
import { useShare } from '@/components/hooks';
import { Logo } from '@/components/svg';
import { Icon, Row, Text } from '@umami/react-zen';
const LOGO_SIZE = { sm: 24, md: 32, lg: 40 };
const TEXT_SIZE = { sm: 'sm', md: 'base', lg: 'lg' } as const;
export function ShareBranding({ size = 'md' }: { size?: 'sm' | 'md' | 'lg' }) {
const share = useShare();
const logoDomain = share?.whiteLabel?.domainName || 'https://umami.is';
const logoName = share?.whiteLabel?.displayName || 'umami';
const logoImage = share?.whiteLabel?.logoUrl;
const height = LOGO_SIZE[size];
return (
<a href={logoDomain} target="_blank" rel="noopener" style={{ marginLeft: 12 }}>
<Row alignItems="center" gap>
{logoImage ? (
<img src={logoImage} alt={logoName} style={{ height }} />
) : (
<Icon>
<Logo />
</Icon>
)}
<Text size={TEXT_SIZE[size]} weight="bold">
{logoName}
</Text>
</Row>
</a>
);
}
@@ -0,0 +1,25 @@
'use client';
import { useShare } from '@/components/hooks';
import { Column, Row } from '@umami/react-zen';
import { ShareBranding } from './ShareBranding';
export function ShareFooter() {
const share = useShare();
if (!share?.whiteLabel) {
return null;
}
return (
<Column
paddingX={{ base: '3', md: '6' }}
width="100%"
maxWidth="1320px"
style={{ margin: '0 auto' }}
>
<Row border="top" justifyContent="flex-end" paddingY="4">
<ShareBranding size="sm" />
</Row>
</Column>
);
}
+5 -21
View File
@@ -1,10 +1,11 @@
import { Button, Column, Icon, Row, Text, ThemeButton } from '@umami/react-zen';
import { Button, Column, Icon, Row, ThemeButton } from '@umami/react-zen';
import { NavMenu } from '@/components/common/NavMenu';
import { useMessages, useNavigation, useShare } from '@/components/hooks';
import { AlignEndHorizontal, Clock, Eye, PanelLeft, Sheet, Tag, User } from '@/components/icons';
import { LanguageButton } from '@/components/input/LanguageButton';
import { PreferencesButton } from '@/components/input/PreferencesButton';
import { Funnel, Lightning, Logo, Magnet, Money, Network, Path, Target } from '@/components/svg';
import { Funnel, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg';
import { ShareBranding } from './ShareBranding';
export function ShareNav({
collapsed,
@@ -18,11 +19,7 @@ export function ShareNav({
const share = useShare();
const { t, labels } = useMessages();
const { pathname } = useNavigation();
const { slug, parameters, whiteLabel } = share;
const logoDomain = whiteLabel?.domainName || 'https://umami.is';
const logoName = whiteLabel?.displayName || 'umami';
const logoImage = whiteLabel?.logoUrl;
const { slug, parameters } = share;
const renderPath = (path: string) => `/share/${slug}${path}`;
@@ -149,20 +146,7 @@ export function ShareNav({
border={isMobile ? undefined : 'right'}
>
<Row as="header" gap alignItems="center" justifyContent="space-between">
{!collapsed && (
<a href={logoDomain} target="_blank" rel="noopener" style={{ marginLeft: 12 }}>
<Row alignItems="center" gap>
{logoImage ? (
<img src={logoImage} alt={logoName} style={{ height: 24 }} />
) : (
<Icon>
<Logo />
</Icon>
)}
<Text weight="bold">{logoName}</Text>
</Row>
</a>
)}
{!collapsed && <ShareBranding size="md" />}
{!onItemClick && (
<Button variant="quiet" onPress={() => onCollapse?.(!collapsed)}>
<Icon color="muted">
+19 -19
View File
@@ -1,7 +1,5 @@
'use client';
import { Column, Grid, Row, useTheme } from '@umami/react-zen';
import { usePathname } from 'next/navigation';
import { useEffect, useState } from 'react';
import { BoardViewPage } from '@/app/(main)/boards/[boardId]/BoardViewPage';
import { LinkPage } from '@/app/(main)/links/[linkId]/LinkPage';
import { PixelPage } from '@/app/(main)/pixels/[pixelId]/PixelPage';
import { AttributionPage } from '@/app/(main)/websites/[websiteId]/(reports)/attribution/AttributionPage';
@@ -19,11 +17,14 @@ import { SessionsPage } from '@/app/(main)/websites/[websiteId]/sessions/Session
import { WebsiteHeader } from '@/app/(main)/websites/[websiteId]/WebsiteHeader';
import { WebsitePage } from '@/app/(main)/websites/[websiteId]/WebsitePage';
import { WebsiteProvider } from '@/app/(main)/websites/WebsiteProvider';
import { BoardViewPage } from '@/app/(main)/boards/[boardId]/BoardViewPage';
import { PageBody } from '@/components/common/PageBody';
import { useShare } from '@/components/hooks';
import { MobileMenuButton } from '@/components/input/MobileMenuButton';
import { ENTITY_TYPE } from '@/lib/constants';
import { Column, Grid, Row, useTheme } from '@umami/react-zen';
import { usePathname } from 'next/navigation';
import { useEffect, useState } from 'react';
import { ShareFooter } from './ShareFooter';
import { ShareNav } from './ShareNav';
const PAGE_COMPONENTS: Record<string, React.ComponentType<{ websiteId: string }>> = {
@@ -72,25 +73,24 @@ export function SharePage() {
}
}, [setTheme]);
if (shareType === ENTITY_TYPE.board && boardId) {
const entityPage =
shareType === ENTITY_TYPE.board && boardId ? (
<BoardViewPage boardId={boardId} showActions={false} />
) : shareType === ENTITY_TYPE.pixel && pixelId ? (
<PixelPage pixelId={pixelId} showHeaderActions={false} />
) : shareType === ENTITY_TYPE.link && linkId ? (
<LinkPage linkId={linkId} showHeaderActions={false} />
) : null;
if (entityPage) {
return (
<BoardViewPage
boardId={boardId}
showActions={false}
showControls={false}
showEntityBadges={false}
/>
<Column>
{entityPage}
<ShareFooter />
</Column>
);
}
if (shareType === ENTITY_TYPE.pixel && pixelId) {
return <PixelPage pixelId={pixelId} showHeaderActions={false} />;
}
if (shareType === ENTITY_TYPE.link && linkId) {
return <LinkPage linkId={linkId} showHeaderActions={false} />;
}
// Check if the requested path is allowed
const pageKey = path || '';
const isAllowed = pageKey === '' || pageKey === 'overview' || parameters[pageKey] !== false;
+3 -1
View File
@@ -60,6 +60,7 @@ async function relationalQuery(
website_event.utm_source,
website_event.session_id,
website_event.visit_id,
website_event.hostname,
count(*) c,
min(website_event.created_at) min_time,
max(website_event.created_at) max_time
@@ -77,7 +78,8 @@ async function relationalQuery(
website_event.utm_medium,
website_event.utm_source,
website_event.session_id,
website_event.visit_id),
website_event.visit_id,
website_event.hostname),
channels as (
select case
+3 -2
View File
@@ -39,7 +39,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
website_event.url_query,
website_event.utm_medium,
website_event.utm_source,
website_event.session_id
website_event.session_id,
website_event.hostname
from website_event
${cohortQuery}
${excludeBounceQuery}
@@ -61,7 +62,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
when ${toPostgresLikeClause('referrer_domain', EMAIL_DOMAINS)} or utm_medium ilike '%mail%' then 'email'
when ${toPostgresLikeClause('referrer_domain', SHOPPING_DOMAINS)} or utm_medium ilike '%shop%' then concat(prefix, 'Shopping')
when ${toPostgresLikeClause('referrer_domain', VIDEO_DOMAINS)} or utm_medium ilike '%video%' then concat(prefix, 'Video')
wwhen referrer_domain != regexp_replace(hostname, '^www.', '') and referrer_domain != '' then 'referral'
when referrer_domain != regexp_replace(hostname, '^www.', '') and referrer_domain != '' then 'referral'
else '' end AS x,
count(distinct session_id) y
from prefix
@@ -56,17 +56,17 @@ async function relationalQuery(websiteId: string, currency: string, filters: Que
join session
on session.session_id = website_event.session_id
and session.website_id = website_event.website_id
join (
select distinct session_id
from revenue
where website_id = {{websiteId::uuid}}
and revenue.created_at between {{startDate}} and {{endDate}}
and upper(currency) = {{currency}}
) rev on rev.session_id = website_event.session_id
where website_event.website_id = {{websiteId::uuid}}
${dateQuery}
${filterQuery}
${searchQuery}
and website_event.session_id in (
select distinct session_id
from revenue
where website_id = {{websiteId::uuid}}
${dateQuery}
and upper(currency) = {{currency}}
)
group by
session.session_id,
session.website_id,
+42 -18
View File
@@ -233,6 +233,7 @@
let sent = false;
let timeoutId;
let isInitialLoad = true;
let activationStart = 0;
const observe = (type, callback) => {
try {
@@ -247,42 +248,63 @@
// TTFB
observe('navigation', entry => {
metrics.ttfb = Math.max(entry.responseStart - entry.startTime, 0);
activationStart = entry.activationStart || 0;
metrics.ttfb = Math.max(entry.responseStart - activationStart, 0);
});
// FCP
observe('paint', entry => {
if (entry.name === 'first-contentful-paint') {
metrics.fcp = entry.startTime;
metrics.fcp = Math.max(entry.startTime - activationStart, 0);
}
});
// LCP
observe('largest-contentful-paint', entry => {
metrics.lcp = entry.startTime;
metrics.lcp = Math.max(entry.startTime - activationStart, 0);
});
// CLS
let clsValue = 0;
// CLS - session windows algorithm (gap < 1s, max 5s duration; report worst window)
let clsSessionValue = 0;
let clsSessionEntries = [];
observe('layout-shift', entry => {
if (!entry.hadRecentInput) {
clsValue += entry.value;
metrics.cls = clsValue;
const lastEntry = clsSessionEntries[clsSessionEntries.length - 1];
const firstEntry = clsSessionEntries[0];
if (
lastEntry &&
entry.startTime - lastEntry.startTime - lastEntry.duration < 1000 &&
entry.startTime - firstEntry.startTime < 5000
) {
clsSessionValue += entry.value;
clsSessionEntries.push(entry);
} else {
clsSessionValue = entry.value;
clsSessionEntries = [entry];
}
if (clsSessionValue > (metrics.cls || 0)) {
metrics.cls = clsSessionValue;
}
}
});
// INP
let inpValue = 0;
// INP - group by interactionId, 98th percentile, 40ms threshold
let interactions = {};
try {
const observer = new PerformanceObserver(list => {
list.getEntries().forEach(entry => {
if (entry.duration > inpValue) {
inpValue = entry.duration;
metrics.inp = inpValue;
if (entry.interactionId) {
const existing = interactions[entry.interactionId];
if (!existing || entry.duration > existing) {
interactions[entry.interactionId] = entry.duration;
}
const values = Object.values(interactions).sort((a, b) => b - a);
const p98Index = Math.floor(Math.max(values.length, 10) * 0.02);
metrics.inp = values[Math.min(p98Index, values.length - 1)] || 0;
}
});
});
observer.observe({ type: 'event', buffered: true, durationThreshold: 16 });
observer.observe({ type: 'event', buffered: true, durationThreshold: 40 });
} catch {
/* not supported */
}
@@ -301,7 +323,7 @@
if (metrics.ttfb === undefined) {
const navigation = getEntriesByType('navigation')?.[0];
if (navigation) {
metrics.ttfb = Math.max(navigation.responseStart - navigation.startTime, 0);
metrics.ttfb = Math.max(navigation.responseStart - (navigation.activationStart || 0), 0);
}
}
@@ -310,7 +332,7 @@
entry => entry.name === 'first-contentful-paint',
);
if (fcpEntry) {
metrics.fcp = fcpEntry.startTime;
metrics.fcp = Math.max(fcpEntry.startTime - activationStart, 0);
}
}
@@ -318,7 +340,7 @@
const lcpEntries = getEntriesByType('largest-contentful-paint');
const lcpEntry = lcpEntries?.[lcpEntries.length - 1];
if (lcpEntry) {
metrics.lcp = lcpEntry.startTime;
metrics.lcp = Math.max(lcpEntry.startTime - activationStart, 0);
}
}
};
@@ -340,8 +362,10 @@
Object.keys(metrics).forEach(k => {
delete metrics[k];
});
clsValue = 0;
inpValue = 0;
activationStart = 0;
clsSessionValue = 0;
clsSessionEntries = [];
interactions = {};
sent = false;
if (timeoutId) clearTimeout(timeoutId);
timeoutId = setTimeout(sendPerformance, 10000);