J.Wu
J.Wu

Reputation: 1

Google Analytics Event Tracking onSubmit Code

I'm trying to set up event tracking, but it doesn't work. The event counts zero on Google Analytics. I think there is something wrong with my code. Any ideas on what is wrong? Thank you.

 <input id="submit_o2830002"         name="/atg/commerce/order/purchase/CartModifierFormHandler.checkout" value="goCheckOut" class="endbtn" type="submit" onsubmit="ga('send', {
                        &nbsp; hitType: 'event',
                        &nbsp; eventCategory: 'Order',
                        &nbsp; eventAction: 'goCheckOut',
                        &nbsp; eventLabel: 'click goCheckOut'
                        });">

Upvotes: 0

Views: 1086

Answers (1)

Sampsa Suoninen
Sampsa Suoninen

Reputation: 624

Issue you're having is as far as I can see it a syntax one. Are those " " characters really there in the code? If so, remove them. They should cause JavaScript errors when submitting form. You cannot add HTML entities to JavaScript like this, especially where they do not belong. I recommend pasting the JavaScript code to something like JSHint to validate it if issues arise.

The onSubmit code should be like so:

ga('send', {hitType: 'event', eventCategory: 'Order', eventAction: 'goCheckOut', eventLabel: 'click });

Tip: You can use your browser's developer tools to make sure if a call to Google Analytics is made when you use this (remember to use "persist logs" or similar option). This helps you to confirm if the function is run correctly and sends data. Developer tools is opened on most browsers with F12 (Windows) and use the tab called "network" to monitor calls to "google-analytics.com".

Upvotes: 1

Related Questions