2023-12-03 11:07:03 +00:00
|
|
|
import { Button } from 'react-basics';
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
import Script from 'next/script';
|
2023-03-23 21:01:15 +00:00
|
|
|
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';
|
2020-10-08 22:02:48 +00:00
|
|
|
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 }) {
|
2022-12-28 23:43:22 +00:00
|
|
|
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) {
|
2022-08-09 17:27:35 +00:00
|
|
|
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', {
|
2023-06-01 04:46:49 +00:00
|
|
|
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)}`,
|
2023-06-01 04:46:49 +00:00
|
|
|
number: 1,
|
2023-07-11 06:08:57 +00:00
|
|
|
number2: Math.random() * 100,
|
2023-06-01 04:46:49 +00:00
|
|
|
time2: new Date().toISOString(),
|
|
|
|
|
nested: {
|
2023-03-23 21:01:15 +00:00
|
|
|
test: 'test-data',
|
|
|
|
|
number: 1,
|
2023-06-01 04:46:49 +00:00
|
|
|
object: {
|
2023-03-23 21:01:15 +00:00
|
|
|
test: 'test-data',
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-01 04:46:49 +00:00
|
|
|
array: [1, 2, 3],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleIdentifyClick() {
|
2023-12-03 11:07:03 +00:00
|
|
|
window['umami'].identify({
|
2023-06-01 04:46:49 +00:00
|
|
|
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],
|
2023-03-23 21:01:15 +00:00
|
|
|
});
|
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>
|
2022-08-09 17:27:35 +00:00
|
|
|
{website && (
|
2024-01-15 05:17:11 +00:00
|
|
|
<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"
|
|
|
|
|
/>
|
2024-01-15 05:17:11 +00:00
|
|
|
<div className={styles.actions}>
|
|
|
|
|
<div className={styles.group}>
|
2023-01-31 05:44:07 +00:00
|
|
|
<div className={styles.header}>Page links</div>
|
2022-08-09 17:27:35 +00:00
|
|
|
<div>
|
2023-04-04 07:27:25 +00:00
|
|
|
<Link href={`/console/${websiteId}/page/1/?q=abc`}>page one</Link>
|
2022-08-09 17:27:35 +00:00
|
|
|
</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>
|
2022-08-09 17:27:35 +00:00
|
|
|
<div>
|
2023-03-26 11:15:08 +00:00
|
|
|
<a href="https://www.google.com" data-umami-event="external-link-direct">
|
2023-03-09 04:23:32 +00:00
|
|
|
external link (direct)
|
|
|
|
|
</a>
|
2022-01-15 03:10:46 +00:00
|
|
|
</div>
|
2022-08-09 17:27:35 +00:00
|
|
|
<div>
|
2023-03-09 04:23:32 +00:00
|
|
|
<a
|
|
|
|
|
href="https://www.google.com"
|
2023-03-26 11:15:08 +00:00
|
|
|
data-umami-event="external-link-tab"
|
2023-03-09 04:23:32 +00:00
|
|
|
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>
|
2024-01-15 05:17:11 +00:00
|
|
|
<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">
|
2022-08-09 17:27:35 +00:00
|
|
|
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>
|
2024-01-15 05:17:11 +00:00
|
|
|
<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>
|
2024-01-15 05:17:11 +00:00
|
|
|
<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}>
|
2022-08-09 17:27:35 +00:00
|
|
|
Run script
|
|
|
|
|
</Button>
|
2023-12-03 11:07:03 +00:00
|
|
|
<Button id="manual-button" variant="primary" onClick={handleIdentifyClick}>
|
2023-06-01 04:46:49 +00:00
|
|
|
Run identify
|
|
|
|
|
</Button>
|
2023-10-03 06:51:26 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-01-15 05:17:11 +00:00
|
|
|
<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;
|