Hi! I would like to track form submission as a GA event in analytics using the following script? It seems the event is not firing properly in GA as I don’t see the changes event tracking data getting collected: ga(‘send’, ‘event’, ‘form-submission’, ‘submit’, ‘infosession-signup’);
Theres a couple things here you would need to be aware of.
You need to have the dataLayer installed before your container code on every page. It would look something like this: <script>dataLayer = window.dataLayer || [];</script>
You’ll need to setup a custom event trigger inside GTM as well as create custom variables that grab your dataLayer category, action, and label values. Once you have those 2 things you can use them inside a standard GA event tag.
That looks like it should work without any issues. Have you checked the console to see if there are any JS errors during the submission?
Also, make sure that you don’t have Google Analytics installed using Google Tag Manager. If Google Analytics included in that manner you may need create a proxy trigger/tag using a dataLayer event push.
The other thing to try is to set the transport field to “beacon” (previously called useBeacon" to make sure the event isn’t cancelled if the form redirects after submission. You can read about that here:
Yes, I am using GA via Google Tag Manager. Could you share a little bit more about “creating a proxy trigger/tag using a datalayer event push”? Any documentations I can refer to?