Analytics

A component to easily add analytics providers like Vercel and Google Analytics.

Installation

Import the component from the passport-ui package.

components/example.tsx
1import { Analytics, useAnalytics } from "passport-ui";

Usage

Basic example showing how to use the component.

components/example.tsx
1{/* Place once in your app root */}
2<Analytics
3 providers={{
4 googleAnalytics: {
5 trackingId: "G-XXXXXXXXXX",
6 },
7 }}
8 enabled={process.env.NODE_ENV === "production"}
9/>
10
11{/* Use the hook in components */}
12function TrackingExample() {
13 const { trackEvent, trackPageView, setUserProperties } = useAnalytics();
14
15 const handleButtonClick = () => {
16 trackEvent('button_click', {
17 category: 'ui',
18 label: 'header_cta'
19 });
20 };
21
22 const handlePageView = () => {
23 trackPageView('/demo-page');
24 };
25
26 return (
27 <Button onClick={handleButtonClick}>
28 Track Click Event
29 </Button>
30 );
31}

Additional resources

Documentation and examples are available in Storybook.