AMP客户端ID错误

时间:2018-05-18 17:41:22

标签: javascript google-analytics amp-html clientid

目前尝试实现CLIENT_ID变量(https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#variable-substitution-in-links),以便链接为:

<a id="get-started" href="https://subdomain.website.com/?client_id=CLIENT_ID(_ga)" data-amp-replace="CLIENT_ID">

我们还将域名列入白名单:

<meta name="amp-link-variable-allowed-origin" content="https://www.website.com https://subdomain.website.com">

然后修改了GA代码:

    <amp-analytics type="googleanalytics">
     <script type="application/json">
      {
        "vars": {
          "account": "UA-XXXXXXX-X"
        },
        "extraUrlParams": {
          "clientId": "${clientId(_ga)}"
        },
        "triggers": {
          "trackPageview": {
            "on": "visible",
            "request": "pageview"
          }
        }
      }
    </script>
   </amp-analytics>

控制台正在报告这些错误:

element-service.js:63 The first argument to CLIENT_ID, the fallback Cookie name, is required:  undefined
log.js:317 Uncaught Error: The first argument to CLIENT_ID, the fallback Cookie name, is required: undefined​​​

1 个答案:

答案 0 :(得分:1)

改为使用CLIENT_ID(_ga)

<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXXX-X"

  },
  "extraUrlParams": {
    "ampClientId": "CLIENT_ID(_ga)"
  },
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
    }
  }
}
</script>