Add gtag.js to your site

The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform. This page describes how to use gtag.js to configure a site for Google Analytics tracking. For general (i.e. non-product specific) gtag.js documentation, read the gtag.js developer guide.

Install the global tracking snippet

To install the global tracking snippet, copy the following code and paste it immediately after the <head> tag on every page of your site. Replace GA_TRACKING_ID with the tracking ID of the Google Analytics property to which you want to send data. You need only one global snippet per page.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');

This snippet loads the gtag.js library, establishes GA_TRACKING_ID as the default Google Analytics property ID, and sends a pageview hit to Google Analytics.

Disable pageview tracking

The default behavior of this snippet is to send a pageview hit to Google Analytics. This is the desired behavior in most cases; pageviews are automatically tracked once you add the snippet to each page on your site. However, if you don’t want the snippet to send a pageview hit to Google Analytics, set the send_page_view parameter to false:

gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });

Configure additional Google Analytics properties

By default, the snippet configures a single Google Analytics property. To configure a second Google Analytics property with the tracking ID GA_TRACKING_ID_2, add an additional config command:

gtag('config', 'GA_TRACKING_ID_2');