• 1918

    What a great topic! If there is one part of most SEO campaigns that is given less glory than it deserves it’s event tracking.

    The best part of having a smart person doing analytics for clients is that they start to look at everything on their site differently. It’s always gratifying to hear a client say the 4 magic words, “can we test that?”

  • iamchrisle

    Great stuff Nico!! Event tracking is super powerful stuff that really help get detailed metrics on your users.

  • nicomiceli

    Thanks man! I agree, it’s one of those things where people don’t realize the impact and great influx of data you can get until you implement it.

  • Glen Craig

    Thanks for the great definitions. I knew maybe two of those. I think I’ll be tinkering with my newsletter forms now!

  • Zach

    This is a very informative article. You guys should write something on virtual page views as well. I struggled to find solid information on it, and it is great for tracking events on a single URL.

  • nicomiceli

    Thanks Zach! And good idea about virtual page views, might have to write something up about that. :)

  • nicomiceli

    Yeah, I was blown away when I found all of them. For the full list check this out:

    Also if you want to get into form tracking our old developer @iamchrisle:disqus wrote this post all about which has awesome code examples

  • Aaron Weiner

    Does this work the same in the new Universal Analytics? Also, what if you’re using more than one Analytics code on your site? Is the event triggered in both codes?

  • nicomiceli

    Hi Aaron – good question. Universal Analytics (which is awesome and Im pumped you asked about it) uses a slightly different syntax. Here it is: ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, numerical value);
    You can also go a lot more advanced with it by adding in additional fields as JS objects. To read more about that here is the documentation –

    Regarding your question about have 2 analytics codes and having it hit twice – I’ll be honest, I don’t know. I 99% sure it will hit twice since you want that data in both accounts but that’s going to go on my to-do list for next week.

  • Aaron Weiner

    I’m looking to track 404 errors as events in the new Universal Analytics.

    Would this work?

    ga(‘send’, ‘event’, ‘Error 404′, ‘page: ‘ + document.location.pathname + + ‘ ref: ‘ + document.referrer);

  • nicomiceli

    Do you want to track people coming to your site and hitting 404 pages or clicking on something on your site that leads to a 404?

    Off the top of my head I would probably build this out as an if statement then have the GA event code. For that GA code I would probably use more of a document.location.href to get the URL.

  • Aaron Weiner

    I would like to track both 404s and where they came from.

  • nicomiceli

    Oh ok, then your code looks like it should work

  • Aaron Weiner

    Thanks. It’s appears to be working in both asynchronous and universal.

  • nicomiceli

    Sweet! Good to know.

  • rfreilino

    Can you be more specific about the syntax? For example, is it:

    onsubmit=”ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, numerical value);”


    onsubmit=ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, numerical value);


  • nicomiceli

    For Universal Analytics it would be the first one:

    onsubmit=”ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, numerical value);”

    And the onsubmit would go in the form tag

    Let me know if you have any more questions.

  • rfreilino

    Hi @nimoniceli. Thanks so much for this awesome post, and your help. I’m actually still having trouble.

    In the form tag, my code is as follows:

    onsubmit=”ga(‘send’, ‘form’, ‘submitted’, ’service request form’);”

    However, no events are showing up in my reports when I make form submissions.

    Additionally, I set up several events as goals, and obviously those aren’t showing up either. For the form event I have set up the goal as follows:

    Category: Regular Expression: form
    Action: Regular Expression: submitted
    Label: Regular Expression: service request form

    Any ideas why my events aren’t showing up? And are my goals set up properly to track these events?

  • nicomiceli

    You have Universal Analytics on your site correct? The new version?

    Here is an example in JSFiddle using jquery to show you how it works.

    Make sure you have your console open for it so you can see the different interactions.

    Do you understand the code? I can comment it out if needed.

  • Omar Elbaga

    Great article! Where do you see the event clicks afterward inside the Analytics Dashboard?

  • Srinivasan T

    Good stuff. I was looking for this kind of simple resource of event tracking. Very glad that found your post. clear and simple about the Google even tracking for non coders.

  • Martin Jones

    Great post – thank you. Would you recommend using onsubmit on a form instead of onclick on an input (submit) button? I have an example where I am missing some form submissions and I wonder if it might be because of using the latter method.

  • carloisles

    I’ll try this one and see if it will work this time. Thanks for the answers and suggestions, really helpful! :)

  • Vikas Rathee

    Is this mandatory to add the analytic code in website header. I
    added the GA analytic code in footer and created many event. But i am
    not able to see anything in google analytics report. Can you please
    suggest if i am missing something :

    GA Code :
    Event code : onerror=”_gaq.push(['_trackEvent','mainimage','failed','pageid'])”

  • Peter Waegemans

    Great article! How powerful it has become… Soon we can check if our user falls asleep on our site.

  • Sheila Dela Pena

    I’ve got a question re opt non/interaction (true/false). The GA documentation ( says the syntax is _trackEvent(category, action, opt_label, opt_value, opt_noninteraction) and that when set to true, “indicates that the event hit will not be used in bounce-rate calculation.” Did Google commit a mistake there?

    By default it’s set to false and means it is not excluded in the bounce rate calculations. Since by definition, Bounce Rate measures the “single-page sessions”, if engagement in that page with the event tracking is okay, and the user goes to another page, that will not even be considered a Bounce.

    However, if from that page with event tracker the user proceeds to leave the site all together, then it gets considered as a Bounce. I think that is a good thing coz then that will be in the Bounce Rate calculation and that, together with other metrics, will provide a good insight as to how users engage with the site.

    Hope I’m making sense. This is a very good article. :)

  • TurboPoet94

    Nico, thanks for such a great site! I’ve been reading up on events and tracking events and I just want to touch base to make sure I’m not using events when something else should be used instead.

    Let’s say I have a fairly rich WordPress content site with tons of dynamic content and the classic GA installed.

    I want to know what area of a given page users are clicking to get to the next page.

    To simplify things – like, REALLY simplify things, lets say there are only 2 ways people on Page X can get to Page Y:
    1) clicking a link in a list of popular_posts in a sidebar
    2) clicking a link of related_posts under the article.

    I want to track how many clicks to other pages came from the list of popular_posts in the sidebar and how many clicks to other pages came from the related_posts under the article.

    Is this a case where events should be used? I’m reading on some other sites that when using GA, that outside of clicks to external links, you should limit events to things happening on the same page so it won’t screw up the rest of the analytics.

    And yet, I’m sitting here thinking, “Wow, if I could make events work somehow for every click on the site, I’d be able to know the location of each click!”

    Is think a case where using event tracking is OK?
    Is there something else I should be using?


  • Jared Steffen

    This article needs to be updated. Google released a new method:

  • Tomasz Pieta

    How can this be accurate? onclick=_gaq.push([‘_trackEvent’, ‘button’, ’clicked’, ’contact us’,, ’true’])

    Shouldn’t this be -> onclick=”_gaq.push([‘_trackEvent’, ‘button’, ’clicked’, ’contact us’,, ’true’]);”

  • Danny Penrose

    Nice post but needs to be updated for Universal Analytics – ga(‘send’, ‘event’, ‘register’, ‘complete’); –

  • Sarina Larson

    HI everyone. I know that GA favors sites like WordPress, Joomla, Drupal… but NOT weebly, wix, etc. I am a Social Media Manager of 1.5 years and want to know: is it best to (a) learn how to design technical implementation of google analytics and event tracking and implement by myself for clients or (b) find a partner to assume this part as i cover strategy and maintenance of social and it’s effects of business objectives?