Published on October 15, 2025
Learn how to integrate Google Analytics with your GitHub Pages website to track visitor behavior, page views, and overall performance. This guide makes it easy to monitor your site’s traffic and gain valuable insights.
Step 1: Go to Google Analytics and create a new property for your website.
Step 2: Copy your unique Measurement ID (it looks like G-XXXXXXXXXX).
Step 3: In your <head> tag of every HTML page (or in your template), paste this code before the closing </head> tag:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
Step 4: Replace G-XXXXXXXXXX with your actual Google Analytics Measurement ID.
Step 5: Push the changes to GitHub Pages and verify your data in Google Analytics after 24–48 hours.
Screenshot placeholder: Google Analytics dashboard showing your site traffic
Tip: For faster updates, keep your analytics script in a shared header file if you use includes.