Blog

  • http://www.1918.com/ 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: http://www.w3schools.com/tags/ref_eventattributes.asp

    Also if you want to get into form tracking our old developer @iamchrisle:disqus wrote this post all about which has awesome code examples http://www.seerinteractive.com/blog/how-to-track-user-engagement

  • 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 – https://developers.google.com/analytics/devguides/collection/analyticsjs/events

    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 + document.location.search + ‘ 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);”

    or

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

    or…

  • 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.

    http://jsfiddle.net/nicomiceli/WK5eN/

    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.

  • http://lessonsdadnevertaughtyou.com/ 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! :)

  • http://www.interdigitalmarketing.com/ 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 : http://www.pricingindia.in
    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.

Get our Newsletter

Keep up-to-date search trends, latest blog posts and more!