0

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?

Blexy
  • 9,573
  • 6
  • 42
  • 55
Bilet1988
  • 21
  • 2
  • possible duplicate of [Track event in google analytics upon clicking form submit](http://stackoverflow.com/questions/4086587/track-event-in-google-analytics-upon-clicking-form-submit) – CrayonViolent Mar 31 '14 at 17:40

3 Answers3

2

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>
Max Al Farakh
  • 4,386
  • 4
  • 29
  • 56
  • Google updated their methods. You should look at their new way of doing things: https://developers.google.com/analytics/devguides/collection/analyticsjs/events – invot Apr 29 '14 at 17:14
0

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'
        }
    }
});
Diego ZoracKy
  • 2,227
  • 15
  • 14
0

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>
Thomascs
  • 75
  • 6