How to Install the GA4 Tag | Step-by-Step Guide for GTM and gtag.js

June 21, 2026

Author: Shusaku Yosa
GA4のタグ設置方法|GTM・gtag.js別の手順を解説

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.

What Is the GA4 Tag? The Basics You Should Know First

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 Two Ways to Install the GA4 Tag

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.

  • Installing gtag.js directly: A simple method where you paste the code inside the <head> of your HTML. Suited to small sites or cases where you don't plan to add more tags.
  • Using GTM (Google Tag Manager): A method that goes through a tool allowing centralized tag management. If you'll run multiple tags or event tracking, this is recommended in the long run.

[Method 1] Installing the GA4 Tag with gtag.js

The simplest approach is to paste the Google tag (gtag.js) code issued by GA4 directly onto your site.

STEP 1: Get Your Measurement ID and Tag Code

  1. In the GA4 admin screen, open "Admin" → "Data streams"
  2. Select the target web stream and check the Measurement ID (G-XXXXXXX)
  3. From "View tag instructions," copy the code snippet for manual installation

STEP 2: Paste the Tag Code Inside <head>

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 node

If 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.

[Method 2] Installing the GA4 Tag with GTM

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.

STEP 1: Install the GTM Container Tag on Your Site

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.

STEP 2: Create the Google Tag for GA4 Configuration

  1. In the GTM admin screen, click "Tags" → "New"
  2. Under "Tag Configuration," select "Google Tag"
  3. Enter your GA4 Measurement ID (G-XXXXXXX) in the "Tag ID" field
  4. Set the trigger to "All Pages"
  5. Name the tag and save

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.

STEP 3: Verify in Preview, Then Publish

  1. Use GTM's "Preview" mode to confirm the tag fires correctly
  2. If there are no problems, click "Publish" to reflect it in the production environment

GTM or gtag.js: Which Should You Choose?

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.

  • When gtag.js fits: Small sites, measurement limited to GA4, an environment where you can edit code directly
  • When GTM fits: Operating multiple tags, heavy use of event tracking, wanting non-engineers to manage tags
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.

How to Check Whether the GA4 Tag Is Working Correctly

After installation, always verify that measurement is working properly. The typical verification methods are as follows.

  • GA4 Realtime report: Access your own site, and if active users appear in the Realtime report, measurement is working.
  • Google Tag Assistant: You can diagnose whether the tag fires correctly and whether there are any errors.
  • GTM Preview mode: If you use GTM, you can check the tag firing status on a per-page basis.

Common Causes When Data Cannot Be Measured

If you installed the tag but no data is collected, the following causes are possible.

  • A mistake in the Measurement ID (using an ID from a different stream)
  • The tag is installed in the wrong place (pasted outside <head>)
  • The tag is only on some pages
  • Interference from double installation of gtag.js and GTM
  • Forgetting to publish (in the case of GTM)

Conclusion

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.

Related posts