【问题标题】:Multiple experiments with google analytics api谷歌分析 api 的多次实验
【发布时间】:2014-07-16 09:01:47
【问题描述】:

我们使用分析 api 下载实验和变体,并在我们端为访问者进行变体选择(即此处描述的服务器端实验:https://developers.google.com/analytics/solutions/experiments-server-side

当访问者访问一个正在试验的网址并且他们有一个选定的变体时,他们会得到如下描述的 javascript:

<script>
cxApi.setChosenVariation(1, 'a9BcDEFgHijKl8mON-Opqw');
</script>

这工作正常。我们希望运行多个实验(例如,一个涉及菜单的站点范围的实验,以及一个特定于页面的实验),变体选择和一切都可以正常运行。对于用户来说,当他们参与多个实验时,他们会多次调用 setChosenVariation,如下所示:

<script>
cxApi.setChosenVariation(1, 'a1BcDEFgHijKl2mON-3pqr');
cxApi.setChosenVariation(1, 'z9YxWVVuTsrPl8oNM-7lkj');
</script>

我找不到这不起作用的任何原因,但在实验结果中,发生这种情况时,我们看到所有用户只分配到一个实验,尽管两个实验都有结果(创造转化率>100%)。

是否有对这种行为的解释(我觉得第二次调用可能会覆盖第一次调用?)和/或正确的方法?

非常感谢

【问题讨论】:

    标签: javascript google-analytics google-experiments


    【解决方案1】:

    轻松回答对我不起作用。感谢Google Analytics Debugger 扩展,我可以看到ga('send','pageview') 都在发送有关第二次实验的数据。使用synchronous call 有效,我最终得到了类似的结果:

    var sendExperiment = function(tracker, experimentVar, experimentId) {
      cxApi.setChosenVariation(experimentVar, experimentId);
      tracker.send('event', 'experiment', 'view',{'nonInteraction': 1});
    }
    
    ga(function(tracker) {
     sendExperiment(tracker, 1, 'a1BcDEFgHijKl2mON-3pqr');
     sendExperiment(tracker, 2, 'z9YxWVVuTsrPl8oNM-7lkj');
    });
    

    【讨论】:

    • 我们现在已经离开了 GA(Ease 的回答也对我们不起作用)。这个答案看起来不错,但我无法测试它
    • 谢谢!我知道这是一个非常古老的问题,但我花了很多时间寻找答案却没有运气,所以我还是决定发布我的结果。
    • 我不认为这实际上被称为同步。你得到的实际上是两个异步调用,实验参数设置不同。
    【解决方案2】:

    我认为,当您在每个实验下设置选定的变体时,您应该将实验值发送到 Google Analytics(分析)。 代码如下:

    cxApi.setChosenVariation(1, 'a1BcDEFgHijKl2mON-3pqr'); 
    ga('send', 'pageview');
    cxApi.setChosenVariation(1, 'z9YxWVVuTsrPl8oNM-7lkj'); 
    ga('send', 'pageview');
    

    【讨论】:

      【解决方案3】:

      我意识到这是一个老问题,但我最近也不得不为这个问题想出一个解决方案,并认为我会与一些现实世界的限制分享我的方法。

      在高层次上,我的方法是这样工作的:

      1. 加载 Google Content Experiments API 代码
      2. 设置 Analytics 并创建第二个跟踪器(用于同一配置文件),该跟踪器仅用于跟踪我正在运行的第二个并发实验。
      3. 对我的常规 GA 代码进行任何自定义。
      4. 创建一个函数来检查用户当前所在的页面是否是我正在运行给定测试的页面,如果是,则为该特定实验的用户找到选择的变体,执行它并将信息发送回具有自定义事件的相关 GA 跟踪器。

      不幸的是,我不得不采用这种方法,因为我正在使用的平台只允许我对全局标题进行编辑,而不是任何类型的页面特定基础。所以正如我提到的,它只是根据我正在运行测试的 URL 检查规范 URL 标记。

      <!-- Load the regular Content Experiments JS API without any ID parameters -->
      <script src="//www.google-analytics.com/cx/api.js"></script>
      
      <!-- Setup Google Analytics -->
      <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');
      
        // Create the first regular tracker like you normaly would
        ga('create', 'UA-XXXXXXXX-1', 'auto', {'allowLinker': true, 'siteSpeedSampleRate': 90});
        // Create the second named tracker just for experiments
        ga('create', 'UA-XXXXXXXX-1', 'auto', 'experimentTracker');
      
        //Setup all of the regular customizations for the regular tracker if you need to
        ga('require', 'linker');
        ga('require', 'linkid', 'linkid.js');
        ga('require', 'ec');
        ga('require', 'displayfeatures');
        ga('linker:autoLink', ['example.com','domain2.com'], false, true);
      
        // Send the pageview like normal for the regular tracker
        ga('send', 'pageview');
      </script>
      
      <script>
        // Define the different experiments you wish to run and the page
      	var experimentOneID = "a1BcDEFgHijKl2mON-3pqr";
      	var	experimentTwoID = "z9YxWVVuTsrPl8oNM-7lkj";
      	var experimentOneURL = "http://www.example.com/experiment-1/";
      	var experimentTwoURL = "http://www.example.com/experiment-2/";
      
        var runContentExperiment = function(experimentID) {
          // Ask Google Analytics which variation to show the user and specify the experiment ID.
          var chosenVariation = cxApi.chooseVariation(experimentID);
          // Set the chosen variation for GA
          cxApi.setChosenVariation(chosenVariation, experimentID);
      
          // Here is where we have the page specific code changes you might want to make
          if (experimentID === experimentOneID) {
            var pageVariations = [
              function() {},  // Original: Do nothing. This will render the default HTML.
              function() {    // Variation 1 of Experiment 1
                // Do Something here in experiment 1
              }
            ];
            pageVariations[chosenVariation]
            ga('send', 'event', 'Content Experiment', 'View', experimentID, { 'nonInteraction': 1 });
          }
          else if (experimentID === experimentTwoID) {
            var pageVariations = [
              function() {},  // Original: Do nothing. This will render the default HTML.
              function() {    // Variation 1 of Experiment 2
                // Do Something here in experiment 2
              },
              function() { // Variation 2 of Experiment 2
      
              }
            ];
            pageVariations[chosenVariation]
            ga('experimentTracker.send', 'event', 'Content Experiment', 'View', experimentID, { 'nonInteraction': 1 });
          }
        }
      
        // Check the canonical URL of the page and make sure it matches the one we want
        var canonical = document.querySelector("link[rel='canonical']").href;
        if (canonical === experimentOneURL) {
          $(function() {
            runContentExperiment(experimentOneID);
          });
        } 
        else if (canonical === experimentTwoURL) {
          $(function() {
            runContentExperiment(experimentTwoID);
          });
        } 
      </script>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-09
        • 2016-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多