The Google tag is a single piece of JavaScript that sends data from your website to multiple Google products. Instead of managing separate tags for Google Analytics, Google Ads, and Floodlight, you add one snippet and connect it to your destinations.
This article explains what the Google tag does, what the code looks like, and how to configure events. You will find google analytics example code you can adapt, plus the exact steps to verify your setup.
The Google Tag In Plain Terms
The Google tag (sometimes called the gtag.js tag) is a unified measurement tag. Before it existed, you might have added a Google Analytics tracking code, a separate Google Ads conversion pixel, and a Floodlight tag. Now you add one base snippet to every page, and that single tag routes data to whichever Google products you choose.
Each Google tag has a tag ID. The ID is a string like G-XXXXXXXX, AW-YYYYYY, or GTM-XXXXXX. The prefix tells you which type of destination the ID represents:
| Prefix | ID type | Description |
|---|---|---|
GTM-XXXXXX | Google Tag Manager container ID (default) | Default for new installations. Supports all Google, third-party, and custom tags. |
G-XXXXXX | Destination-specific ID | Identifies a Google Analytics 4 measurement ID. Learn how to find yours. |
AW-XXXXXX | Destination-specific ID | Identifies a Google Ads conversion ID. |
DC-XXXXXX | Destination-specific ID | Identifies a Floodlight advertiser ID. |
GT-XXXXXX | Google tag ID | Identifies a Google tag created in prior versions. |
When you add the Google tag snippet to your site, you do not need to change the code every time you add a new product. Instead, you open the Google tag screen inside Google Analytics, Google Ads, or Campaign Manager 360 and connect additional destinations. The tag then sends data to all linked products automatically. For GA4 properties, the tag automatically records page views, outbound clicks, site search, and scrolls when you enable enhanced measurement.
All global site tags (the older gtag.js implementation) have been converted into Google tags. If your site still uses a global site tag, it already works as a Google tag without any update. You can manage user access to the tag settings separately from product access, so a developer can adjust measurement settings without gaining access to Google Ads reports.
What The Tag Snippet Contains
The Google tag snippet is two blocks of JavaScript placed in the <head> of every page. Here is a typical google analytics example code for a GA4 property:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXX');
</script>The first <script> tag loads the gtag.js library asynchronously from Google’s servers. The id parameter in the URL tells the library which tag ID to initialize. The second <script> block sets up a data layer array, defines the gtag() function, and then calls two commands: gtag('js', new Date()) timestamps the page load, and gtag('config', 'G-XXXXXXXX') tells the library to send data to the GA4 measurement ID.
By default, the config command triggers a page_view event for Google Analytics 4. If you want to prevent that automatic pageview, you can pass an extra parameter: gtag('config', 'G-XXXXXXXX', {'send_page_view': false});. This is useful when you track pageviews manually, for example in single-page applications.
You can add multiple config commands for different products. For instance, to also send data to a Google Ads account and a Floodlight configuration, you would add:
gtag('config', 'AW-YYYYYY');
gtag('config', 'DC-ZZZZZZ');Each config command can accept additional parameters that apply only to that destination. The snippet is the same whether you use a G-, AW-, or GTM- ID. To find your exact snippet, go to Admin > Data collection and modification > Data streams, click your web stream, click View tag instructions in the Google tag section at the bottom, then choose Install manually. Place the snippet as high in the <head> as possible. If you use a CMS, paste it into the theme's header template or the platform's designated custom code field.
Short on time? Analytics Art can check this in your property for you.
Settings On The Google Tag Screen
After the snippet is live, you manage the tag’s behavior through the Google tag screen. In Google Analytics 4, go to Admin > Data collection and modification > Data streams and click your web stream. Then click Configure tag settings. The screen displays your tag ID and a link to View tag instructions where you can copy the snippet.
This screen lets you adjust settings without editing the on-page code. The changes apply to all destinations connected to that Google tag. You can:
- Manage destinations: Link or unlink Google Ads, Floodlight, or other product accounts.
- Measure interactions automatically: Page views, clicks, scrolls and more can be measured in Google Analytics without extra code through enhanced measurement.
- Set up user consent: Set up and manage how the tag handles user consent. For a full walkthrough, see our Google Consent Mode v2 guide.
- Manage users: Grant or revoke access to the Google tag settings independently from the GA4 property. This lets you give a developer permission to adjust tag configuration without granting access to reports.
If you have multiple Google tags on the same site, you can combine them from this screen. Combining them helps you get better data and manage the tags in one place. Any change you make here updates the tag’s behavior across all pages that include the snippet. There is no need to redeploy code. The same Google tag screen is accessible inside Google Ads and Campaign Manager 360, so you can adjust measurement settings from whichever product you are working in.
Sending Events With The Google Tag
The config command establishes the data flow, but to record user actions you need the event command. Its format is:
gtag('event', 'event_name', {
'parameter1': 'value1',
'parameter2': 'value2'
});You can use recommended events (standardized names and parameters that GA4 recognises) or custom events (names and parameters you define). For example, a recommended purchase event expects specific parameters like currency, value, and items. A custom event like newsletter_signup can carry any key-value pairs you need.
Here is a google analytics code sample that sends a custom event when a button is clicked:
<script>
function newsletterSignup() {
gtag('event', 'newsletter_signup', {
'time': Date.now()
});
}
</script>
<button onclick="newsletterSignup()">Sign me up!</button>Events are sent to every destination you configured with config. If you want an event to go only to a specific destination, include the send_to parameter with the target ID.
Parameters can be scoped at three levels: event, config, and global (set). An event-level parameter overrides a config-level one, which overrides a global one. For instance, if you set a global campaign name with gtag('set', {'campaign_name': 'Spring Sale'}), but later pass a different campaign name in a specific event, the event’s value wins.
To attach a parameter to every subsequent event on the page, use the set command:
gtag('set', {'campaign_id': '1234'});The consent command controls how tags behave based on user consent. You can set default consent states and update them after the user makes a choice. For example:
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied'
});After setup, validate that events are firing correctly by checking the Realtime report in GA4 or using Google Tag Assistant. For more event examples, see the gtag.js configure documentation.
Google Tag Vs Tag Manager
People often confuse the Google tag (gtag.js) with Google Tag Manager (GTM). They solve different problems.
The Google tag is a JavaScript library you add directly to your website’s code. It sends data to Google products and lets you control measurement settings from the Google tag screen. You write a few lines of JavaScript to send events, and you can manage destinations without touching the code again.
Google Tag Manager is a container that loads tags dynamically through a web interface. Instead of hard-coding every tracking snippet, you install the GTM container once and then add, edit, or remove tags (Google Analytics, Google Ads, Facebook, custom HTML, etc.) from the GTM dashboard. GTM also provides a data layer, triggers, and variables for advanced control.
Here is a quick comparison:
| Feature | Google tag (gtag.js) | Google Tag Manager |
|---|---|---|
| Installation | Add the snippet to every page manually or via CMS | Add the GTM container snippet to every page |
| Tag management | Edit settings in the Google tag screen; add events in code | Add and configure tags through the GTM web interface |
| Third-party tags | Google products only (GA4, Ads, Floodlight, etc.) | Any tag (Google, Facebook, LinkedIn, custom HTML) |
| Data layer | Uses a simple array; you push events with gtag() | Full data layer with variables and triggers |
| Version control | Code changes follow your own release process; tag screen settings need no code change | Workspaces, versions, and publishing controls |
In practice, many sites use both. The Google tag snippet can load a GTM container when you use a GTM-XXXXXX ID. Inside the container, you then use Google Analytics: GA4 Event tags to send events. This hybrid approach gives you the flexibility of GTM’s interface while still benefiting from the unified Google tag infrastructure.
If you only need Google products and are comfortable editing site code, the standalone Google tag is simpler. If you plan to add many third-party pixels or need a no-code way to manage triggers, use Google Tag Manager. You can learn more about setting up GA4 with GTM in our GA4 and Google Tag Manager guide.
Frequently Asked Questions
What Is A Google Analytics Tag?
A Google Analytics tag is the JavaScript snippet that sends data from your website to Google Analytics. In GA4, this tag is part of the broader Google tag, which can also send data to Google Ads and Floodlight. The tag ID usually starts with "G-" and is placed on every page.
Where Should You Paste The Google Tag Snippet?
Paste the Google tag snippet in the <head> section of every page on your site, as high as possible. If you use a CMS like WordPress or Shopify, add it to the theme’s header file or a dedicated custom code field. The snippet must load before any event calls.
How Does The Google Tag Work?
The Google tag loads the gtag.js library and initializes a data layer. You use the config command to connect to destinations like GA4 or Google Ads. When events occur, the event command sends data to all connected destinations. Settings are managed through the Google tag screen in GA4 or Google Ads.
What Are The Key Differences Between gtag.js And Google Tag Manager?
gtag.js is a JavaScript library you add directly to your site to send data to Google products. Google Tag Manager is a container that loads and manages multiple tags through a web interface, without editing site code. GTM supports third-party tags and offers version control.
How Do I Send Events With The Google Tag?
Use the gtag('event', 'event_name', {parameters}) command. You can use recommended events with predefined names and parameters, or create custom events. Call the function when a user action occurs, such as a button click. The event is sent to all destinations you configured.
How Can I Verify My Google Tag Is Working?
Use Google Tag Assistant at tagassistant.google.com. Enter your website URL, and it will show which tags are detected and what events they fire. In GA4, you can also check the Realtime report to see if events appear within seconds.
Related GA4 Guides
- Where To Find Your GA4 Measurement ID (G-XXXXXXX)Learn where to find your GA4 measurement ID in the Admin panel, how it differs from property and UA IDs, and where to paste it for GTM, WordPress, Shopify, and gtag.js.
- How To Use Google Tag Assistant To Test GA4 TagsLearn how to use Google Tag Assistant to debug your GA4 tags, check events, and fix connection issues. Step-by-step guide with screenshots.
- How To Add Google Analytics To Your WebsiteAdd Google Analytics 4 to your website: create a property, copy a measurement ID, and install the Google tag. Step-by-step guide for direct, GTM, or CMS installation.
- Google Analytics Admin: Every Setting And Where To Find ItFind every GA4 Admin setting with exact click paths. Learn where to manage accounts, properties, data streams, product links, and user access in Google Analytics.
- How To Add Users To Google Analytics 4Learn how to add users to Google Analytics 4 step by step. Understand roles, data restrictions, and account vs property access. Manage your GA4 users securely.
More in Setup & Tags or browse all GA4 guides.