Analytics
Set up analytics in your app to track user visits and actions.
Tools
Setup
Google Analytics
- Sign up at Google Analytics.
- Create a new property, select "Web," and follow the setup wizard.
- Copy the Measurement ID (e.g.,
G-XXXXXXXXXX) from the "Data Stream" settings. - Set environment variable:
.env
ANALYTICS_GA_ID="your-measurement-id" - Enable in config:
shared/config.ts
analytics: { enableGoogleAnalytics: true, },
Umami
- Sign up at Umami or self-host.
- Add a website in the Umami dashboard.
- Copy the Website ID from the tracking code.
- Set environment variable:
.env
ANALYTICS_UMAMI_WEBSITE_ID="your-umami-website-id" - Enable in config:
shared/config.ts
analytics: { enableUmamiAnalytics: true, },
DataFast
- Sign up at DataFast.
- Register your site in the dashboard.
- Copy the Website ID from the site configuration.
- Set environment variable:
.env
ANALYTICS_DATAFAST_WEBSITE_ID="your-datafast-website-id" - Enable in config:
shared/config.ts
analytics: { enableDatafastAnalytics: true, },
Usage
- Page Views: Automatically tracked for every visit.
- User Actions: Clicks, navigation, and interactions are tracked.
- Dashboard: Check analytics data in the provider dashboards:
Track Custom Events
You can track specific actions with $trackEvent:
vue
const { $trackEvent } = useNuxtApp();
// Example: tracking a navbar button click
$trackEvent('navbar', { buttonName: 'Get ShipAhead' });