How do I track multiple Google Optimize experiments in Google AMP?

China☆狼群 提交于 2020-08-26 06:10:20

问题


The amp-experiment docs demonstrate tracking multiple experiments in AMP. However, how do I configure the amp-analytics properly?

In the reporting section of the docs, it mentions a VARIANTS placeholder that will be replaced with a serialized list of experiment and variant names. This answer from the Google Optimize team seems to indicate that it could be added to requests in <amp-analytics> like so:

<amp-analytics type="googleanalytics">
  <script type="application/json">
    {
      "vars": {
        "account": "..."
      },
      "requests": {
        "experiment": "${pageview}&exp=VARIANTS"
      },
      "triggers": {
        "pageview": {
          "on": "visible",
          "request": "experiment"
        }
      }
    }
  </script>
</amp-analytics>

When I try this, though, Google Optimize doesn't register any visits. It seems to require that the experiment request include xid/xvar (for experiment ID/variant) instead:

<amp-analytics type="googleanalytics">
  <script type="application/json">
    {
      ...
      "requests": {
        "experiment": "${pageview}&xid=${xid}&xvar=${xvar}"  <-- modified
      },
      "triggers": {
        "pageview": {
          "on": "visible",
          "request": "experiment",
          "vars": {                                          <-- added
            "xid": "skdjEjia23_1ksjd",                       <-- 
            "xvar": "VARIANT(my-experiment-name)"            <-- 
          }                                                  <-- 
        }
      }
    }
  </script>
</amp-analytics>

This works fine, but then I can only run one experiment at a time, since the xid/xvar are hard-coded to a specific experiment.

Any ideas how I can run multiple experiments?


回答1:


OK, I figured it out. I got an answer from the Google Optimize team in the Google Optimize forum.

The VARIANTS variable gets replaced with serialized experiment names and variants, but what Google Analytics apparently needs is experiment IDs and variants. Thus, the correct solution was to configure <amp-analytics> this way:

<amp-analytics type="googleanalytics">
  <script type="application/json">
    {
      "vars": {
        "account": "..."
      },
      "requests": {
        "experiment": "${pageview}&exp=a1b2c3.VARIANT(my-first-experiment)!d4e5f6.VARIANT(my-second-experiment)"
      },
      "triggers": {
        "pageview": {
          "on": "visible",
          "request": "experiment",
        }
      }
    }
  </script>
</amp-analytics>

Note that a1b2c3 and d4e5f6 are the experiment IDs, not the names. The .VARIANT(...) portions following them indicate the index of the variant selected for those experiments. No idea why the IDs are used in the first place and the names in the VARIANT() callbacks 🤷‍♂️



来源:https://stackoverflow.com/questions/51880387/how-do-i-track-multiple-google-optimize-experiments-in-google-amp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!