什么是 `js` gtags.js 命令?

What is the `js` gtags.js command?

Google Analytics 的嵌入代码(好吧,GA 通过 google 标签管理器的 gtags.js)看起来像:

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

    gtag('config', 'REDACTED');
</script>

我正在构建一个 SPA 应用程序,我想知道我需要什么来进行虚拟网页浏览 - Google 的文档遗漏了有关 js 命令的任何内容,并且我不想不遗余力...

  1. gtag('js', new Date()); 行在做什么?
  2. 如果我在代码段中告诉 config 命令不要注册综合浏览量,然后稍后调用 gtags('config', 'REDACTED', {...})(在 {...} 中包含页面信息),我是否需要在配置调用之前执行 gtag('js', new Date());?

这是 gtag JavaScript 文件中的相关代码:

js: function(a) {
    if (2 == a.length && a[1].getTime) return {
        event: "gtm.js",
        "gtm.start": a[1].getTime()
    }
}

这似乎是一个 init 函数 - 它检查某种命令数组是否存在并具有预期的长度(可能是为了确保它之前没有被初始化)然后发出 gtm.js事件和时间戳(a[1].getTime 通过测试 getTime 方法检查传入的 Date 对象)。

所以它可能对运行它多次既无害也无益(因为它只会return一个值一次)。