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:

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

  analytics('config', 'TRACKING_ID');
</script>