Advanced Analytics - Discussions
2.1K members online now
2.1K members online now
Guide Me
star_border
Reply

Best way to track form submission

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi Community

 

I'd like to reliably track the number of submissions on a form whose action takes the user to an external website.

 

I have tried:

<form action="https://secure.myurl.com" method="post" name="checkout"  onsubmit="ga('send', 'event', 'Forms', 'Go Pay']);" >

 

and then on the form's submit button

<input name="submit" value="Submit" type="submit" onClick="ga('send', 'event', 'Forms', 'Go Pay']);">

 

But so far no data has turned up in my analytics account.

Do I need to give a day or so to arrive or is this to do with the javascript not having a chance to run (i.e. I need to use the 'transport: beacon' option?)

 

Thanks 

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Peter D
June

Re: Best way to track form submission

[ Edited ]
Top Contributor
# 2
Top Contributor

Hi @Peter D  :-)

 

I have tried:

<form action="https://secure.myurl.com" method="post" name="checkout"  onsubmit="ga('send', 'event', 'Forms', 'Go Pay']);" >

 

and then on the form's submit button

<input name="submit" value="Submit" type="submit" onClick="ga('send', 'event', 'Forms', 'Go Pay']);">

 
There is a right square bracket in there at the end of the event tracking code which is likely causing an error

currently reads as:
"ga('send', 'event', 'Forms', 'Go Pay']);"

should read as:
"ga('send', 'event', 'Forms', 'Go Pay');"

 

One of the problems with tracking form submits that move visitors to an external site, is that often the tracking code can stop executing on the current page if a new page begins to load

 

You may want to look into using autotrack which has an outboundFormTracker plugin to handle this type of situation and the code loading correctly

https://github.com/googleanalytics/autotrack#outboundformtracker

eta.. sometimes events can take a while to show up in the reports, however usually (not always) you should be able to see an event as it fires, in the real time reports.

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Best way to track form submission

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Doh! Very careless of me. 

Thank you for your help. That's fixed it.