---
title: Analytics Events
lastModified: "2026-10-14T22:13:04-07:00"
lastAuthor: Kaylee
---
```tsx title="src/components/pageviews.tsx"
import { useLocation } from '@tanstack/react-router';
import { useEventDispatcher } from 'c15t/tanstack-start';
import { useEffect } from 'react';

/** Render once inside `ConsentRoot`, such as in the root route. */
export const Pageviews = () => {
	const events = useEventDispatcher({ pageviews: ['posthog'] });
	// The path with its query string, so search and filter changes count.
	const href = useLocation({ select: (location) => location.href });
	useEffect(() => {
		events.pageview(href);
	}, [events, href]);
	return null;
};
```
