gtag.js (Global Site Tag) is a Google JavaScript library that makes it easier to integrate and manage various Google services on a website—particularly Google Analytics, Google Ads, and other marketing and analytics tools.
gtag.js provides a single tracking code for centrally capturing events, page views and conversions . Website owners can define interactions directly in the code without having to add multiple separate tracking scripts.
Typical functions of gtag.js:
- Tracking page views
- Sending custom events (e.g. clicks and downloads)
- Setting up Conversion tracking
- Connecting multiple Google services through a single code snippet
gtag.js is Google's recommended implementation method for newer services and replaces older libraries such as analytics.js and the classic Google Ads conversion tags.
Note: Instead of adding gtag.js directly, you can also use Google Tag Manager which provides greater flexibility for managing tags.