Forums » Developers

Manual goal logging and preventDefault()

If we have a JS form handler that uses preventDefault on the form submission (so we can't use "onclick" as far as I know), what's the best way to manually track a goal associated with the form submit?

The preventDefault() is used to validate the form first & then trigger 'submit'. Tried using "onsubmit" in the form without success.

And does it matter that we're using the asynchronous version of the Clicky tracking code? The action being tracked is a form submission - so, highly unlikely that it would occur prior to the Clicky tracking code being loaded.

Posted Tue Jun 24 2014 8:52am by dpmain

Could you display it with your "Thank You" message for the form submission?

I run dynamic goals this way on most contact forms that I have a "Thank You" or related message that I show after submit. Should still be able to transfer/get data from the form via a POST/GET if that is what you're after?

Posted Tue Jun 24 2014 10:37am by ringo64

Unfortunately there's no thankyou - just a "retURL" attribute that sends them to a web page we don't control.

Posted Tue Jun 24 2014 11:18am by dpmain

Ah, that complicates things just a bit :)

My suggestion, might take a little time but will work. Add a function in your JS form handler that after fields are validated to trigger Clicky's dynamic goal, then allow submission of the form. Just need to make sure the dynamic goal executes prior to the POST to the external URL.

Example of dynamic goal trigger:

var clicky_custom = {};
clicky_custom.goal = { name: 'Goal Name' };

Posted Tue Jun 24 2014 2pm by ringo64

Thanks! Will give that a shot.

Posted Tue Jun 24 2014 2:05pm by dpmain

Reply to this discussion

Forums are closed due to massive spam. Sorry.