功放表格提交成功后,在功放页面中触发Google amp-analytics事件

时间:2019-12-19 10:02:44

标签: google-analytics amp-html amp-analytics amp-form

我试图在AMP提交成功后触发一个事件。

此刻,我使用dataLayer.push()并发送:类别,操作和标签。

如何使用本文档https://amp.dev/documentation/components/amp-form/#analytics-triggers

中的示例触发成功事件

这是文档中的代码:

<amp-analytics>
  <script type="application/json">
    {
      "requests": {
        "event": "https://www.example.com/analytics/event?eid=${eventId}",
        "searchEvent": "https://www.example.com/analytics/search?formId=${formId}&query=${formFields[query]}"
      },
      "triggers": {
        "formSubmit": {
          "on": "amp-form-submit",
          "request": "searchEvent"
        },
        "formSubmitSuccess": {
          "on": "amp-form-submit-success",
          "request": "event",
          "vars": {
            "eventId": "form-submit-success"
          }
        },
        "formSubmitError": {
          "on": "amp-form-submit-error",
          "request": "event",
          "vars": {
            "eventId": "form-submit-error"
          }
        }
      }
    }
  </script>
</amp-analytics>

1 个答案:

答案 0 :(得分:1)

  1. 缺少selector-AMP必须知道这是哪个表单元素
  2. 其他数据可以作为vars传递。例如。对于Google Analytics(分析),分别为event_labelevent_nameevent_category。有关AMP & GA integration here的更多信息。
…
"formSubmit": {
  "on": "amp-form-submit-success",
  "selector": "form",
  "request": "event",
  "vars": {
    "event_label": "Label 1"
  }
},
…