When I launched my portfolio, I wanted to know:
Who’s visiting it? Where from? What pages?
That’s when I turned to Google Analytics.
🔍 Why Google Analytics?
It helps you track:
- Page views & unique users
- Bounce rate
- Traffic sources (referrals, search, direct)
- Device and location stats
🚀 How I Integrated It
- Created a GA4 property on Google Analytics
- Grabbed the measurement ID (e.g.,
G-XXXXXXXX) - Added this tracking script to my Astro site:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXX');
</script>