Home

gtagjs

gtag.js, short for Global Site Tag, is Google's unified tagging framework for websites. It provides a single tag to implement and configure Google Analytics, Google Ads, and other Google marketing products. The goal is to simplify tagging by standardizing data collection across services and reducing the number of separate tags a site must manage.

The library loads asynchronously from Google's servers and uses a dataLayer array to store commands and data.

Typical usage involves including the gtag.js script in the page and issuing configuration calls, for example

gtag.js is the recommended tagging method for new implementations and it supersedes older tagging approaches like

When
a
page
loads,
gtag.js
creates
a
global
gtag
function
that
pushes
instructions
into
the
dataLayer.
Google
services
read
those
instructions
to
initialize
properties,
configure
tracking,
and
log
events,
enabling
consistent
event
measurement
across
linked
products.
gtag('js',
new
Date());
gtag('config',
'GA_MEASUREMENT_ID');
Additional
options
can
customize
behavior,
such
as
sending
page
views
or
setting
user
properties.
GA4
property
IDs
begin
with
G-
(for
example,
G-XXXXXXX),
while
Universal
Analytics
properties
use
IDs
that
begin
with
UA-.
analytics.js.
It
supports
multiple
Google
products
from
a
single
tag
and
can
manage
configurations
for
both
GA4
and
UA
properties,
though
Google
encourages
migration
toward
GA4-focused
configurations.
Throughout
its
use,
developers
should
consider
privacy,
consent,
and
compliance
requirements,
and
debugging
tools
such
as
browser
consoles
or
Google’s
Tag
Assistant
to
verify
proper
data
collection.