Search
Clear search
Close search
Google apps
Main menu
true

Set up Analytics tracking with gtag.js

gtag.js is the web tagging library that works for Google's site measurement, conversion tracking, and remarketing products – giving you better control while making implementation easier. By using gtag.js, you will be able to benefit from the latest dynamic features and integrations as they become available.

In this article:

Basic instructions

  1. If you have not already done so, create a property in Google Analytics. Create one Analytics property for each website you want to track. Creating a property generates a tracking ID, which you'll use in your gtag.js tracking code snippet.
  2. Find your tracking ID, as described below. You'll use this tracking ID in the tracking code snippet.
  3. Copy and paste the gtag.js tracking code snippet to each web page you want to track. Add the tracking code snippet right after the opening <head> tag on each page.

Find your tracking ID

To find the tracking ID:

  1. Sign in to your Analytics account.
  2. Click Admin.
  3. Select an account from the menu in the ACCOUNT column.
  4. Select a property from the menu in the PROPERTY column.
  5. Under PROPERTY, click Tracking Info > Tracking Code. Your tracking ID is displayed at the top of the page.

Tracking code snippet

Paste the following snippet right after the <head> tag on each page of your site. Replace GA_TRACKING_ID with your own Google Analytics tracking ID:

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

Verify that the tracking code is working

To verify that the tracking code is working, visit your website and check to see that your visit is being registered in the Real-Time reports.

gtag.js Developer Guide

Was this article helpful?
How can we improve it?
Google Analytics training and support resources

Check out our comprehensive list to learn more about Analytics solutions.