Analytics Setup
Add analytics to your Pagesmith site. Google Analytics, Plausible, and other tracking tools.
Track visitors, conversions, and user behavior with analytics.
Adding Analytics
Via Code Editor
- Open Code tab in the editor
- Find your layout file (
src/layouts/Layout.astro) - Add the script before
</head>
Via AI
Add [Analytics Provider] tracking to all pages. Use tracking ID: [your-id]
Google Analytics 4
Add to your layout:
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
Replace G-XXXXXXX with your Measurement ID.
Plausible
Lightweight, privacy-focused alternative:
<script defer data-domain="yoursite.com" src="https://plausible.io/js/script.js"></script>
Benefits:
- No cookies needed
- GDPR compliant by default
- Simpler dashboard
- Better performance
Fathom
Another privacy-focused option:
<script src="https://cdn.usefathom.com/script.js" data-site="XXXXXXXX" defer></script>
Vercel Analytics
If hosting on Vercel:
npm install @vercel/analytics
---
import { Analytics } from '@vercel/analytics/react';
---
<Analytics />
What to Track
Page Views
All analytics tools track automatically.
Events
Track specific actions:
// Google Analytics
gtag('event', 'signup', {
'event_category': 'conversion',
'event_label': 'hero_cta'
});
// Plausible
plausible('Signup', { props: { location: 'hero' } });
Conversions
Track goal completions:
- Form submissions
- Button clicks
- Purchases
Privacy Considerations
Cookie Consent
If using cookies (Google Analytics), add consent:
<!-- Show banner before loading analytics -->
<script>
if (userConsented) {
// Load analytics
}
</script>
Cookieless Options
Plausible and Fathom don't use cookies — no consent banner needed.
Self-Hosted Analytics
For full control:
- Plausible Cloud or self-hosted
- Umami (open source)
- Matomo
Debugging
Check Installation
- Open browser DevTools
- Go to Network tab
- Filter by analytics domain
- Verify requests are sent
Real-Time Reports
Most tools show real-time data:
- Visit your site
- Check real-time dashboard
- Confirm tracking works
Related Docs
- Publishing — Deploy your site
- SEO Best Practices — Track search performance