umami/src/app/(main)/console/TestConsole.tsx

165 lines
5.2 KiB
TypeScript
Raw Normal View History

2023-12-03 11:07:03 +00:00
import { Button } from 'react-basics';
import Link from 'next/link';
import Script from 'next/script';
import WebsiteSelect from 'components/input/WebsiteSelect';
2022-01-15 03:10:46 +00:00
import Page from 'components/layout/Page';
import PageHeader from 'components/layout/PageHeader';
import EventsChart from 'components/metrics/EventsChart';
2024-01-29 22:47:52 +00:00
import WebsiteChart from '../websites/[websiteId]/WebsiteChart';
2024-01-29 02:33:40 +00:00
import { useApi, useNavigation } from 'components/hooks';
import styles from './TestConsole.module.css';
2020-09-27 07:51:29 +00:00
2023-12-03 11:07:03 +00:00
export function TestConsole({ websiteId }: { websiteId: string }) {
const { get, useQuery } = useApi();
2023-12-02 04:27:59 +00:00
const { data, isLoading, error } = useQuery({
queryKey: ['websites:me'],
queryFn: () => get('/me/websites'),
});
2023-10-20 00:01:21 +00:00
const { router } = useNavigation();
2020-09-27 07:51:29 +00:00
2023-12-03 11:07:03 +00:00
function handleChange(value: string) {
router.push(`/console/${value}`);
2020-09-27 07:51:29 +00:00
}
function handleClick() {
2023-12-03 11:07:03 +00:00
window['umami'].track({ url: '/page-view', referrer: 'https://www.google.com' });
window['umami'].track('track-event-no-data');
window['umami'].track('track-event-with-data', {
test: 'test-data',
boolean: true,
booleanError: 'true',
time: new Date(),
2024-06-20 04:41:45 +00:00
user: `user${Math.round(Math.random() * 10)}`,
number: 1,
number2: Math.random() * 100,
time2: new Date().toISOString(),
nested: {
test: 'test-data',
number: 1,
object: {
test: 'test-data',
},
},
array: [1, 2, 3],
});
}
function handleIdentifyClick() {
2023-12-03 11:07:03 +00:00
window['umami'].identify({
userId: 123,
name: 'brian',
number: Math.random() * 100,
test: 'test-data',
boolean: true,
booleanError: 'true',
time: new Date(),
time2: new Date().toISOString(),
nested: {
test: 'test-data',
number: 1,
object: {
test: 'test-data',
},
},
array: [1, 2, 3],
});
2020-09-27 07:51:29 +00:00
}
2023-01-31 05:44:07 +00:00
if (!data) {
return null;
}
2023-08-15 20:08:18 +00:00
const website = data?.data.find(({ id }) => websiteId === id);
2023-01-31 05:44:07 +00:00
2020-09-27 07:51:29 +00:00
return (
2023-12-03 11:07:03 +00:00
<Page isLoading={isLoading} error={error}>
2023-01-31 05:44:07 +00:00
<PageHeader title="Test console">
2023-02-15 10:27:18 +00:00
<WebsiteSelect websiteId={website?.id} onSelect={handleChange} />
2020-09-27 07:51:29 +00:00
</PageHeader>
{website && (
<div className={styles.container}>
2023-03-26 11:15:08 +00:00
<Script
async
2023-10-20 00:01:21 +00:00
data-website-id={websiteId}
2024-05-13 06:15:49 +00:00
src={`${process.env.basePath || ''}/script.js`}
2023-03-26 11:15:08 +00:00
data-cache="true"
/>
<div className={styles.actions}>
<div className={styles.group}>
2023-01-31 05:44:07 +00:00
<div className={styles.header}>Page links</div>
<div>
2023-04-04 07:27:25 +00:00
<Link href={`/console/${websiteId}/page/1/?q=abc`}>page one</Link>
</div>
<div>
2023-04-04 07:27:25 +00:00
<Link href={`/console/${websiteId}/page/2/?q=123 `}>page two</Link>
2020-09-27 07:51:29 +00:00
</div>
<div>
2023-03-26 11:15:08 +00:00
<a href="https://www.google.com" data-umami-event="external-link-direct">
external link (direct)
</a>
2022-01-15 03:10:46 +00:00
</div>
<div>
<a
href="https://www.google.com"
2023-03-26 11:15:08 +00:00
data-umami-event="external-link-tab"
target="_blank"
rel="noreferrer"
>
external link (tab)
</a>
2020-09-27 07:51:29 +00:00
</div>
2023-10-03 06:51:26 +00:00
</div>
<div className={styles.group}>
2023-03-26 11:15:08 +00:00
<div className={styles.header}>Click events</div>
2023-12-03 11:07:03 +00:00
<Button id="send-event-button" data-umami-event="button-click" variant="primary">
Send event
</Button>
2023-03-26 11:15:08 +00:00
<Button
id="send-event-data-button"
data-umami-event="button-click"
data-umami-event-name="bob"
data-umami-event-id="123"
2023-12-03 11:07:03 +00:00
variant="primary"
2023-03-26 11:15:08 +00:00
>
Send event with data
</Button>
<Button
id="button-with-div-button"
data-umami-event="button-click"
data-umami-event-name="bob"
data-umami-event-id="123"
variant="primary"
>
<div className={styles.wrapped}>Button with div</div>
</Button>
<div data-umami-event="div-click" className={styles.wrapped}>
DIV with attribute
</div>
<div data-umami-event="div-click-one" className={styles.wrapped}>
<div data-umami-event="div-click-two" className={styles.wrapped}>
<div data-umami-event="div-click-three" className={styles.wrapped}>
Nested DIV
</div>
</div>
</div>
2023-10-03 06:51:26 +00:00
</div>
<div className={styles.group}>
2023-01-31 05:44:07 +00:00
<div className={styles.header}>Javascript events</div>
2023-12-03 11:07:03 +00:00
<Button id="manual-button" variant="primary" onClick={handleClick}>
Run script
</Button>
2023-12-03 11:07:03 +00:00
<Button id="manual-button" variant="primary" onClick={handleIdentifyClick}>
Run identify
</Button>
2023-10-03 06:51:26 +00:00
</div>
</div>
<WebsiteChart websiteId={website.id} />
<EventsChart websiteId={website.id} />
</div>
2020-09-27 07:51:29 +00:00
)}
</Page>
);
}
2023-04-21 15:00:42 +00:00
export default TestConsole;