umami/components/pages/console/TestConsole.js

115 lines
3.6 KiB
JavaScript
Raw Normal View History

2023-01-31 06:44:07 +01:00
import { Button, Column, Row, Dropdown, Item } from 'react-basics';
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/router';
2022-01-15 04:10:46 +01:00
import Page from 'components/layout/Page';
import PageHeader from 'components/layout/PageHeader';
import EventsChart from 'components/metrics/EventsChart';
import WebsiteChart from 'components/metrics/WebsiteChart';
2023-02-15 11:27:18 +01:00
import WebsiteSelect from 'components/input/WebsiteSelect';
import useApi from 'hooks/useApi';
import styles from './TestConsole.module.css';
2020-09-27 09:51:29 +02:00
export default function TestConsole() {
const { get, useQuery } = useApi();
2023-02-15 11:27:18 +01:00
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
const router = useRouter();
const {
basePath,
query: { id },
} = router;
2020-09-27 09:51:29 +02:00
2023-01-31 06:44:07 +01:00
function handleChange(value) {
router.push(`/console/${value}`);
2020-09-27 09:51:29 +02:00
}
function handleClick() {
window.umami('umami-default');
2020-09-27 09:51:29 +02:00
window.umami.trackView('/page-view', 'https://www.google.com');
window.umami.trackEvent('track-event-no-data');
window.umami.trackEvent('track-event-with-data', { test: 'test-data', time: Date.now() });
2020-09-27 09:51:29 +02:00
}
2023-01-31 06:44:07 +01:00
if (!data) {
return null;
}
const websiteId = id?.[0];
const website = data.find(({ id }) => websiteId === id);
2020-09-27 09:51:29 +02:00
return (
2023-01-31 06:44:07 +01:00
<Page loading={isLoading} error={error}>
2020-09-27 09:51:29 +02:00
<Head>
{typeof window !== 'undefined' && website && (
2022-03-11 05:39:11 +01:00
<script
async
defer
2022-11-01 07:42:37 +01:00
data-website-id={website.id}
2022-03-11 05:39:11 +01:00
src={`${basePath}/umami.js`}
data-cache="true"
/>
2020-09-27 09:51:29 +02:00
)}
</Head>
2023-01-31 06:44:07 +01:00
<PageHeader title="Test console">
2023-02-15 11:27:18 +01:00
<WebsiteSelect websiteId={website?.id} onSelect={handleChange} />
2020-09-27 09:51:29 +02:00
</PageHeader>
{website && (
2020-09-27 09:51:29 +02:00
<>
<Row className={styles.test}>
<Column xs="4">
2023-01-31 06:44:07 +01:00
<div className={styles.header}>Page links</div>
<div>
<Link href={`/console/${websiteId}?page=1`}>
<a>page one</a>
</Link>
</div>
<div>
<Link href={`/console/${websiteId}?page=2`}>
<a>page two</a>
</Link>
2020-09-27 09:51:29 +02:00
</div>
<div>
<Link href={`https://www.google.com`}>
<a className="umami--click--external-link-direct">external link (direct)</a>
</Link>
2022-01-15 04:10:46 +01:00
</div>
<div>
<Link href={`https://www.google.com`}>
<a className="umami--click--external-link-tab" target="_blank">
external link (tab)
</a>
</Link>
2020-09-27 09:51:29 +02:00
</div>
</Column>
<Column xs="4">
2023-01-31 06:44:07 +01:00
<div className={styles.header}>CSS events</div>
<Button id="primary-button" className="umami--click--button-click" variant="action">
Send event
</Button>
</Column>
<Column xs="4">
2023-01-31 06:44:07 +01:00
<div className={styles.header}>Javascript events</div>
<Button id="manual-button" variant="action" onClick={handleClick}>
Run script
</Button>
</Column>
</Row>
<Row>
<Column>
2023-01-31 06:44:07 +01:00
<div className={styles.header}>Statistics</div>
2020-10-21 15:44:43 +02:00
<WebsiteChart
2022-11-01 07:42:37 +01:00
websiteId={website.id}
2020-10-21 15:44:43 +02:00
title={website.name}
domain={website.domain}
showLink
/>
2023-01-31 06:44:07 +01:00
<div className={styles.header}>Events</div>
2022-11-01 07:42:37 +01:00
<EventsChart websiteId={website.id} />
</Column>
</Row>
2020-09-27 09:51:29 +02:00
</>
)}
</Page>
);
}