2020-08-01 04:05:14 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import WebsiteChart from './WebsiteChart';
|
|
|
|
import RankingsChart from './RankingsChart';
|
2020-08-01 12:34:56 +02:00
|
|
|
import WorldMap from './WorldMap';
|
2020-08-06 04:04:02 +02:00
|
|
|
import Page from './Page';
|
2020-08-01 12:34:56 +02:00
|
|
|
import { getDateRange } from 'lib/date';
|
|
|
|
import { get } from 'lib/web';
|
|
|
|
import { browserFilter, urlFilter, refFilter, deviceFilter, countryFilter } from 'lib/filters';
|
2020-08-01 04:05:14 +02:00
|
|
|
import styles from './WebsiteDetails.module.css';
|
|
|
|
|
2020-08-01 06:56:25 +02:00
|
|
|
const pageviewClasses = 'col-md-12 col-lg-6';
|
|
|
|
const sessionClasses = 'col-12 col-lg-4';
|
2020-08-01 04:05:14 +02:00
|
|
|
|
|
|
|
export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' }) {
|
|
|
|
const [data, setData] = useState();
|
2020-08-04 08:20:35 +02:00
|
|
|
const [chartLoaded, setChartLoaded] = useState(false);
|
2020-08-01 12:34:56 +02:00
|
|
|
const [countryData, setCountryData] = useState();
|
2020-08-01 04:05:14 +02:00
|
|
|
const [dateRange, setDateRange] = useState(getDateRange(defaultDateRange));
|
|
|
|
const { startDate, endDate } = dateRange;
|
|
|
|
|
|
|
|
async function loadData() {
|
|
|
|
setData(await get(`/api/website/${websiteId}`));
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:20:35 +02:00
|
|
|
function handleDataLoad() {
|
|
|
|
if (!chartLoaded) setTimeout(() => setChartLoaded(true), 300);
|
|
|
|
}
|
|
|
|
|
2020-08-01 04:05:14 +02:00
|
|
|
function handleDateChange(values) {
|
2020-08-02 09:51:26 +02:00
|
|
|
setTimeout(() => setDateRange(values), 300);
|
2020-08-01 04:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (websiteId) {
|
|
|
|
loadData();
|
|
|
|
}
|
|
|
|
}, [websiteId]);
|
|
|
|
|
|
|
|
if (!data) {
|
2020-08-02 08:37:46 +02:00
|
|
|
return null;
|
2020-08-01 04:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-06 04:04:02 +02:00
|
|
|
<Page>
|
2020-08-01 04:05:14 +02:00
|
|
|
<div className="row">
|
2020-08-01 06:56:25 +02:00
|
|
|
<div className={classNames(styles.chart, 'col')}>
|
2020-08-04 03:12:28 +02:00
|
|
|
<h2>{data.label}</h2>
|
2020-08-04 08:20:35 +02:00
|
|
|
<WebsiteChart
|
2020-08-04 03:12:28 +02:00
|
|
|
websiteId={websiteId}
|
2020-08-04 08:20:35 +02:00
|
|
|
onDataLoad={handleDataLoad}
|
|
|
|
onDateChange={handleDateChange}
|
|
|
|
stickyHeader
|
2020-08-04 03:12:28 +02:00
|
|
|
/>
|
2020-08-02 06:20:52 +02:00
|
|
|
</div>
|
2020-08-01 12:34:56 +02:00
|
|
|
</div>
|
2020-08-04 08:20:35 +02:00
|
|
|
{chartLoaded && (
|
|
|
|
<>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
|
|
|
<div className={pageviewClasses}>
|
|
|
|
<RankingsChart
|
|
|
|
title="Pages"
|
|
|
|
type="url"
|
|
|
|
heading="Views"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
dataFilter={urlFilter}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={pageviewClasses}>
|
|
|
|
<RankingsChart
|
|
|
|
title="Referrers"
|
|
|
|
type="referrer"
|
|
|
|
heading="Views"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
dataFilter={refFilter}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
|
|
|
<div className={sessionClasses}>
|
|
|
|
<RankingsChart
|
|
|
|
title="Browsers"
|
|
|
|
type="browser"
|
|
|
|
heading="Visitors"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
dataFilter={browserFilter}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={sessionClasses}>
|
|
|
|
<RankingsChart
|
|
|
|
title="Operating system"
|
|
|
|
type="os"
|
|
|
|
heading="Visitors"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={sessionClasses}>
|
|
|
|
<RankingsChart
|
|
|
|
title="Devices"
|
2020-08-07 04:37:19 +02:00
|
|
|
type="device"
|
2020-08-04 08:20:35 +02:00
|
|
|
heading="Visitors"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
dataFilter={deviceFilter}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
|
|
|
<div className="col-12 col-md-12 col-lg-8">
|
|
|
|
<WorldMap data={countryData} />
|
|
|
|
</div>
|
|
|
|
<div className="col-12 col-md-12 col-lg-4">
|
|
|
|
<RankingsChart
|
|
|
|
title="Countries"
|
|
|
|
type="country"
|
|
|
|
heading="Visitors"
|
|
|
|
websiteId={websiteId}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
|
|
|
dataFilter={countryFilter}
|
|
|
|
onDataLoad={data => setCountryData(data)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
2020-08-06 04:04:02 +02:00
|
|
|
</Page>
|
2020-08-01 04:05:14 +02:00
|
|
|
);
|
|
|
|
}
|