1

我正在尝试从 AMP 页面向 Google Analytics 发送自定义页面名称(页面 url)。通常我会像这样发送自定义页面名称:

ga('send', 'pageview', {'page': 'myPageName'});

但 amp-analytics 只能从此 JSON 代码自定义:

    <amp-analytics type="googleanalytics" id="analytics1">
      <script type="application/json">
      {
        "vars": {
          "account": "UA-664228-1"
        },

        "triggers": {

          "trackPageview": {
            "on": "visible",
            "request": "pageview",
            "vars": {
              "title": "<?php the_title() ?>",
              "ampdocUrl": "${canonicalUrl}"
            }
          }
        }
      </script>
    </amp-analytics>

如何修改返回给 Google Analytics 的页面名称(页面 url)?

4

2 回答 2

3

好的,我想通了。您添加一个 documentLocation 变量。就是这样:

 <amp-analytics type="googleanalytics" id="analytics1">
  <script type="application/json">
  {
    "vars": {
      "account": "UA-664228-1"
    },

    "triggers": {

      "trackPageview": {
        "on": "visible",
        "request": "pageview",
        "vars": {
          "title": "<?php the_title() ?>",
          "ampdocUrl": "${canonicalUrl}",
          "documentLocation": "myCustomPage"
        }
      }
    }
  </script>
</amp-analytics>
于 2016-10-25T14:22:48.087 回答
0

您可以使用变量 substiution

于 2016-10-26T16:47:09.187 回答