如何使用Google Analytics跟踪表单提交

时间:2021-11-13 14:48:07

I wanted to track a simple contact us form submission and the code I used for this is,

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

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"

It doesn't work and gives this error,

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

Uncaught SyntaxError: Unexpected token ILLEGAL VM300:1

未捕获的SyntaxError:意外的标记ILLEGAL VM300:1

Everything else in the Google Analytic account is working fine. May be because the developer has implemented the code inside a function?

Google Analytic帐户中的其他所有内容均正常运行。可能是因为开发人员已在函数内部实现了代码?

ny help regarding this would be highly appreciated.

对此有用的帮助将受到高度赞赏。

Thank you

1 个解决方案

#1


0  

You have a newline character in your string

您的字符串中有换行符

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

Removing it makes it work:

删除它使它工作:

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

The problem is explained here: JavaScript string with new line - but not using \n

这里解释了这个问题:带有新行的JavaScript字符串 - 但没有使用\ n

#1


0  

You have a newline character in your string

您的字符串中有换行符

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

Removing it makes it work:

删除它使它工作:

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

The problem is explained here: JavaScript string with new line - but not using \n

这里解释了这个问题:带有新行的JavaScript字符串 - 但没有使用\ n