我的团队正在开发一套工具和页面,需要谷歌分析才能让我们进行分析。我们的团队有一个Google Analytics帐户,用于收集我们现在使用过的数据。
最近,我们必须将我们的网站与另一个网站的另一个存储库相结合。因此,我们的分析已停止向我们的分析帐户发送数据。而是将数据发送到其他团队的帐户。他们使用的框架将某些代码注入网站的所有页面。
我们希望将我们的活动数据发送到我们的帐户,并弄清楚如何正确地将我们的分析对象与他们的分析对象分开。下面的代码是我们想要更改的示例,以便允许与2个不同的帐户进行通信。任何帮助是极大的赞赏。
{{1}}
答案 0 :(得分:5)
此页面上的两个现有答案不正确,实际上无效。您绝对不需要两次下载analytics.js
脚本,并且您绝对不想要创建两个command queue函数。
您要做的是创建两个tracker objects,至少给其中一个命名,然后使用两者发送数据。
以下是一个例子:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
// Creates the first tracker for one of your accounts,
// and uses the default name.
ga('create', 'UA-XXXXX-1', 'auto');
// Creates the second tracker for the other account,
// and give it the name "secondary"
ga('create', 'UA-XXXXX-2', 'auto', 'secondary');
// Sends events from both trackers,
// i.e. one event hit will be sent to each account.
ga('send', 'event', 'MyAnalytics', 'MyEvent');
ga('secondary.send', 'event', 'TheirAnalytics', 'TheirEvent');
</script>
有关详细信息,请查看working with multiple trackers和using named trackers上的文档。
答案 1 :(得分:-1)
将上一个ga2('send', 'event', 'MyAnalytics', 'MyEvent');
更改为 import java.io.*;
public class PracticeWriter
{
public static void main(String[] args) {
System.out.println("Method 1");
PrintWriter writer = new PrintWriter(System.out,true);
writer.println("Method 2");
}
}
并使用true