如何使用Google Analytics跟踪表单提交(How to track a form submission using Google Analytics)

编程入门 行业动态 更新时间:2024-10-27 15:20:30
如何使用Google Analytics跟踪表单提交(How to track a form submission using Google Analytics)

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

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"

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

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

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

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

谢谢

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

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

ny help regarding this would be highly appreciated.

Thank you

最满意答案

您的字符串中有换行符

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

删除它使它工作:

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

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

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

更多推荐

本文发布于:2023-07-28 12:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   如何使用   Google   submission   Analytics

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!