Google Analytics & AdSense Integration Guide
Google Analytics & AdSense Integration Guide
🚨 IMPORTANT: Replace Placeholder IDs
Before going live, you MUST replace these placeholder IDs with your actual Google IDs:
1. Google Analytics Setup
- Create Google Analytics Account:
- Go to https://analytics.google.com/
- Create a new property for your website
- Get your Measurement ID (format:
G-XXXXXXXXXX)
- Replace in Cookie Consent file:
- File:
_includes/cookie-consent.html - Find:
G-XXXXXXXXXX(appears twice) - Replace with your actual Measurement ID
- File:
2. Google AdSense Setup
- Apply for Google AdSense:
- Go to https://www.google.com/adsense/
- Submit your website for review
- Wait for approval (can take days/weeks)
- Get your Publisher ID:
- Format:
ca-pub-XXXXXXXXXXXXXXXX - Find it in your AdSense dashboard
- Format:
- Replace in files:
- File:
_includes/cookie-consent.html- Find:
ca-pub-XXXXXXXXXXXXXXXX - Replace with your Publisher ID
- Find:
- File:
_includes/ad-banner.html- Find:
ca-pub-XXXXXXXXXXXXXXXX - Replace with your Publisher ID
- Find:
1234567890 - Replace with actual ad slot ID from AdSense
- Find:
- File:
📝 How to Use Ad Units
Adding Ads to Race Pages
Edit your save_markdown() function in scrape_and_generate.py:
# Add this after the race summary, before the results table
md += f"""
{summary}
<!-- Advertisement -->
{{% include ad-banner.html %}}
---
**Crónica por:** [{author_info['name']}]({author_info['url']})
"""
Manual Ad Placement
You can manually add ads to any markdown file:
<!-- In any .md file -->
<!-- Google AdSense Ad Unit - Replace with your actual ad code -->
<!-- This is a responsive banner ad - place it between content sections -->
<div class="ad-container" style="text-align: center; margin: 20px 0; padding: 10px;">
<p style="font-size: 12px; color: #666; margin-bottom: 10px;">Publicidad</p>
<!-- Replace 'ca-pub-XXXXXXXXXXXXXXXX' with your Publisher ID -->
<!-- Replace '1234567890' with your actual ad slot ID -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-XXXXXXXXXXXXXXXX"
data-ad-slot="1234567890"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<style>
.ad-container {
border: 1px solid #e1e1e1;
border-radius: 4px;
background-color: #fafafa;
margin: 20px auto;
max-width: 100%;
}
@media (max-width: 768px) {
.ad-container {
margin: 15px 5px;
}
}
</style>
🔧 Testing
Test Cookie Consent:
- Clear your browser cookies for your site
- Reload the page
- Cookie banner should appear
- Test all consent options
Test Analytics:
- Install Google Analytics Debugger extension
- Check Real-time reports in Analytics dashboard
- Verify events are being tracked
Test AdSense:
- Ads may take 24-48 hours to appear after setup
- Use Chrome DevTools to check for AdSense errors
- Check AdSense dashboard for policy issues
⚖️ Legal Compliance
GDPR Requirements Met:
- ✅ Cookie consent banner
- ✅ Granular cookie controls
- ✅ Privacy policy with all required information
- ✅ Cookie policy with detailed explanations
- ✅ User rights clearly explained
- ✅ Legal basis for processing stated
Additional Recommendations:
- Privacy Policy Link: Already added to footer
- Cookie Settings: Users can reconfigure anytime
- Data Retention: Clearly stated in policies
- Third-party Disclosure: Google partnerships disclosed
- Contact Information: Available via GitHub
🌍 International Considerations
EU/GDPR:
- All requirements covered in privacy and cookie policies
- Explicit consent required for advertising cookies
California (CCPA):
- Current implementation covers basic requirements
- Consider adding “Do Not Sell My Info” if needed
UK (UK-GDPR):
- Same requirements as EU GDPR
- Current implementation is compliant
📊 Analytics Events to Track
Consider adding custom events in your race pages:
// Track race page views by type
gtag('event', 'race_view', {
'race_type': 'road', // or 'cyclocross', 'gravel', etc.
'author': 'Javier Morata'
});
// Track popular races
gtag('event', 'popular_race', {
'race_name': 'Tour de France'
});
🚀 Performance Tips
- Lazy Loading: Ads load after cookie consent
- Mobile Optimization: Responsive ad units included
- Page Speed: Analytics loads asynchronously
- SEO: Privacy pages help with search rankings
🛠️ Troubleshooting
Common Issues:
- Ads not showing:
- Check AdSense approval status
- Verify Publisher ID is correct
- Check browser ad blockers
- Analytics not tracking:
- Verify Measurement ID
- Check cookie consent is accepted
- Use Analytics debugger
- Cookie banner not appearing:
- Clear browser cookies
- Check console for JavaScript errors
📋 Go-Live Checklist
- Replace all placeholder IDs
- Test cookie consent functionality
- Verify Analytics tracking
- Confirm AdSense approval
- Test on mobile devices
- Check page load speed
- Verify legal pages accessibility
- Test from different countries (VPN)
📈 Revenue Optimization
Once everything is working:
- Analyze Traffic: Use Analytics to find popular content
- Ad Placement: Test different ad positions
- Content Strategy: Create content around popular races
- SEO: Optimize for cycling-related keywords
- Social Media: Share race summaries to increase traffic
Remember: Always prioritize user experience over ad revenue. Too many ads can hurt your site’s credibility and performance.