mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
2620e8fe26
3
src/app/(main)/teams/[teamId]/reports/utm/page.tsx
Normal file
3
src/app/(main)/teams/[teamId]/reports/utm/page.tsx
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Page from 'app/(main)/reports/utm/page';
|
||||||
|
|
||||||
|
export default Page;
|
@ -0,0 +1,3 @@
|
|||||||
|
import Page from 'app/(main)/websites/[websiteId]/event-data/page';
|
||||||
|
|
||||||
|
export default Page;
|
@ -0,0 +1,3 @@
|
|||||||
|
import Page from 'app/(main)/websites/[websiteId]/realtime/page';
|
||||||
|
|
||||||
|
export default Page;
|
@ -0,0 +1,3 @@
|
|||||||
|
import Page from 'app/(main)/websites/[websiteId]/reports/page';
|
||||||
|
|
||||||
|
export default Page;
|
@ -1,6 +1,6 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import Favicon from 'components/common/Favicon';
|
import Favicon from 'components/common/Favicon';
|
||||||
import { useMessages, useWebsite } from 'components/hooks';
|
import { useMessages, useTeamUrl, useWebsite } from 'components/hooks';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import ActiveUsers from 'components/metrics/ActiveUsers';
|
import ActiveUsers from 'components/metrics/ActiveUsers';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
@ -19,6 +19,7 @@ export function WebsiteHeader({
|
|||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
const { renderTeamUrl } = useTeamUrl();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { data: website } = useWebsite(websiteId);
|
const { data: website } = useWebsite(websiteId);
|
||||||
const { name, domain } = website || {};
|
const { name, domain } = website || {};
|
||||||
@ -62,7 +63,11 @@ export function WebsiteHeader({
|
|||||||
: pathname.match(/^\/websites\/[\w-]+$/);
|
: pathname.match(/^\/websites\/[\w-]+$/);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link key={label} href={`/websites/${websiteId}${path}`} shallow={true}>
|
<Link
|
||||||
|
key={label}
|
||||||
|
href={renderTeamUrl(`/websites/${websiteId}${path}`)}
|
||||||
|
shallow={true}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="quiet"
|
variant="quiet"
|
||||||
className={classNames({
|
className={classNames({
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Button, Flexbox, Icon, Icons, Text } from 'react-basics';
|
import { Button, Flexbox, Icon, Icons, Text } from 'react-basics';
|
||||||
import { useMessages } from 'components/hooks';
|
import { useMessages, useTeamUrl } from 'components/hooks';
|
||||||
import WebsiteHeader from '../WebsiteHeader';
|
import WebsiteHeader from '../WebsiteHeader';
|
||||||
import ReportsDataTable from 'app/(main)/reports/ReportsDataTable';
|
import ReportsDataTable from 'app/(main)/reports/ReportsDataTable';
|
||||||
|
|
||||||
export function WebsiteReportsPage({ websiteId }) {
|
export function WebsiteReportsPage({ websiteId }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
const { renderTeamUrl } = useTeamUrl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsiteHeader websiteId={websiteId} />
|
<WebsiteHeader websiteId={websiteId} />
|
||||||
<Flexbox alignItems="center" justifyContent="end">
|
<Flexbox alignItems="center" justifyContent="end">
|
||||||
<Link href={`/reports/create`}>
|
<Link href={renderTeamUrl('/reports/create')}>
|
||||||
<Button variant="primary">
|
<Button variant="primary">
|
||||||
<Icon>
|
<Icon>
|
||||||
<Icons.Plus />
|
<Icons.Plus />
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
import useApi from './useApi';
|
|
||||||
import { UseQueryOptions } from '@tanstack/react-query';
|
|
||||||
import { useDateRange, useNavigation, useTimezone } from 'components/hooks';
|
import { useDateRange, useNavigation, useTimezone } from 'components/hooks';
|
||||||
import { zonedTimeToUtc } from 'date-fns-tz';
|
import { zonedTimeToUtc } from 'date-fns-tz';
|
||||||
|
import useApi from './useApi';
|
||||||
|
|
||||||
export function useWebsiteEvents(
|
export function useWebsiteEvents(websiteId: string, options?: { [key: string]: string }) {
|
||||||
websiteId: string,
|
|
||||||
options?: Omit<UseQueryOptions, 'queryKey' | 'queryFn'>,
|
|
||||||
) {
|
|
||||||
const { get, useQuery } = useApi();
|
const { get, useQuery } = useApi();
|
||||||
const [dateRange] = useDateRange(websiteId);
|
const [dateRange] = useDateRange(websiteId);
|
||||||
const { startDate, endDate, unit, offset } = dateRange;
|
const { startDate, endDate, unit, offset } = dateRange;
|
||||||
const { timezone } = useTimezone();
|
const { timezone } = useTimezone();
|
||||||
const {
|
const {
|
||||||
query: { url, event },
|
query: { url, referrer, os, browser, device, country, region, city, title, event },
|
||||||
} = useNavigation();
|
} = useNavigation();
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
@ -20,14 +16,22 @@ export function useWebsiteEvents(
|
|||||||
endAt: +zonedTimeToUtc(endDate, timezone),
|
endAt: +zonedTimeToUtc(endDate, timezone),
|
||||||
unit,
|
unit,
|
||||||
offset,
|
offset,
|
||||||
timezone,
|
|
||||||
url,
|
url,
|
||||||
|
referrer,
|
||||||
|
os,
|
||||||
|
browser,
|
||||||
|
device,
|
||||||
|
country,
|
||||||
|
region,
|
||||||
|
city,
|
||||||
|
title,
|
||||||
|
timezone,
|
||||||
event,
|
event,
|
||||||
};
|
};
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['events', { ...params }],
|
queryKey: ['events', { websiteId, ...params }],
|
||||||
queryFn: () => get(`/websites/${websiteId}/events`, { ...params }),
|
queryFn: () => get(`/websites/${websiteId}/events`, params),
|
||||||
enabled: !!websiteId,
|
enabled: !!websiteId,
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
@ -30,7 +30,7 @@ export const FILTER_DAY = 'filter-day';
|
|||||||
export const FILTER_RANGE = 'filter-range';
|
export const FILTER_RANGE = 'filter-range';
|
||||||
export const FILTER_REFERRERS = 'filter-referrers';
|
export const FILTER_REFERRERS = 'filter-referrers';
|
||||||
export const FILTER_PAGES = 'filter-pages';
|
export const FILTER_PAGES = 'filter-pages';
|
||||||
export const UNIT_TYPES = ['year', 'month', 'hour', 'day'];
|
export const UNIT_TYPES = ['year', 'month', 'hour', 'day', 'minute'];
|
||||||
export const EVENT_COLUMNS = ['url', 'referrer', 'title', 'query', 'event'];
|
export const EVENT_COLUMNS = ['url', 'referrer', 'title', 'query', 'event'];
|
||||||
|
|
||||||
export const SESSION_COLUMNS = [
|
export const SESSION_COLUMNS = [
|
||||||
|
@ -2,7 +2,7 @@ import * as yup from 'yup';
|
|||||||
|
|
||||||
export const dateRange = {
|
export const dateRange = {
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pageInfo = {
|
export const pageInfo = {
|
||||||
|
@ -17,7 +17,7 @@ const schema = {
|
|||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
websiteId: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||||
event: yup.string(),
|
event: yup.string(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ const schema = {
|
|||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
websiteId: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||||
field: yup.string(),
|
field: yup.string(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,7 @@ const schema = {
|
|||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
websiteId: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ const schema = {
|
|||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
id: yup.string().uuid().required(),
|
id: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref<number>('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref<number>('startAt')).required(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { canViewWebsite } from 'lib/auth';
|
import { canViewWebsite } from 'lib/auth';
|
||||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||||
import { getRequestDateRange } from 'lib/request';
|
import { getRequestFilters, getRequestDateRange } from 'lib/request';
|
||||||
import { NextApiRequestQueryBody, WebsiteMetric } from 'lib/types';
|
import { NextApiRequestQueryBody, WebsiteMetric } from 'lib/types';
|
||||||
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
||||||
import { NextApiResponse } from 'next';
|
import { NextApiResponse } from 'next';
|
||||||
@ -15,16 +15,32 @@ export interface WebsiteEventsRequestQuery {
|
|||||||
unit?: string;
|
unit?: string;
|
||||||
timezone?: string;
|
timezone?: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
referrer?: string;
|
||||||
|
title?: string;
|
||||||
|
os?: string;
|
||||||
|
browser?: string;
|
||||||
|
device?: string;
|
||||||
|
country?: string;
|
||||||
|
region: string;
|
||||||
|
city?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
GET: yup.object().shape({
|
GET: yup.object().shape({
|
||||||
websiteId: yup.string().uuid().required(),
|
websiteId: yup.string().uuid().required(),
|
||||||
startAt: yup.number().integer().required(),
|
startAt: yup.number().integer().required(),
|
||||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||||
unit: UnitTypeTest,
|
unit: UnitTypeTest,
|
||||||
timezone: TimezoneTest,
|
timezone: TimezoneTest,
|
||||||
url: yup.string(),
|
url: yup.string(),
|
||||||
|
referrer: yup.string(),
|
||||||
|
title: yup.string(),
|
||||||
|
os: yup.string(),
|
||||||
|
browser: yup.string(),
|
||||||
|
device: yup.string(),
|
||||||
|
country: yup.string(),
|
||||||
|
region: yup.string(),
|
||||||
|
city: yup.string(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,7 +52,7 @@ export default async (
|
|||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
await useValidate(schema, req, res);
|
await useValidate(schema, req, res);
|
||||||
|
|
||||||
const { websiteId, timezone, url } = req.query;
|
const { websiteId, timezone } = req.query;
|
||||||
const { startDate, endDate, unit } = await getRequestDateRange(req);
|
const { startDate, endDate, unit } = await getRequestDateRange(req);
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
@ -44,13 +60,15 @@ export default async (
|
|||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await getEventMetrics(websiteId, {
|
const filters = {
|
||||||
|
...getRequestFilters(req),
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
timezone,
|
timezone,
|
||||||
unit,
|
unit,
|
||||||
url,
|
};
|
||||||
});
|
|
||||||
|
const events = await getEventMetrics(websiteId, filters);
|
||||||
|
|
||||||
return ok(res, events);
|
return ok(res, events);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
|||||||
`
|
`
|
||||||
select
|
select
|
||||||
event_name x,
|
event_name x,
|
||||||
${getDateQuery('created_at', unit, timezone)} t,
|
${getDateQuery('website_event.created_at', unit, timezone)} t,
|
||||||
count(*) y
|
count(*) y
|
||||||
from website_event
|
from website_event
|
||||||
${joinSession}
|
${joinSession}
|
||||||
where website_id = {{websiteId::uuid}}
|
where website_event.website_id = {{websiteId::uuid}}
|
||||||
and created_at between {{startDate}} and {{endDate}}
|
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||||
and event_type = {{eventType}}
|
and event_type = {{eventType}}
|
||||||
${filterQuery}
|
${filterQuery}
|
||||||
group by 1, 2
|
group by 1, 2
|
||||||
|
Loading…
Reference in New Issue
Block a user