What Is a Tracking Code? Placement and How to Verify It in GA4

July 24, 2026

Author: Shusaku Yosa
トラッキングコードとは?設置位置とGA4での確認方法を解説

To analyze how your website is performing, you first need to install a tracking code correctly. Yet many people are unsure what a tracking code actually is, where it should be placed, or how to confirm that it is working. This article explains the basics of tracking codes, the correct placement, and how to verify that they are firing using GA4 (Google Analytics 4).

What Is a Tracking Code?

A tracking code is a short program (script) installed in the HTML of a website in order to measure and collect access data such as visitor counts, page views, and traffic sources. It generally refers to the code issued by analytics tools such as Google Analytics or Google Tag Manager, and it is sometimes called a measurement tag or analytics tag.

By embedding this code in your pages, data is sent from the visitor's browser to the tool's servers when they visit your site, allowing you to review access data in the admin interface. If the tracking code is not installed, or is not working correctly, no access data will be recorded for that page at all.

Tracking Code vs. Tracking ID

A common point of confusion is the difference from a tracking ID. A tracking ID is a unique number that identifies which measurement target (property) the data should be sent to. A tracking code, on the other hand, is the entire script that contains that ID and actually carries out the measurement process. In short, the ID is the destination, while the code is the whole mechanism that includes that destination.

Note that in GA4, the older UA-style tracking IDs beginning with "UA-" have been replaced by Measurement IDs beginning with "G-".

Main Types of Tracking Codes

The tracking codes used on websites mainly fall into the following types.

  • gtag.js (Global Site Tag): a method of installing the GA4 measurement code directly in your HTML. Easy to set up.
  • Google Tag Manager (GTM): a system for managing multiple tags in one place. GA4 tags can also be deployed through GTM.
  • Advertising and other tool tags: conversion tags for Google Ads, pixels for social media advertising, and other purpose-specific tracking codes.

In a current GA4 environment, the mainstream approaches are either installing gtag.js directly or deploying it through GTM. From a management and scalability standpoint, GTM is recommended when you are handling multiple tags.

Where to Place a Tracking Code

If a tracking code is placed in the wrong location, it may fail to measure correctly or negatively affect page load speed. It is worth understanding the basic placement rules.

As High as Possible Within the head Element

As a rule, the GA4 gtag.js snippet and the GTM snippet should be placed inside the HTML head element, as close to the top as possible. Executing the code early in the page load process helps prevent measurement gaps even when a user leaves immediately. Google's official guidance also recommends placing the code right after the opening head tag.

GTM Requires Two Locations: head and body

When using Google Tag Manager, the two snippets it issues must each be placed in their designated positions.

  • First snippet: place it as high as possible within the head element.
  • Second snippet (noscript): place it immediately after the opening body tag. It serves as a fallback for environments where JavaScript is disabled.

Install It on Every Page Without Exception

The tracking code must be installed on every page you want to measure. If the code is missing from certain pages, no data will be collected for them and your site-wide figures will diverge from reality. In most CMS platforms, installing it once in a shared header template applies it to all pages, but standalone landing pages are especially prone to being missed, so take extra care.

How to Install the GA4 Tracking Code

Here is the basic flow for installing the GA4 tracking code (gtag.js) directly. For more detailed installation steps including GTM, please also refer to our separate article on GA4 tag setup.

  1. In the GA4 admin interface, open the target property and select the relevant web stream under "Data streams."
  2. On the stream details screen, open "View tag instructions" and choose the "Install manually" tab.
  3. Copy the entire gtag.js code that is displayed.
  4. Paste the code inside the head element of every page on your site, as high up as possible.
  5. Save and publish your changes, then confirm that the code is reflected on the live pages.

How to Verify a Tracking Code in GA4

After installation, always confirm that the tracking code is working. GA4 provides features that let you verify data transmission in real time.

Check the Realtime Report

The easiest verification method is the Realtime report. While visiting the target site from your own smartphone or a different browser, open "Reports" and then "Realtime" in GA4. If your own visit appears among the active users from the past 30 minutes, the tracking code is working correctly.

Use DebugView for Detailed Verification

When you want to verify individual events in detail, use DebugView. By enabling the "Google Analytics Debugger" browser extension or using GTM's preview mode, you can confirm in real time whether your actions are reaching GA4 as events. This lets you check whether page views, clicks, and other interactions are being recorded as intended.

What to Check When Nothing Is Being Measured

If your own visit does not appear in the Realtime report, check the following points.

  • Whether the Measurement ID (beginning with G-) is set correctly within the code
  • Whether the code is pasted correctly inside the head element and no tags are truncated
  • Whether the code is actually reflected on the pages you want to measure (no missing installations)
  • Whether your own visits are being filtered out by an ad blocker or IP exclusion settings

Summary

A tracking code is the foundational mechanism for measuring access data on a website. As a rule, place the code issued by GA4 or GTM inside the head element of every page, as high up as possible, and always verify its behavior afterward using the Realtime report or DebugView. Installing and validating it correctly is what makes site improvements based on reliable data possible. Start by checking whether your own visit is being measured in the Realtime report.

Related posts