I've been looking at this as needed to get GA click tracking sorted and have a solution after finding the issues mentioned by Enrise above with FrankAnthony's method firing twice. Turns out using the jQuery method hooking off of the gform_confirmation_loaded function has problems too as whilst it'll fire jQuery code and execute it, it reports errors loading jQuery anyway, something it's already done. Use Firebug to see what I mean and wrap either of the suggested functions above with a simple bit of jQuery as follows:
[js]
jQuery('#gforms_confirmation_message').css('background-color','red');
So anyway, the solution, albeit a minor hack is to use normal JS but to prevent it being called twice. This is done by wrapping the GA code in an IF statement to check for the existence of jQuery which has the desired effect of only running once and not erroring and causing the GA code to fail. Any thought on other work rounds would be appreciated, wish this sort of tracking could be implemented in the core code though :)
Code for those that might want to get this working though is as follows:
[js]
<script>
if (typeof jQuery != 'undefined') {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_setDomainName', 'none']); // Not needed if cross domain tracking not required
_gaq.push(['_setAllowLinker', 'none']); // Not needed if cross domain tracking not required
_gaq.push(['_trackPageview', '/conversion']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>
Posted 13 years ago on Thursday August 25, 2011 |
Permalink