Hi,
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.
Thanks
Hi All,
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.
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXXXX-1’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘https://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
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!
KR
Siro
References to above procedure:
Ref 1) https://developers.google.com/analytics/devguides/collection/gajs/
Ref 2) https://www.creare.co.uk/goal-tracking-contact-form-7