Sub topic 3
What the Google Tag Is and What It Does
This chapter assumes you understand the basics of users, sessions, and events. You also need access to a GA4 web data stream and the ability to edit your site's HTML or its tag-management settings.
The Google tag connects your site to GA4
The Google tag is Google's website tagging system. It is a small piece of code that loads on your pages and sends information to Google services, such as Google Analytics 4 and Google Ads.
For GA4, the tag sends data to a web data stream in a GA4 property. The stream has a Measurement ID, such as G-XXXXXXXXXX. This ID tells the tag where to send the data. A Measurement ID is an identifier, not a password, so it can appear in your page source.
The Google tag normally sends a page_view event when a page loads. It can also send other events, such as clicks, form submissions, purchases, and custom events. The information sent with an event can include the page URL, page title, referrer, device details, and event parameters.
gtag.js and the Google tag
gtag.js is the JavaScript library and programming interface used to configure the Google tag and send commands. The Google tag is the tagging system; gtag.js is one way your page communicates with that system.
A basic installation looks like this:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>Replace both instances of G-XXXXXXXXXX with the Measurement ID for your web data stream. Place the snippet as high in the <head> section as your site allows. The async attribute lets the browser download the library without blocking the rest of the page.
The first commands create a dataLayer array and define the gtag function. The data layer is a queue in the browser. Commands go into this queue so the Google tag can process them when its library is ready.
The config command initializes the tag for a destination. In this example, the destination is the GA4 web data stream. Unless you change the configuration, this command also causes the initial page view to be sent.
Google Tag Manager is a different installation route
Google Tag Manager, or GTM, is a system for managing tags from a web interface. It can load the Google tag without requiring you to add each tracking change directly to your site's HTML.
The Google tag and GTM are related, but they are not the same thing:
| Item | Role |
|---|---|
| Google tag | Collects and routes data to Google destinations |
| `gtag.js` | JavaScript library and command interface for the Google tag |
| Google Tag Manager | Container system that deploys and manages tags |
With a direct installation, your page contains the gtag.js snippet. With GTM, your page contains the GTM container snippet, and the container deploys a Google tag configuration. Do not use both routes for the same GA4 stream unless you have deliberately configured them to avoid duplicate events.
Configuration controls behavior
The Google tag can receive configuration options. For example, you can enable debug mode while testing:
gtag('config', 'G-XXXXXXXXXX', {
debug_mode: true
});Events sent with debug mode enabled can appear in GA4 DebugView. Remove or disable this option after testing unless you have a specific reason to keep it.
Other settings control page-view behavior, cross-domain measurement, cookie behavior, and consent handling. Consent defaults must be established before the configuration command when your privacy requirements require storage to be denied initially.
Know what one tag should send
A common error is adding the same GA4 configuration through a platform plugin, a manually pasted snippet, and GTM. Each copy may send its own page_view event. The result is inflated page views and possibly duplicate conversions.
Choose one primary installation route for the web stream. Keep event definitions in one controlled location when possible. If a platform integration already inserts the Google tag, do not paste a second copy into the theme without checking the integration settings.
Exercise
A site already uses a platform's GA4 integration. You also find a gtag.js snippet in the site's HTML. What should you check first?
Show answer
Check whether both installations use the same Measurement ID and whether both send the initial page view. Remove or disable one route if they duplicate the Google tag or its events.