【问题标题】:How to track a form submission using Google Analytics如何使用 Google Analytics 跟踪表单提交
【发布时间】:2016-09-11 19:57:23
【问题描述】:

我想跟踪一个简单的联系我们表单提交,我用于此的代码是,

form action="/contact-us/#wpcf7-f2017-p2044-o1" method="post" **onsubmit = "ga('send', 'event', 'Contact Form Submission', 'post', location.pathname, {
  nonInteraction: true});"** class="wpcf7-form sent" novalidate="novalidate"

它不起作用并给出此错误,

Uncaught SyntaxError: Unexpected token ILLEGAL VM300:1

Google Analytic 帐户中的其他所有内容都运行良好。可能是因为开发者在函数内部实现了代码?

非常感谢您对此提供任何帮助。

谢谢

【问题讨论】:

  • 这些 ** 字符实际上是否在代码中,或者您是否尝试使用事件跟踪突出显示该位?

标签: javascript google-analytics google-analytics-api event-tracking


【解决方案1】:

你的字符串中有一个换行符

"ga('send', 'event', 'Contact Form Submission', 'post', location.pathname, {
  nonInteraction: true});"

删除它使其工作:

"ga('send', 'event', 'Contact Form Submission', 'post', location.pathname, {nonInteraction: true});"

这里解释了问题: JavaScript string with new line - but not using \n

【讨论】:

  • 非常感谢 Elmer,我会努力的
  • 就是这样 :) 新行是错误,非常感谢 Elmer Fudd
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 2023-04-10
  • 1970-01-01
  • 2013-10-27
  • 2013-08-14
  • 2023-01-22
相关资源
最近更新 更多