Universal Analytics (UA) 将于 2023 年 7 月 1 日弃用,这意味着它将停止处理数据。Analytics 360 媒体资源将于 2023 年 10 月 1 日停用。迁移到 Google Analytics(分析)4

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>