0

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

ketan
  • 19,129
  • 42
  • 60
  • 98
cool_kid
  • 337
  • 1
  • 3
  • 13

1 Answers1

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

Community
  • 1
  • 1
Elmer Fudd
  • 16
  • 1