Add gtag.js to your site

The Global Site Tag (gtag.js) provides a framework for streamlined web page tagging – giving you better control while making implementation easier. By using gtag.js, you will be able to benefit from the latest tracking features and integrations as they become available.

Install the global tracking snippet

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

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');
</script>

After you put the global gtag.js snippet on your web page, you can use the config command to configure additional products. For example, if you need to configure a second Google Analytics property, you could add it as follows:

<script>
  gtag('config', 'GA_TRACKING_ID_2');
</script>

where GA_TRACKING_ID_2 is the property ID for the additional Google Analytics account.

If you don't want gtag.js to send the pageview automatically, set send_page_view to false:

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

Next step

Learn how to send data to Google Analytics.