Google Analytics 4 Setup Guide
What’s Been Configured
I’ve added Google Analytics 4 tracking to your GitHub Pages site:
- _config.yml - Added analytics configuration
- _includes/analytics.html - GA4 tracking code
- _includes/head.html - Custom head include with analytics
Next Steps: Get Your Google Analytics Tracking ID
1. Create Google Analytics Account
- Go to https://analytics.google.com/
- Sign in with your Google account
- Click “Start measuring” or “Admin” (gear icon)
2. Create a Property (GA4)
- Click “Create Property”
- Enter property details:
- Property name: “Ramesh’s Tech Blog” (or your preference)
- Reporting time zone: Your timezone
- Currency: USD (or your preference)
- Click “Next”
3. Set Up Data Stream
- Choose “Web” as the platform
- Enter your website details:
- Website URL:
https://r2rajan.github.io - Stream name: “GitHub Pages Blog”
- Website URL:
- Click “Create stream”
4. Get Your Measurement ID
- You’ll see a Measurement ID that looks like:
G-XXXXXXXXXX - Copy this ID
5. Update Your Site Configuration
- Open
_config.yml - Find this section:
analytics: provider: "google-gtag" google: tracking_id: "G-XXXXXXXXXX" # Replace with your GA4 Measurement ID - Replace
G-XXXXXXXXXXwith your actual Measurement ID - Save the file
6. Deploy Your Changes
git add _config.yml _includes/analytics.html _includes/head.html
git commit -m "Add Google Analytics 4 tracking"
git push origin main
Wait 2-5 minutes for GitHub Pages to rebuild your site.
7. Test Your Analytics
- Visit your website: https://r2rajan.github.io
- In Google Analytics, go to Reports → Realtime
- You should see your visit appear within 30 seconds!
How to Track Top Performing Posts
After 1-2 weeks of data collection:
- Go to Reports → Engagement → Pages and screens
- You’ll see a list of all pages with:
- Views
- Users
- Average engagement time
- Events per session
- To see your top blog posts specifically:
- Click Add filter (funnel icon)
- Select “Page path and screen class”
- Choose “contains” and enter
/20(to filter blog posts by year) - Apply filter
- Export Reports:
- Click the Share icon (top right)
- Download as PDF, CSV, or Google Sheets
Custom Reports for Blog Posts
- Go to Explore (left sidebar)
- Create a Free form exploration
- Add dimensions:
- Page path
- Page title
- Add metrics:
- Views
- Users
- Average engagement time
- Save and bookmark this report
Privacy & GDPR Compliance
The current setup:
- ✅ Uses GA4 (more privacy-focused than Universal Analytics)
- ✅ Cookie consent flags set
- ⚠️ IP anonymization is OFF (set to
truein _config.yml if needed for GDPR)
To enable IP anonymization:
analytics:
provider: "google-gtag"
google:
tracking_id: "G-XXXXXXXXXX"
anonymize_ip: true # Change to true
Troubleshooting
Analytics not showing data?
- Check your Measurement ID is correct in
_config.yml - Verify site has been rebuilt (check GitHub Actions)
- Clear browser cache
- Check browser console for errors (F12)
- Verify GA4 tag with Google Tag Assistant extension
Want to exclude your own visits?
- In Google Analytics, go to Admin → Data Streams
- Click your stream → Configure tag settings → Show all
- Click Define internal traffic
- Add your IP address