Reputation: 21
I want to use a Google Analytics-event like this:
onclick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'Home Contact']);"
when the following form action is fired:
<form action="http://webshop-cs.tecdoc.net/sonnak/?user=sonnakno&pass=sonnakno&articleCountry=NO" method="post" target="_blank">
<input id="submit" src="http://www.sonnak.com/wp/wp-content/uploads/2010/07/lv2.jpg" type="image" value="submit"/>
</form>
Any idea how?
Upvotes: 0
Views: 676
Reputation: 75
Are you using the updated Google Analytics tracking code in your header? Should look like this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
</script>
Use the new format for tracking events:
onclick="ga('send', 'event', 'Category', 'Action')"
The send
and event
values you can't change, without them the script won't send anything to Google Analytics. The Catergoy
and Action
values are required, you can give them any name you want. For Action
I would recommend click
, that's the action you're registering with onclick
. You can even add more optional parameters if you need to.
Your code could look something like this:
<form action="http://webshop-cs.tecdoc.net/sonnak/?user=sonnakno&pass=sonnakno&articleCountry=NO" method="post" target="_blank">
<input id="submit" src="http://www.sonnak.com/wp/wp-content/uploads/2010/07/lv2.jpg" type="image" value="submit" onclick="ga('send', 'event', 'Form', 'click')";"/>
</form>
Upvotes: 0
Reputation: 2285
Can i recommend you this jQuery plugin (i'm the author). Will be easy to setup the Event Tracking for Google Analytics with it:
https://github.com/DiegoZoracKy/google-analytics-event-tracking.
With this plugin, your code to track this form submit would be:
$.googleAnalyticsEventTracking({
targetSelector: 'form[action="http://webshop-cs.tecdoc.net/sonnak/?user=sonnakno&pass=sonnakno&articleCountry=NO"]', // I suggest you give an ID (e.g. home-contact) to this form and then use #home-contact instead of lookup for the action attribute
events: {
eventType: 'submit',
gaEventData: {
category: 'Forms',
action: 'Submit',
label: 'Home Contact'
}
}
});
Upvotes: 0
Reputation: 4496
Do you mean like this?
<form action="http://webshop-cs.tecdoc.net/sonnak/?user=sonnakno&pass=sonnakno&articleCountry=NO" method="post" target="_blank">
<input id="submit" src="http://www.sonnak.com/wp/wp-content/uploads/2010/07/lv2.jpg" type="image" value="submit" onclick="_gaq.push(['_trackEvent', 'Forms', 'Submit', 'Home Contact']);"/>
</form>
Upvotes: 2