Take our developer survey. We want your feedback so we can learn how to improve Google Analytics, and make it an even better tool for you.

Rename the gtag object

In some cases you'd like to add gtag.js to your page, but gtag() is already being used for something else. gtag.js allows you rename the global gtag() object to avoid name conflicts.

Rename the global object

To rename the global object, change gtag() in the global site tag to another name. For any instances where gtag() is called in your code, be sure to rename them to match.

For example, to rename the gtag() object to analytics(), change the tag as follows:

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

  analytics('config', 'GA_MEASUREMENT_ID');