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

Published:
Last Updated:
Category: Web Analytics
Authors: Shusaku Yosa

Published:
Last Updated:
Category: Web Analytics
Authors: Shusaku Yosa
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).
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.
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-".
The tracking codes used on websites mainly fall into the following types.
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.
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 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.
When using Google Tag Manager, the two snippets it issues must each be placed in their designated positions.
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.
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.
After installation, always confirm that the tracking code is working. GA4 provides features that let you verify data transmission in real time.
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.
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.
If your own visit does not appear in the Realtime report, check the following points.
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.
A clear explanation of time on page and how it relates to GA4's average engagement time. Covers how to think about avera...

How to measure GA4 click events with GTM. Covers the step-by-step process from enabling built-in variables to creating t...

An explanation of Access Analysis Kenkyujo, a free, high-functionality Japanese access analysis tool. Covers features li...