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 in the tracking snippet

To rename the global object, change gtag() in the tracking snippet 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 tracking snippet as follows:

<!-- 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 analytics(){dataLayer.push(arguments);}
  analytics('js', new Date());

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