How to Install Google Analytics 4 and Tag Manager on a Static Blog
Home > Tutorial > How to Install Google Analytics 4 and Tag Manager on a Static Blog
Archive
- Installing Apache, MySQL, PHP, and phpMyAdmin on Arch Linux 2021
- Configuring an Apache Virtual Host on Arch Linux Jun 12, 2021
- How to Deploy a Static Blog to GitHub Pages Nov 17, 2026
- How to Sign Up for make.fun with an Agent Nov 17, 2026
- How to Hunt Bug Bounties with Agentic-Bug-Hunter Nov 18, 2026
- How to Install Google Analytics 4 and Tag Manager on a Static Blog Nov 26, 2026
- How to Optimize SEO for a GitHub Pages Blog Nov 26, 2026
- How to Join make.fun Bounties with an AI Agent Nov 26, 2026
- How to Build a Tank Bot on battle.training Nov 26, 2026
- How to Make a Bootable Ventoy USB Nov 26, 2026
- How to Mint Free NFTs on BSC Safely Nov 30, 2026
- How to Make Automated Story YouTube Shorts (Stickman + TTS) Nov 30, 2026
Google Analytics 4 (GA4) is a free Google tool for seeing your blog's visitors: how many people come, where they come from, and which pages they read. Google Tag Manager (GTM) is a free tool for installing tracking code like GA4 without having to edit your blog files every time. This tutorial installs both on a static blog — install once, and 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
Open analytics.google.com and sign in with your Google account. Click Admin at the bottom left, then choose Create → Property. Fill in the property name (your blog's name, for example), choose the Asia/Jakarta time zone and the IDR currency, then continue. Choose the Web platform, fill in your blog's URL (for example
https://username.github.io) and the stream name, then click Create stream. After that you'll see your Measurement ID — the code looks like G-XXXXXXXXXX. Copy it and save it for now.
Tip: The Measurement ID on this blog is
G-E8PLTTEFKX — but that's this blog's ID. You must use the ID from your own property; don't copy this example ID.
Step 2: Create a Google Tag Manager Container
Open tagmanager.google.com and sign in with the same Google account. Click Create Account, fill in the account name and container name (your blog's name, for example), choose Target Platform Web, then click Create. Once the container is created, you'll see your Container ID — the code looks like
GTM-XXXXXXX. Copy it and save it.
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. First, the GTM snippet — paste it 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 -->
<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 -->
Second, the GTM noscript snippet — paste it 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) -->
<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) -->
Third, the gtag.js snippet for GA4 — paste it inside
<head> too, 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>
<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-E8PLTTEFKX with your own Measurement ID, and GTM-TKZ69BJN with 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
Save and upload all the HTML files you changed, then wait 1–2 minutes for your blog to update. Open analytics.google.com, go into your property, then choose Reports → Realtime. Open your blog in another browser tab — within 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 such as daily visitor counts and the most-read pages only appear 24–48 hours after installation. So 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, so 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 and belong to your own property/container, not the examples from this tutorial.
- Check that the snippets are on every page — open View Source in your browser (Ctrl+U) and search for
G- and GTM-.
- Turn off your ad blocker while testing — some ad blockers block Google Analytics, so no data gets sent.
- Wait a bit — a newly deployed blog needs 1–2 minutes before the new files show up, and Realtime needs 1–2 minutes to display a visit.
References
- https://support.google.com/analytics/answer/9304153
- https://support.google.com/tagmanager/answer/6103696
Like this tutorial? Support the author so there are more free tutorials.
Support via Saweria
Comments