2020-09-27 09:51:29 +02:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import Head from 'next/head';
|
|
|
|
import Link from 'next/link';
|
2021-11-21 04:37:13 +01:00
|
|
|
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 DropDown from 'components/common/DropDown';
|
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
|
|
|
import EventsChart from 'components/metrics/EventsChart';
|
|
|
|
import Button from 'components/common/Button';
|
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
|
|
|
import Icon from 'components/common/Icon';
|
|
|
|
import useFetch from 'hooks/useFetch';
|
2022-02-23 07:47:59 +01:00
|
|
|
import useUser from 'hooks/useUser';
|
2022-01-15 04:10:46 +01:00
|
|
|
import ChevronDown from 'assets/chevron-down.svg';
|
2020-10-09 00:02:48 +02:00
|
|
|
import styles from './TestConsole.module.css';
|
2020-09-27 09:51:29 +02:00
|
|
|
|
2020-09-29 05:23:42 +02:00
|
|
|
export default function TestConsole() {
|
2022-02-23 07:47:59 +01:00
|
|
|
const { user } = useUser();
|
2020-09-27 09:51:29 +02:00
|
|
|
const [website, setWebsite] = useState();
|
2022-01-15 04:10:46 +01:00
|
|
|
const [show, setShow] = useState(true);
|
2021-11-21 04:37:13 +01:00
|
|
|
const { basePath } = useRouter();
|
2022-02-23 08:52:31 +01:00
|
|
|
const { data } = useFetch('/websites');
|
2020-09-27 09:51:29 +02:00
|
|
|
|
2020-09-29 05:23:42 +02:00
|
|
|
if (!data || !user?.is_admin) {
|
2020-09-27 09:51:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = data.map(({ name, website_id }) => ({ label: name, value: website_id }));
|
|
|
|
const selectedValue = options.find(({ value }) => value === website?.website_id)?.value;
|
|
|
|
|
|
|
|
function handleSelect(value) {
|
|
|
|
setWebsite(data.find(({ website_id }) => website_id === value));
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleClick() {
|
|
|
|
window.umami('event (default)');
|
|
|
|
window.umami.trackView('/page-view', 'https://www.google.com');
|
|
|
|
window.umami.trackEvent('event (custom)', 'custom-type');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<Head>
|
|
|
|
{typeof window !== 'undefined' && website && (
|
2021-11-21 04:37:13 +01:00
|
|
|
<script async defer data-website-id={website.website_uuid} src={`${basePath}/umami.js`} />
|
2020-09-27 09:51:29 +02:00
|
|
|
)}
|
|
|
|
</Head>
|
|
|
|
<PageHeader>
|
|
|
|
<div>Test Console</div>
|
|
|
|
<DropDown
|
|
|
|
value={selectedValue || 'Select website'}
|
|
|
|
options={options}
|
|
|
|
onChange={handleSelect}
|
|
|
|
/>
|
|
|
|
</PageHeader>
|
|
|
|
{!selectedValue && <EmptyPlaceholder msg="I hope you know what you're doing here" />}
|
|
|
|
{selectedValue && (
|
|
|
|
<>
|
2022-01-15 04:10:46 +01:00
|
|
|
<div>
|
|
|
|
<Icon
|
|
|
|
icon={<ChevronDown />}
|
|
|
|
className={classNames({ [styles.hidden]: !show })}
|
|
|
|
onClick={() => setShow(!show)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{show && (
|
|
|
|
<div className={classNames(styles.test, 'row')}>
|
|
|
|
<div className="col-4">
|
2022-03-02 04:28:44 +01:00
|
|
|
<PageHeader>Page links</PageHeader>Nmo
|
2022-01-15 04:10:46 +01:00
|
|
|
<div>
|
|
|
|
<Link href={`?page=1`}>
|
|
|
|
<a>page one</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Link href={`?page=2`}>
|
|
|
|
<a>page two</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2022-03-02 04:28:44 +01:00
|
|
|
<div>
|
|
|
|
<Link href={`https://www.google.com`}>
|
|
|
|
<a className="umami--click--external-link">external link</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2020-09-27 09:51:29 +02:00
|
|
|
</div>
|
2022-01-15 04:10:46 +01:00
|
|
|
<div className="col-4">
|
|
|
|
<PageHeader>CSS events</PageHeader>
|
|
|
|
<Button
|
|
|
|
id="primary-button"
|
|
|
|
className="umami--click--primary-button"
|
|
|
|
variant="action"
|
|
|
|
>
|
|
|
|
Send event
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="col-4">
|
|
|
|
<PageHeader>Javascript events</PageHeader>
|
|
|
|
<Button id="manual-button" variant="action" onClick={handleClick}>
|
|
|
|
Run script
|
|
|
|
</Button>
|
2020-09-27 09:51:29 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-01-15 04:10:46 +01:00
|
|
|
)}
|
2020-09-27 09:51:29 +02:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
2020-10-21 15:44:43 +02:00
|
|
|
<WebsiteChart
|
|
|
|
websiteId={website.website_id}
|
|
|
|
title={website.name}
|
|
|
|
domain={website.domain}
|
|
|
|
showLink
|
|
|
|
/>
|
2020-09-27 09:51:29 +02:00
|
|
|
<PageHeader>Events</PageHeader>
|
|
|
|
<EventsChart websiteId={website.website_id} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|