Google Analytics Setup Guide
Google Analytics Setup Guide
This repository comes with built-in support for Google Analytics. Follow this guide to set up Google Analytics tracking for your website.
Overview
The site supports three different Google Analytics implementations:
- Google Analytics 4 (GA4) - Recommended for new websites
- Universal Analytics - Legacy version (sunset on July 1, 2023)
- Classic Google Analytics - Older legacy version
We recommend using Google Analytics 4 (GA4) as it’s the current version supported by Google.
Step 1: Create a Google Analytics Account
- Go to Google Analytics
- Sign in with your Google account
- Click Start measuring or Admin (gear icon)
- Create an account:
- Enter an Account Name (e.g., “Personal Website”)
- Configure account data sharing settings
- Click Next
Step 2: Set Up a Property
- Enter a Property Name (e.g., “My GitHub Pages Site”)
- Select your Reporting Time Zone
- Select your Currency
- Click Next
Step 3: Configure Property Details
- Select your business category and size
- Choose how you plan to use Google Analytics
- Click Create
- Accept the Terms of Service
Step 4: Set Up Data Stream
- Choose Web as your platform
- Enter your website URL:
https://[your-github-username].github.io- For example:
https://mtyrolski.github.io
- For example:
- Enter a Stream name (e.g., “GitHub Pages Site”)
- Click Create stream
Step 5: Get Your Measurement ID
After creating the data stream, you’ll see your Measurement ID (also called Tracking ID). It looks like:
- GA4 format:
G-XXXXXXXXXX(starts with “G-“) - Universal Analytics format:
UA-XXXXXXXXX-X(starts with “UA-“)
Copy this ID - you’ll need it for the next step.
Step 6: Configure Your Jekyll Site
- Open the
_config.ymlfile in your repository - Find the
analyticssection (around line 100-105):
# Analytics
analytics:
provider : "false"
google:
tracking_id :
- Update it with your Google Analytics settings:
For Google Analytics 4 (Recommended):
# Analytics
analytics:
provider : "google-analytics-4"
google:
tracking_id : "G-XXXXXXXXXX"
For Universal Analytics (Legacy):
# Analytics
analytics:
provider : "google-universal"
google:
tracking_id : "UA-XXXXXXXXX-X"
For Classic Google Analytics (Legacy):
# Analytics
analytics:
provider : "google"
google:
tracking_id : "UA-XXXXXXXXX-X"
- Replace
G-XXXXXXXXXX(orUA-XXXXXXXXX-X) with your actual Measurement ID - Save the file
Step 7: Commit and Deploy
- Commit your changes:
git add _config.yml git commit -m "Add Google Analytics tracking" git push - GitHub Pages will automatically rebuild your site (this may take a few minutes)
Step 8: Verify Installation
- Visit your website:
https://[your-github-username].github.io - Open your browser’s Developer Tools (F12)
- Go to the Network tab
- Refresh the page
- Look for requests to:
googletagmanager.com(for GA4)google-analytics.com(for Universal/Classic)
- In Google Analytics:
- Go to Reports → Realtime
- You should see your visit appear within a few seconds
Disabling Analytics on Specific Pages
If you want to disable analytics tracking on specific pages, add this to the page’s front matter:
---
title: "My Page"
analytics: false
---
Troubleshooting
Analytics not working?
- Check your tracking ID format:
- GA4 IDs start with
G- - Universal Analytics IDs start with
UA- - Make sure you’re using the correct provider for your ID format
- GA4 IDs start with
- Verify the configuration:
- Open
_config.ymland ensure:- The provider is NOT set to
"false" - The tracking_id is properly formatted with quotes
- There are no extra spaces or typos
- The provider is NOT set to
- Open
- Check if the site has rebuilt:
- Go to your repository on GitHub
- Click on Actions tab
- Check if the latest deployment succeeded (green checkmark)
- Verify the analytics code is included:
- View the page source of your website
- Search for
gtag(GA4) orgoogle-analytics.com(Universal) - The tracking code should be present in the HTML
- Browser extensions:
- Ad blockers and privacy extensions may block Google Analytics
- Try testing in an incognito/private window
- Or temporarily disable extensions
- Clear your browser cache:
- Your browser might be showing a cached version of the site
- Hard refresh: Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (Mac)
Data not showing in Google Analytics?
- It can take 24-48 hours for data to appear in standard reports
- Check Realtime reports for immediate verification
- Make sure your site has actual visitors (visit it yourself!)
Additional Features
Event Tracking
Google Analytics 4 automatically tracks many events. To track custom events, you can use JavaScript in your pages:
gtag('event', 'event_name', {
'event_category': 'category',
'event_label': 'label',
'value': 1
});
Enhanced Measurement
In your GA4 property settings, you can enable enhanced measurement for:
- Page views
- Scrolls
- Outbound clicks
- Site search
- Video engagement
- File downloads
To enable these:
- Go to Admin → Data Streams
- Click on your web stream
- Toggle Enhanced measurement on
- Click the gear icon to customize which events to track
Privacy Considerations
When using Google Analytics, consider:
- Add a Privacy Policy: Inform visitors about your use of analytics
- Cookie Consent: Consider implementing a cookie consent banner for GDPR compliance
- IP Anonymization: GA4 anonymizes IP addresses by default
- Data Retention: Configure data retention settings in Google Analytics Admin
Resources
- Google Analytics 4 Documentation
- GA4 Setup Guide
- Migrating from Universal Analytics to GA4
- Jekyll Analytics Documentation
Support
If you encounter issues:
- Check the troubleshooting section above
- Review the Google Analytics Help Center
- Open an issue in the repository with details about your problem