umami/pages/test.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-07-24 04:56:55 +02:00
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/router';
2020-08-07 11:27:12 +02:00
import Layout from 'components/layout/Layout';
2020-07-24 04:56:55 +02:00
export default function Test() {
const router = useRouter();
const { id } = router.query;
if (!id) {
return <h1>No id query specified.</h1>;
}
2020-09-18 22:40:46 +02:00
function handleClick() {
window.umami('Custom event');
window.umami.pageView('/fake', 'https://www.google.com');
window.umami.pageEvent('pageEvent', 'custom-type');
}
2020-07-24 04:56:55 +02:00
return (
<>
<Head>
{typeof window !== 'undefined' && (
<script async defer data-website-id={id} src="/umami.js" />
2020-07-24 04:56:55 +02:00
)}
</Head>
<Layout>
<p>
2020-09-18 22:40:46 +02:00
Here you can test if your umami installation works. Open the network tab in your browser
2020-07-24 04:56:55 +02:00
developer console and watch for requests to the url <b>collect</b>. The links below should
trigger page views. Clicking on the button should trigger an event.
</p>
<h2>Page links</h2>
<Link href={`?id=${id}&q=1`}>
2020-07-24 04:56:55 +02:00
<a>Page One</a>
</Link>
<br />
<Link href={`?id=${id}&q=2`}>
2020-07-24 04:56:55 +02:00
<a>Page Two</a>
</Link>
<h2>Events</h2>
<button
id="primary-button"
className="otherClass umami--click--primary-button align-self-start"
2020-07-24 04:56:55 +02:00
type="button"
>
Button
</button>
2020-09-18 22:40:46 +02:00
<h2>Manual trigger</h2>
<button id="manual-button" type="button" onClick={handleClick}>
Button
</button>
2020-07-24 04:56:55 +02:00
</Layout>
</>
);
}