0

I'm using Universal Analytics tracking code and would like to start tracking click events for one of the buttons. I added the ga('send'...) on click event via jQuery. Do I need to make any changes to the actual Universal Analytics tracking snippet?

2 Answers 2

2

No, you don't need to make any changes. I'm assuming you are invoking the library and creating the tracker through the standard method.

Your code should look something like this:

<button onclick="ga('send', 'event', 'your_category', 'your_action', 'your_label');">

With jQuery, placing an event listener on the button:

$('button').click(function(){
    console.log("sending your event"); // use this to debug
    ga('send', 'event', 'your_category', 'your_action', 'your_label');
}
2
  • Any updates, OP?
    – nyuen
    Aug 26, 2015 at 20:39
  • 1
    Above will work, just make sure before you redirect that the above event finishes else you will have some missing clicks. Sep 12, 2015 at 19:15
0

No you don't. Google mentions that the events tracking is part of analytics.js (which is what the default Universal Analytics snippet is calling).

I'm sure you already saw this, but in case you didn't and you're wanting to confirm that you did the jQuery part correctly, here's Google's example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.