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?
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?
Hi Petersen.
You can hook into the Validation on success event like this: Drag a Custom Code action into the form On Load event and add this code:
Then add a Load JS action and define the function:
The load JS action accepts PHP so you can add variables to the code here if needed.
Bob
You can hook into the Validation on success event like this: Drag a Custom Code action into the form On Load event and add this code:
<?php
$form->form_params->set('jsvalidation_onValidateSuccess', 'trackEvent');
?>
Then add a Load JS action and define the function:
function trackEvent() {
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);
}
The load JS action accepts PHP so you can add variables to the code here if needed.
Bob
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
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
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?
Hi petersen,
To load the code in the On Submit event I'd drag a Load JS action into it; I think that will work OK. I'd put it after any Validation or Captcha actions and before the Show Thanks Message action.
Bob
how to implement this using the Auto Serverside validation.
I've no idea - what exactly are you asking?To load the code in the On Submit event I'd drag a Load JS action into it; I think that will work OK. I'd put it after any Validation or Captcha actions and before the Show Thanks Message action.
Bob
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.
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
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
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'.
To clarify, I want to fire the event on the page that is rendered when we use 'Show thank you message'.
This topic is locked and no more replies can be posted.