If you have a form, you can add
onclick ="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);" to the submit tag, but this will fire every time the button is clicked. This is a problem if the form fails validation. Where is it best to load the tracking code so that it's only when successful?
Thanks Bob. Popped them in the View. Just waiting for the results to hit analytics
Hey there,
I'm using Chrono Contact V 3.2 09 Nov 2010 and would like to add Google Analytics tracking to each form I'm using. Somehow I can't get it work :-(
Could you explain me how I can achieve that?
I have currently pasted the following tracking code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['_trackPageview']);
(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>
in "Form" "On Submit code - after sending email:"
Looking forward to your reply.
Kind regards,
Bromm
Hi Bromm,
I just ran a test and the code you have appears to load the Google Analytics library correctly. Do you see any JavaScript errors on the page?
Bob
Digging up an old thread here but could you explain how to implement this using the Auto Serverside validation. Is there a way to attach the js to the show message event?
Sorry, I'm not being clear.
The initial thread was about attaching the event to the javascript validation event. I'd like to fire the Google event when the 'Thank you' message shows.
Hi Petersen,
I think that the method I wrote about in my last post will do that though I'm not sure if loading the code is enough or if it has to be specifically triggered?
Bob
That's the crux. Not sure if anything will specifically fire it unless I wrap it in a onload-type function.
Hi petersen,
I'm sorry, I've lost track of the question here. You can, of course, wrap the code in domready or load function - but that has nothing to do with attaching it to a submit button??
Bob
My fault for mixing questions. Sorry Bob.
To clarify, I want to fire the event on the page that is rendered when we use 'Show thank you message'.
Hi petersen,
Yes, and what is the problem?
Bob