:bulb: This post explains how to apply Google Analytics (GA4) to a GitHub blog and track visitor statistics.

[01] What is Google Analytics?

A Web Analytics Service from Google that tracks and reports website traffic.

It lets you monitor visitor statistics for your blog.

[02] Setting Up Google Analytics

Sign Up and Create an Account

  • Visit the Google Analytics site to create an account and walk through setup.

    (link) google analytics

    01

  • The account name does not need to match your Google ID.

    02

  • Use the blog URL as the property name.
  • Set the reporting time zone and currency to your locale (e.g., Republic of Korea / KRW).

    03

  • Business information is optional (you can change it later).

    04

  • Accept the Terms of Service.

    05

  • Accepting the terms completes the initial setup.
  • To actually monitor traffic data, you need to configure a Data Stream and create a Measurement ID.
  • The Measurement ID is added to the GitHub Blog config file so Google Analytics can track the page.
  • Google Analytics currently runs as GA4 (Google Analytics 4) and uses IDs in the G-XXX format.
  • The previous version, UA (Google Analytics 3), used IDs in the UA-XXX format.

    When you search for how to set up Google Analytics, you’ll see many posts referencing the UA-XXX tracking ID. Since we created a Google Analytics 4 property above, methods built around UA-XXX won’t work correctly.

  • A GitHub Blog is a web property, so select Web as the platform. 06

  • Enter the blog URL as the Website URL; choose any Stream name you like. 07

  • Apply the Measurement ID (G-4DKPW49KWZ in the screenshot below) to the GitHub Blog. 08

GitHub Blog Configuration

Minimal Mistakes theme.

  • In _config.yml, set provider to google-gtag and add the measurement_id (create the field if it doesn’t exist) using the tracking ID above.

    18

  • Add the following line inside the <script> block in _includes/analytics-providers/google-gtag.html:

    1
    
    gtag('config', );
    

    10

[03] Verifying the Result

  • If everything is wired up, refresh the blog and check the Google Analytics home — the stats appear immediately.

    11