How to Install the GA4 Tag | Step-by-Step Guide for GTM and gtag.js
Published:
Last Updated:
Category:
Published:
Last Updated:
Category:

Authors: Shusaku Yosa
To start collecting data in GA4 (Google Analytics 4), you first need to install the "GA4 tag" correctly on your website. There are two main ways to do this: embedding the Google tag (gtag.js) directly, or using Google Tag Manager (GTM). This article explains the steps for each method in a beginner-friendly way, and covers post-installation verification and key cautions.
The GA4 tag is the measurement code that sends your website's access data to GA4. The Google tag (gtag.js) lets you measure the performance of your website and ads simply by adding it once to your site, and it serves the role of sending data to Google Ads and GA4.
What was once called the "global site tag (gtag.js)" is now organized as an independent feature called the "Google tag." The fundamental approach is to set up the tag using the "Measurement ID" (an ID starting with G-) that is issued per GA4 data stream.
There are mainly two methods for installing the GA4 tag. Either method works for measurement, but they differ in how easy they are to operate.
The simplest approach is to paste the Google tag (gtag.js) code issued by GA4 directly onto your site.
Paste the copied tag immediately after the opening <head> tag on every page of your site. The code looks like the following (replace the G-XXXXXXX part with your own Measurement ID).
unknown nodeIf you use WordPress, pasting it inside the <head> of your theme's header.php, or using a dedicated plugin that lets you insert code into the header/footer, is safer because it is less affected by theme updates.
If you paste it in the wrong place, nothing will be measured. Always install the code immediately after the opening <head> tag.
If you want to manage multiple tags or handle event tracking flexibly, installing via GTM is recommended. GTM provides templates for GA4-related and ad tags, so you can basically add and edit tags with no code.
First, create a GTM account and container, then install the two issued snippets (one for <head> and one immediately after <body>) on all pages of your site. This is the foundation that makes GTM work.
It was previously called the "GA4 Configuration Tag," but since around September 2023 the configuration tag within GTM has been unified into the "Google Tag." Therefore, when changing measurement settings, you need to be conscious of whether you are doing it on the GA4 side or the Google Tag side.
If you're unsure, the deciding factor is your future scale of operation. If tags are limited to GA4 and you don't plan to add more, gtag.js is sufficient. On the other hand, if you plan to handle multiple tags such as Google Ads or event tracking, operating with GTM from the start makes management easier.
As an important caution, installing the GA4 tag with both gtag.js and GTM causes double measurement. When migrating to GTM, be sure to remove the gtag.js pasted directly into your HTML.
After installation, always verify that measurement is working properly. The typical verification methods are as follows.
If you installed the tag but no data is collected, the following causes are possible.
Installing the GA4 tag can be done in two ways: pasting gtag.js directly, or using GTM. If you prioritize simplicity, gtag.js is suitable; if you prioritize long-term operation and centralized tag management, GTM is suitable. With either method, always verify operation with the Realtime report or Tag Assistant after installation, and avoiding double measurement is the first step to accurate data collection. Choose the optimal installation method to match your site's operational policy.

A referral is a channel indicating traffic that arrives via a link on another website. This article explains its meaning...

A guide to using Tag Assistant, Google's official tag verification tool. Covers installation, checking tags in the side ...

A guide to checking traffic sources (source/medium) in GA4. Covers the difference between channel, source, and medium, h...