Rename the gtag object

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

Rename the global object in the tracking snippet

To rename the global object, change gtag in the tracking snippet, and in all calls to another name.

For example, if you want to rename the gtag object to analytics, you need to change the tracking snippet as follows:

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

  analytics('config', 'GA_TRACKING_ID');