Google Analytics 4 (GA4) is a free Google tool. It shows your blog’s visitors. You can see how many people come. You can see where they come from. You can also see which pages they read. Google Tag Manager (GTM) is a free tool too. It installs tracking code. Tracking code is small code that records visits. Tracking code like GA4 can be installed without editing your blog files. This tutorial installs both on a static blog. You only need to install once. The data flows right away.
Figure 1: The flow of installing GA4 and GTM on a static blog — from creating a property to seeing data in Realtime.
What You Need
- A Google account (free).
- A static blog that’s already online, for example on GitHub Pages.
- Access to edit your blog’s HTML files.
- A browser.
Step 1: Create a Google Analytics 4 Property
A property is a data container for one blog.
- Open analytics.google.com.
- Sign in with your Google account.
- Click Admin at the bottom left.
- Choose Create → Property.
- Fill in the property name with your blog’s name.
- Choose the Asia/Jakarta time zone and the IDR currency.
- Continue to the next step.
- Choose the Web platform.
- Fill in your blog’s URL. For example
https://username.github.io - Fill in the stream name.
- Click Create stream.
- Copy the Measurement ID that appears. A Measurement ID is the code that identifies your property. The code looks like
G-XXXXXXXXXX.
Tip: The Measurement ID on this blog is
G-E8PLTTEFKX. But that’s this blog’s ID. Use the ID from your own property. Don’t copy this example ID.
Step 2: Create a Google Tag Manager Container
A container is a settings container in GTM. One container is for one blog.
- Open tagmanager.google.com.
- Sign in with the same Google account.
- Click Create Account.
- Fill in the account name and container name with your blog’s name.
- Choose Target Platform Web.
- Click Create.
- Copy the Container ID that appears. A Container ID is the code that identifies your container. The code looks like
GTM-XXXXXXX.
Tip: The Container ID on this blog is
GTM-TKZ69BJN. Just like the Measurement ID, that’s an example from this blog. Use the Container ID from your own container.
Step 3: Install the Snippets on Every Page
There are three snippets to install on every HTML page of your blog. A snippet is a piece of code, ready to paste.
- Paste the GTM snippet right after the
<head>tag:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TKZ69BJN');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TKZ69BJN');</script>
<!-- End Google Tag Manager -->
- Paste the GTM noscript snippet right after the
<body>tag:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TKZ69BJN"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TKZ69BJN"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
- Paste the gtag.js snippet for GA4 inside
<head>, below the GTM snippet:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-E8PLTTEFKX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-E8PLTTEFKX');
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-E8PLTTEFKX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-E8PLTTEFKX');
</script>
Tip: Replace
G-E8PLTTEFKXwith your own Measurement ID. ReplaceGTM-TKZ69BJNwith your own Container ID. If your blog has many pages, the snippets must be on every page. A page without the snippets won’t record its visitors.
Step 4: Check the Data in Realtime
Realtime is a report of visitors right now.
- Save and upload all the HTML files you changed.
- Wait 1–2 minutes for your blog to update.
- Open analytics.google.com.
- Go into your property.
- Choose Reports → Realtime.
- Open your blog in another browser tab.
- Wait 1–2 minutes. The active users number in Realtime will change to 1. That means GA4 is already recording visits.
Figure 2: Check the data in Realtime — open the blog in another tab, and the active users number changes within 1–2 minutes.
Tip: Standard reports only appear 24–48 hours after installation. A standard report shows daily visitor counts and the most-read pages. Don’t panic if the regular reports are still empty on the first day. Check Realtime first.
Warning: Don’t install the GA4 tag inside GTM if you’ve already installed gtag.js directly, as in this tutorial. Both send the same pageview. A pageview is a record of one visit to one page. One visit would be counted twice.
If the Data Doesn’t Show Up
- Check the Measurement ID and Container ID. Make sure both are correct. Make sure both belong to your own property and container. Don’t use the examples from this tutorial.
- Check that the snippets are on every page. Open View Source in your browser (Ctrl+U). Search for
G-andGTM-. - Turn off your ad blocker while testing. An ad blocker is a tool that blocks ads. Some ad blockers block Google Analytics. No data gets sent.
- Wait a bit. A newly deployed blog needs 1–2 minutes before the new files show up. Realtime needs 1–2 minutes to display a visit.
Comments