Tracking snippet for Google Analytics

The Google Analytics tracking snippet is based on the gtag.js library:

<!-- 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>

The first line brings in the gtag.js library. The id parameter indicates that this gtag.js snippet is from a Google Analytics account:

<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>

The next few lines establish a dataLayer array, which is used by gtag.js to pass data back to Google Analytics or to other supported products, and sets up a timestamp:

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

The config command establishes the Google Analytics property "GA_TRACKING_ID" as the default property to receive event data, and sends the standard pageview data to that property:

gtag('config', 'GA_TRACKING_ID');