mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Added hooks for website stats and pageviews.
This commit is contained in:
parent
f50067e44f
commit
7ab580c709
5 changed files with 74 additions and 61 deletions
35
src/components/hooks/queries/useWebsitePageviews.ts
Normal file
35
src/components/hooks/queries/useWebsitePageviews.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { useApi, useDateRange, useNavigation, useTimezone } from 'components/hooks';
|
||||
|
||||
export function useWebsitePageviews(websiteId: string, options?: { [key: string]: string }) {
|
||||
const { get, useQuery } = useApi();
|
||||
const [dateRange] = useDateRange(websiteId);
|
||||
const { startDate, endDate, unit } = dateRange;
|
||||
const [timezone] = useTimezone();
|
||||
const {
|
||||
query: { url, referrer, os, browser, device, country, region, city, title },
|
||||
} = useNavigation();
|
||||
|
||||
const params = {
|
||||
startAt: +startDate,
|
||||
endAt: +endDate,
|
||||
unit,
|
||||
timezone,
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
region,
|
||||
city,
|
||||
title,
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['websites:pageviews', params],
|
||||
queryFn: () => get(`/websites/${websiteId}/pageviews`, params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export default useWebsitePageviews;
|
||||
32
src/components/hooks/queries/useWebsiteStats.ts
Normal file
32
src/components/hooks/queries/useWebsiteStats.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { useApi, useDateRange, useNavigation } from 'components/hooks';
|
||||
|
||||
export function useWebsiteStats(websiteId: string, options?: { [key: string]: string }) {
|
||||
const { get, useQuery } = useApi();
|
||||
const [dateRange] = useDateRange(websiteId);
|
||||
const { startDate, endDate } = dateRange;
|
||||
const {
|
||||
query: { url, referrer, title, os, browser, device, country, region, city },
|
||||
} = useNavigation();
|
||||
|
||||
const params = {
|
||||
startAt: +startDate,
|
||||
endAt: +endDate,
|
||||
url,
|
||||
referrer,
|
||||
title,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
region,
|
||||
city,
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['websites:stats', params],
|
||||
queryFn: () => get(`/websites/${websiteId}/stats`, params),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export default useWebsiteStats;
|
||||
|
|
@ -136,10 +136,7 @@ export function BarChart({
|
|||
const updateChart = () => {
|
||||
setTooltipPopup(null);
|
||||
|
||||
datasets.forEach((dataset, index) => {
|
||||
chart.current.data.datasets[index].data = dataset.data;
|
||||
chart.current.data.datasets[index].label = dataset.label;
|
||||
});
|
||||
chart.current.data.datasets = datasets;
|
||||
|
||||
chart.current.options = getOptions();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue