We used to have the old google analytics code in the additional settings box and it tracked form submissions fake page views with the below code:
on_sent_ok: "_gaq.push(['_trackPageview', '/thanks']);"
Then we updated to universal analytics and replaced the above code that was in the additional settings box with the below and set up an event goal to match it:
on_sent_ok: "ga('send', 'event', 'category', 'action', 'label');"
.... but now it doesn't track form submissions.
I also tried send pageview /thanks with the new universal code and set the page destination as a goal and still no joy.
Please can someone help with this? Do we need to implement Roundcape's procedure first before this will work??
Any help would be much appreciated.
I was struggling with this, and other posts didn't seem to resolve.
Additionally, errors were very random, some of my sites work, some don't. I was getting a "Uncaught ReferenceError: _gaq is not defined" when submitting (you can see this by opening the developer tools, console on google chrome)
At the end I resolved by introducing the following code (Ref 1) on the Header, at the beginning, of the page where your contact form is, replacing the UA-XXXXXX-1 with your analytics code.
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
Then you can add the tracking code in the "Additional Settings" of the form, where you replace the /goals/enquiry-sent with whatever goal page you have defined (Ref 2):
on_sent_ok: "_gaq.push(['_trackPageview', '/goals/enquiry-sent']);"
This now works consistently across all my websites. Hope this helps!
References to above procedure:
Ref 1) https://developers.google.com/analytics/devguides/collection/gajs/
Ref 2) http://www.creare.co.uk/goal-tracking-contact-form-7