将事件发送到两个单独的 google 分析帐户?

Send events to two separate google analytics accounts?

是否可以将跟踪事件发送到两个单独的 google 分析帐户?

当然可以。请确保每个帐户都有自己的跟踪 ID。然后,类似于以下内容(当然包括分析代码之后):

ga('create', trackingId1, window.location.hostname);
ga('send', 'pageview');

ga('create', trackingId2, 'auto', {'name': 'secondAccount'});
ga('secondAccount.send', 'pageview');

我确定 Google 上有这方面的文档,但 Analytics 文档有点像噩梦。

只是为了详细说明斯蒂芬的回答。

  • 是的,在大多数情况下您当然可以设置多个 Google 分析跟踪器,然后发送您想要的任何点击给其中一个或两个。
  • 可能导致您出现问题的情况 - 当您没有严格使用 analytics.js 代码时。 (你有一些挥之不去的ga.js)

使用 analytics.js,事情应该如您所愿,但是使用 ga.js,有 some precautions 需要注意/注意。

Not all configurations are supported. You can, for example, install multiple instances of the Universal Analytics tracking code (analytics.js) on your web pages but only one instance of the Classic Analytics code (ga.js). Multiple instances of ga.js might result in inaccurate data collection, processing, or reporting. You can, however, install one or more instances of analytics.js on web pages that also have a single instance of ga.js.

当您创建多个跟踪器时,请务必确保为其他跟踪器设置 'name',正如 Stephen 的回复中所展示的那样。您可以像这样使用 Stephen 的方法:

ga('create', trackingId2, 'auto', {'name': 'secondAccount'});

或通过将其作为 'create' 中的第四个参数来设置名称,如下所示:

ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');

Stephen 代码重要部分的简短解释:

当为某个跟踪器发送命令时,您在命令名称前加上跟踪器名称,​​后跟一个点。如果您不指定跟踪器名称,​​则默认跟踪器上的命令是 运行。

如果您想了解特定问题范围之外的更多信息,请参阅 Creating Multiple Trackers 上 analytics.js 文档的 link。