Compare commits

...

9 commits

Author SHA1 Message Date
Mike Cao
751568d871 Merge remote-tracking branch 'origin/dev' into dev
Some checks are pending
Create docker images (cloud) / Build, push, and deploy (push) Waiting to run
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run
2025-10-30 17:05:49 -07:00
Mike Cao
b08a6e1113 Don't prefetch pixel links. 2025-10-30 17:05:11 -07:00
Francis Cao
504c459090 update schema validation for link/pixel updates
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
2025-10-30 16:13:36 -07:00
Mike Cao
dfe969cabe Fixed pixels/links collect.
Some checks are pending
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run
2025-10-30 12:53:12 -07:00
Francis Cao
f073fb1996 Add DialogTrigger to overflow menus
Some checks are pending
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run
2025-10-29 12:38:52 -07:00
Francis Cao
72fba187db separate Admin/Settings Nav and add to MobileNav 2025-10-29 11:32:52 -07:00
Francis Cao
ef55b63a3b Fix admin layout and data refresh after update/delete 2025-10-29 11:04:54 -07:00
Francis Cao
c81b1c16c8 fix geteventdatavalues query 2025-10-29 10:10:46 -07:00
Francis Cao
6eefb4173c add improved truncation between tablets and phones
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
2025-10-27 13:54:15 -07:00
22 changed files with 197 additions and 148 deletions

View file

@ -1,15 +1,19 @@
import { Row, NavMenu, NavMenuItem, IconLabel, Text, Grid } from '@umami/react-zen';
import { Globe, Grid2x2, LinkIcon } from '@/components/icons';
import { useMessages, useNavigation } from '@/components/hooks';
import Link from 'next/link';
import { WebsiteNav } from '@/app/(main)/websites/[websiteId]/WebsiteNav';
import { Logo } from '@/components/svg';
import { NavButton } from '@/components/input/NavButton';
import { useMessages, useNavigation } from '@/components/hooks';
import { Globe, Grid2x2, LinkIcon } from '@/components/icons';
import { MobileMenuButton } from '@/components/input/MobileMenuButton';
import { NavButton } from '@/components/input/NavButton';
import { Logo } from '@/components/svg';
import { Grid, IconLabel, NavMenu, NavMenuItem, Row, Text } from '@umami/react-zen';
import Link from 'next/link';
import { AdminNav } from './admin/AdminNav';
import { SettingsNav } from './settings/SettingsNav';
export function MobileNav() {
const { formatMessage, labels } = useMessages();
const { websiteId, renderUrl } = useNavigation();
const { pathname, websiteId, renderUrl } = useNavigation();
const isAdmin = pathname.includes('/admin');
const isSettings = pathname.includes('/settings');
const links = [
{
@ -51,6 +55,8 @@ export function MobileNav() {
})}
</NavMenu>
{websiteId && <WebsiteNav websiteId={websiteId} onItemClick={close} />}
{isAdmin && <AdminNav onItemClick={close} />}
{isSettings && <SettingsNav onItemClick={close} />}
</>
);
}}

View file

@ -1,61 +1,32 @@
'use client';
import { ReactNode } from 'react';
import { Grid, Column } from '@umami/react-zen';
import { useLoginQuery, useMessages, useNavigation } from '@/components/hooks';
import { User, Users, Globe } from '@/components/icons';
import { SideMenu } from '@/components/common/SideMenu';
import { PageBody } from '@/components/common/PageBody';
import { useLoginQuery } from '@/components/hooks';
import { Column, Grid } from '@umami/react-zen';
import { ReactNode } from 'react';
import { AdminNav } from './AdminNav';
export function AdminLayout({ children }: { children: ReactNode }) {
const { user } = useLoginQuery();
const { formatMessage, labels } = useMessages();
const { pathname } = useNavigation();
if (!user.isAdmin || process.env.cloudMode) {
return null;
}
const items = [
{
label: formatMessage(labels.manage),
items: [
{
id: 'users',
label: formatMessage(labels.users),
path: '/admin/users',
icon: <User />,
},
{
id: 'websites',
label: formatMessage(labels.websites),
path: '/admin/websites',
icon: <Globe />,
},
{
id: 'teams',
label: formatMessage(labels.teams),
path: '/admin/teams',
icon: <Users />,
},
],
},
];
const selectedKey = items
.flatMap(e => e.items)
?.find(({ path }) => path && pathname.startsWith(path))?.id;
return (
<Grid columns="auto 1fr" width="100%" height="100%">
<Column height="100%" border="right" backgroundColor>
<SideMenu
items={items}
title={formatMessage(labels.admin)}
selectedKey={selectedKey}
allowMinimize={false}
/>
<Grid columns={{ xs: '1fr', lg: 'auto 1fr' }} width="100%" height="100%">
<Column
display={{ xs: 'none', lg: 'flex' }}
width="240px"
height="100%"
border="right"
backgroundColor
marginRight="2"
>
<AdminNav />
</Column>
<Column gap="6" margin="2">
<PageBody>{children}</PageBody>
</Column>
<PageBody>{children}</PageBody>
</Grid>
);
}

View file

@ -0,0 +1,48 @@
import { SideMenu } from '@/components/common/SideMenu';
import { useMessages, useNavigation } from '@/components/hooks';
import { Globe, User, Users } from '@/components/icons';
export function AdminNav({ onItemClick }: { onItemClick?: () => void }) {
const { formatMessage, labels } = useMessages();
const { pathname } = useNavigation();
const items = [
{
label: formatMessage(labels.manage),
items: [
{
id: 'users',
label: formatMessage(labels.users),
path: '/admin/users',
icon: <User />,
},
{
id: 'websites',
label: formatMessage(labels.websites),
path: '/admin/websites',
icon: <Globe />,
},
{
id: 'teams',
label: formatMessage(labels.teams),
path: '/admin/teams',
icon: <Users />,
},
],
},
];
const selectedKey = items
.flatMap(e => e.items)
?.find(({ path }) => path && pathname.startsWith(path))?.id;
return (
<SideMenu
items={items}
title={formatMessage(labels.admin)}
selectedKey={selectedKey}
allowMinimize={false}
onItemClick={onItemClick}
/>
);
}

View file

@ -1,11 +1,11 @@
import { useState } from 'react';
import { Row, Text, Icon, DataTable, DataColumn, MenuItem, Modal } from '@umami/react-zen';
import Link from 'next/link';
import { Trash } from '@/components/icons';
import { useMessages } from '@/components/hooks';
import { Edit } from '@/components/icons';
import { MenuButton } from '@/components/input/MenuButton';
import { DateDistance } from '@/components/common/DateDistance';
import { useMessages } from '@/components/hooks';
import { Edit, Trash } from '@/components/icons';
import { MenuButton } from '@/components/input/MenuButton';
import { DataColumn, DataTable, Dialog, Icon, MenuItem, Modal, Row, Text } from '@umami/react-zen';
import { TeamDeleteForm } from '../../teams/[teamId]/TeamDeleteForm';
import Link from 'next/link';
import { useState } from 'react';
export function AdminTeamsTable({
data = [],
@ -15,7 +15,7 @@ export function AdminTeamsTable({
showActions?: boolean;
}) {
const { formatMessage, labels } = useMessages();
const [deleteUser, setDeleteUser] = useState(null);
const [deleteTeam, setDeleteTeam] = useState(null);
return (
<>
@ -60,7 +60,7 @@ export function AdminTeamsTable({
</MenuItem>
<MenuItem
id="delete"
onAction={() => setDeleteUser(row)}
onAction={() => setDeleteTeam(id)}
data-test="link-button-delete"
>
<Row alignItems="center" gap>
@ -76,7 +76,11 @@ export function AdminTeamsTable({
</DataColumn>
)}
</DataTable>
<Modal isOpen={!!deleteUser}></Modal>
<Modal isOpen={!!deleteTeam}>
<Dialog style={{ width: 400 }}>
<TeamDeleteForm teamId={deleteTeam} onClose={() => setDeleteTeam(null)} />
</Dialog>
</Modal>
</>
);
}

View file

@ -22,6 +22,7 @@ export function UserEditForm({ userId, onSave }: { userId: string; onSave?: () =
await mutateAsync(data, {
onSuccess: async () => {
toast(formatMessage(messages.saved));
touch('users');
touch(`user:${user.id}`);
onSave?.();
},

View file

@ -11,7 +11,7 @@ export function PixelHeader() {
return (
<PageHeader title={pixel.name} icon={<Grid2x2 />} marginBottom="3">
<LinkButton href={getSlugUrl(pixel.slug)} target="_blank">
<LinkButton href={getSlugUrl(pixel.slug)} target="_blank" prefetch={false}>
<Icon>
<ExternalLink />
</Icon>

View file

@ -1,50 +1,10 @@
'use client';
import { PageBody } from '@/components/common/PageBody';
import { SideMenu } from '@/components/common/SideMenu';
import { useMessages, useNavigation } from '@/components/hooks';
import { Settings2, UserCircle, Users } from '@/components/icons';
import { Column, Grid } from '@umami/react-zen';
import { ReactNode } from 'react';
import { SettingsNav } from './SettingsNav';
export function SettingsLayout({ children }: { children: ReactNode }) {
const { formatMessage, labels } = useMessages();
const { renderUrl, pathname } = useNavigation();
const items = [
{
label: formatMessage(labels.application),
items: [
{
id: 'preferences',
label: formatMessage(labels.preferences),
path: renderUrl('/settings/preferences'),
icon: <Settings2 />,
},
],
},
{
label: formatMessage(labels.account),
items: [
{
id: 'profile',
label: formatMessage(labels.profile),
path: renderUrl('/settings/profile'),
icon: <UserCircle />,
},
{
id: 'teams',
label: formatMessage(labels.teams),
path: renderUrl('/settings/teams'),
icon: <Users />,
},
],
},
];
const selectedKey = items
.flatMap(e => e.items)
.find(({ path }) => path && pathname.includes(path.split('?')[0]))?.id;
return (
<Grid columns={{ xs: '1fr', lg: 'auto 1fr' }} width="100%" height="100%">
<Column
@ -55,12 +15,7 @@ export function SettingsLayout({ children }: { children: ReactNode }) {
backgroundColor
marginRight="2"
>
<SideMenu
items={items}
title={formatMessage(labels.settings)}
selectedKey={selectedKey}
allowMinimize={false}
/>
<SettingsNav />
</Column>
<Column gap="6" margin="2">
<PageBody>{children}</PageBody>

View file

@ -0,0 +1,53 @@
import { SideMenu } from '@/components/common/SideMenu';
import { useMessages, useNavigation } from '@/components/hooks';
import { Settings2, UserCircle, Users } from '@/components/icons';
export function SettingsNav({ onItemClick }: { onItemClick?: () => void }) {
const { formatMessage, labels } = useMessages();
const { renderUrl, pathname } = useNavigation();
const items = [
{
label: formatMessage(labels.application),
items: [
{
id: 'preferences',
label: formatMessage(labels.preferences),
path: renderUrl('/settings/preferences'),
icon: <Settings2 />,
},
],
},
{
label: formatMessage(labels.account),
items: [
{
id: 'profile',
label: formatMessage(labels.profile),
path: renderUrl('/settings/profile'),
icon: <UserCircle />,
},
{
id: 'teams',
label: formatMessage(labels.teams),
path: renderUrl('/settings/teams'),
icon: <Users />,
},
],
},
];
const selectedKey = items
.flatMap(e => e.items)
.find(({ path }) => path && pathname.includes(path.split('?')[0]))?.id;
return (
<SideMenu
items={items}
title={formatMessage(labels.settings)}
selectedKey={selectedKey}
allowMinimize={false}
onItemClick={onItemClick}
/>
);
}

View file

@ -19,6 +19,7 @@ export function TeamDeleteForm({
await mutateAsync(null, {
onSuccess: async () => {
touch('teams');
touch(`teams:${teamId}`);
onSave?.();
onClose?.();
},

View file

@ -1,23 +1,27 @@
'use client';
import { useState } from 'react';
import { Button, Column, Box, DialogTrigger, Popover, Dialog, IconLabel } from '@umami/react-zen';
import { useDateRange, useMessages } from '@/components/hooks';
import { ListCheck } from '@/components/icons';
import { Panel } from '@/components/common/Panel';
import { Breakdown } from './Breakdown';
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
import { FieldSelectForm } from '@/app/(main)/websites/[websiteId]/(reports)/breakdown/FieldSelectForm';
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
import { Panel } from '@/components/common/Panel';
import { useDateRange, useMessages, useMobile } from '@/components/hooks';
import { ListCheck } from '@/components/icons';
import { DialogButton } from '@/components/input/DialogButton';
import { Column, Row } from '@umami/react-zen';
import { useState } from 'react';
import { Breakdown } from './Breakdown';
export function BreakdownPage({ websiteId }: { websiteId: string }) {
const {
dateRange: { startDate, endDate },
} = useDateRange();
const [fields, setFields] = useState(['path']);
const { isMobile } = useMobile();
return (
<Column gap>
<WebsiteControls websiteId={websiteId} />
<FieldsButton value={fields} onChange={setFields} />
<Row alignItems="center" justifyContent={isMobile ? 'flex-end' : 'flex-start'}>
<FieldsButton value={fields} onChange={setFields} />
</Row>
<Panel height="900px" overflow="auto" allowFullscreen>
<Breakdown
websiteId={websiteId}
@ -34,19 +38,15 @@ const FieldsButton = ({ value, onChange }) => {
const { formatMessage, labels } = useMessages();
return (
<Box>
<DialogTrigger>
<Button>
<IconLabel icon={<ListCheck />}>{formatMessage(labels.fields)}</IconLabel>
</Button>
<Popover>
<Dialog title={formatMessage(labels.fields)} style={{ width: 400 }}>
{({ close }) => (
<FieldSelectForm selectedFields={value} onChange={onChange} onClose={close} />
)}
</Dialog>
</Popover>
</DialogTrigger>
</Box>
<DialogButton
icon={<ListCheck />}
label={formatMessage(labels.fields)}
width="800px"
minHeight="300px"
>
{({ close }) => {
return <FieldSelectForm selectedFields={value} onChange={onChange} onClose={close} />;
}}
</DialogButton>
);
};

View file

@ -12,7 +12,7 @@ export function CohortAddButton({ websiteId }: { websiteId: string }) {
label={formatMessage(labels.cohort)}
variant="primary"
width="800px"
minHeight="300px"
height="calc(100dvh - 40px)"
>
{({ close }) => {
return <CohortEditForm websiteId={websiteId} onClose={close} />;

View file

@ -21,7 +21,7 @@ export function CohortEditButton({
variant="quiet"
title={formatMessage(labels.cohort)}
width="800px"
minHeight="300px"
height="calc(100dvh - 40px)"
>
{({ close }) => {
return (

View file

@ -12,6 +12,7 @@ export function SegmentAddButton({ websiteId }: { websiteId: string }) {
label={formatMessage(labels.segment)}
variant="primary"
width="800px"
height="calc(100dvh - 40px)"
>
{({ close }) => {
return <SegmentEditForm websiteId={websiteId} onClose={close} />;

View file

@ -21,6 +21,7 @@ export function SegmentEditButton({
title={formatMessage(labels.segment)}
variant="quiet"
width="800px"
height="calc(100dvh - 40px)"
>
{({ close }) => {
return (

View file

@ -11,6 +11,7 @@ export function WebsiteEditForm({ websiteId, onSave }: { websiteId: string; onSa
await mutateAsync(data, {
onSuccess: async () => {
toast(formatMessage(messages.saved));
touch('websites');
touch(`website:${website.id}`);
onSave?.();
},

View file

@ -24,9 +24,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ link
export async function POST(request: Request, { params }: { params: Promise<{ linkId: string }> }) {
const schema = z.object({
name: z.string(),
url: z.string(),
slug: z.string(),
name: z.string().optional(),
url: z.string().optional(),
slug: z.string().min(8).optional(),
});
const { auth, body, error } = await parseRequest(request, schema);

View file

@ -24,8 +24,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ pixe
export async function POST(request: Request, { params }: { params: Promise<{ pixelId: string }> }) {
const schema = z.object({
name: z.string(),
slug: z.string().min(8),
name: z.string().optional(),
slug: z.string().min(8).optional(),
});
const { auth, body, error } = await parseRequest(request, schema);

View file

@ -82,6 +82,8 @@ export async function POST(request: Request) {
id,
} = payload;
const sourceId = websiteId || pixelId || linkId;
// Cache check
let cache: Cache | null = null;
@ -128,13 +130,13 @@ export async function POST(request: Request) {
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
const visitSalt = hash(startOfHour(createdAt).toUTCString());
const sessionId = id ? uuid(websiteId, id) : uuid(websiteId, ip, userAgent, sessionSalt);
const sessionId = id ? uuid(sourceId, id) : uuid(sourceId, ip, userAgent, sessionSalt);
// Create a session if not found
if (!clickhouse.enabled && !cache?.sessionId) {
await createSession({
id: sessionId,
websiteId,
websiteId: sourceId,
browser,
os,
device,
@ -206,7 +208,7 @@ export async function POST(request: Request) {
: EVENT_TYPE.pageView;
await saveEvent({
websiteId: websiteId || linkId || pixelId,
websiteId: sourceId,
sessionId,
visitId,
eventType,
@ -270,6 +272,9 @@ export async function POST(request: Request) {
} catch (e) {
const error = serializeError(e);
// eslint-disable-next-line no-console
console.log(error);
return serverError({ errorObject: error });
}
}

View file

@ -8,6 +8,7 @@ export interface LinkButtonProps extends ButtonProps {
target?: string;
scroll?: boolean;
variant?: any;
prefetch?: boolean;
children?: ReactNode;
}
@ -16,6 +17,7 @@ export function LinkButton({
variant,
scroll = true,
target,
prefetch,
children,
...props
}: LinkButtonProps) {
@ -23,7 +25,7 @@ export function LinkButton({
return (
<Button {...props} variant={variant} asChild>
<Link href={href} dir={dir} scroll={scroll} target={target}>
<Link href={href} dir={dir} scroll={scroll} target={target} prefetch={prefetch}>
{children}
</Link>
</Button>

View file

@ -3,6 +3,7 @@ import { useBreakpoint } from '@umami/react-zen';
export function useMobile() {
const breakpoint = useBreakpoint();
const isMobile = ['xs', 'sm', 'md'].includes(breakpoint);
const isPhone = ['xs', 'sm'].includes(breakpoint);
return { breakpoint, isMobile };
return { breakpoint, isMobile, isPhone };
}

View file

@ -42,7 +42,7 @@ export function ListTable({
currency,
}: ListTableProps) {
const { formatMessage, labels } = useMessages();
const { isMobile } = useMobile();
const { isPhone } = useMobile();
const getRow = (row: ListData, index: number) => {
const { label, count, percent } = row;
@ -57,7 +57,7 @@ export function ListTable({
showPercentage={showPercentage}
change={renderChange ? renderChange(row, index) : null}
currency={currency}
isMobile={isMobile}
isMobile={isPhone}
/>
);
};

View file

@ -47,7 +47,6 @@ async function relationalQuery(
where event_data.website_id = {{websiteId::uuid}}
and event_data.created_at between {{startDate}} and {{endDate}}
and event_data.data_key = {{propertyName}}
and website_event.event_name = {{eventName}}
${filterQuery}
group by value
order by 2 desc