/**
 * @author Piotr Polak
 * @version 0.1.1
 * @date 05.08.2014
 * @url https://github.com/piotrpolak/jquery-analytics
 * @see https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
 *
 * @example <button data-ga-click-event-category="Button click">Button</button>
 * @example <a href="#" data-ga-click-event-category="Videos" data-ga-click-event-action="Play" data-ga-click-event-label="Rick astley - never gonna give you up" ga-click-event-track-multiplicity="1">Play</a>
 */
(function ($) {

    $.fn.analytics = function () {

        var $element = $(this);

        // Tests whether Google Analytics is present
        function testGaq() {
            // Testing whether _gaq variable is present and push is callable
            if (typeof _gaq !== 'undefined' && typeof _gaq.push === "function") {
                return true;
            }

            return false;
        }

        // Adding click and tap event listeners to selected elements
        // At least data-ga-click-event-category attribute must be defined
        $('*[data-ga-click-event-category]', $element).on("click tap", function (event) {

            // Checking whether there is GA initialized
            if (!testGaq())
            {
                if (typeof console.log === "function") {
                    console.log('_gaq.push is not a function. Make sure Google Analytics is initialized');
                }
                return;
            }

            var $clickedElement = $(this);

            // GA parameters to be read from the element
            var dataParemeters = ['ga-click-event-category', 'ga-click-event-action', 'ga-click-event-label', 'ga-click-event-value', 'ga-click-event-implicit-count'];

            // Data array initialization
            var data = ['_trackEvent'];
            // Used for breaking the loop
            var skip = false;

            // Walking trough the list of allowed parameters
            $.each(dataParemeters, function (index, value) {
                if (skip) {
                    return; // break
                }

                value = $clickedElement.data(value);
                if (!value) {
                    // If there is no value it makes no sense to walk trough the array anymore
                    skip = true;
                    return; // break
                }
                data.push(value);
            });

            // When multiplicity is specified and greater than zero, then the event will be sent a given number of times
            var multiplicity = $clickedElement.data('ga-click-event-track-multiplicity');
            // Only if the initial multiplicity was greater than 0 the following condition will be true
            // By default multiplicity is equal to 0 or undefined so the event will be tracked multiple times
            if (multiplicity > 0) {
                multiplicity--;
                $clickedElement.data('ga-click-event-track-multiplicity', multiplicity);
                if (multiplicity == 0) {
                    $clickedElement.data('ga-click-event-track-multiplicity', -1);

                    // Remove category data thus prevent the event to be reported
                    $clickedElement.data('ga-click-event-category', null);
                    $clickedElement.removeAttr('data-ga-click-event-category');
                }
            }

            // In case data-ga-click-event-category was there but empty
            if (data.length > 1)
            {
                if (typeof console.log === "function") {
                    console.log('GA event tracked', data);
                }

                // Pushing the event
                _gaq.push(data);
            }

        });
    }
})(jQuery);
@@ -683,24 +683,209 @@
 estGaq() %7B%0D%0A
+            // Testing whether ga variable is present and is callable (Universal Analytics)%0D%0A            if (typeof ga === %22function%22) %7B%0D%0A                return true;%0D%0A            %7D%0D%0A%0D%0A
             
@@ -948,16 +948,43 @@
 callable
+ (deprecated ga.js library)
 %0D%0A      
@@ -1139,32 +1139,424 @@
 ;%0D%0A        %7D%0D%0A%0D%0A
+        // Sends the requested event%0D%0A        function sendEvent(data) %7B%0D%0A            if (typeof ga === %22function%22) %7B%0D%0A                return ga.apply(null, %5B'send', 'event'%5D.concat(data));%0D%0A            %7D%0D%0A%0D%0A            if (typeof _gaq !== 'undefined' && typeof _gaq.push === %22function%22) %7B%0D%0A                return _gaq.push(%5B'_trackEvent'%5D.concat(data));%0D%0A            %7D%0D%0A        %7D%0D%0A        %0D%0A
         // Addin
@@ -1970,16 +1970,31 @@
 le.log('
+Neither ga nor 
 _gaq.pus
@@ -2002,12 +2002,8 @@
  is 
-not 
 a fu
@@ -2458,29 +2458,16 @@
 data = %5B
-'_trackEvent'
 %5D;%0D%0A    
@@ -4384,25 +4384,25 @@
         
-_gaq.push
+sendEvent
 (data);%0D

Add support for Universal Analytics script