Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Usage

Use `$('body').analyticsEventTracking();` to initialize the plugin.

All elements in the body tag which contain the class `.track` will be tracked.
All current and future elements in the body tag which contain the class `.track` will be tracked.

Add `data-category="category-name"` to specify the category (default: 'General')
Add `data-action="click"` to specify the action (default: 'click')
Expand Down
50 changes: 25 additions & 25 deletions js/jquery.analytics-event-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@

(function($)
{
$.fn.analyticsEventTracking = function(options)
{
var settings = $.extend({
selector: '.track',
default_category: 'General'
}, options);
$.fn.analyticsEventTracking = function(options)
{
var settings = $.extend({
selector: '.track',
default_category: 'General'
}, options);

if(typeof ga !== 'function')
{
log('Google Analytics (analytics.js) is not initialized.');
return false;
}
if(typeof ga !== 'function')
{
log('Google Analytics (analytics.js) is not initialized.');
return false;
}

return $(this).each(function()
{
var _self = $(this);
return $(this).each(function()
{
var _self = $(this);

bindEvents();
bindEvents();

function bindEvents()
{
_self.find(settings.selector).on('click', function(e)
function bindEvents()
{
_self.on('click', settings.selector, function(e)
{
trackEvent('click', $(this));
});

_self.find(settings.selector + '-blur').on('blur', function(e)
_self.on('blur', settings.selector + '-blur', function(e)
{
trackEvent('blur', $(this));
});

_self.find(settings.selector + '-complete').on('blur', function(e)
_self.on('blur', settings.selector + '-complete', function(e)
{
if($.trim($(this).val()) != '')
{
trackEvent('complete', $(this));
}
});

_self.find(settings.selector + '-focus').on('focus', function(e)
_self.on('focus', settings.selector + '-focus', function(e)
{
trackEvent('focus', $(this));
});

_self.find(settings.selector + '-mouseover').on('mouseover', function(e)
_self.on('mouseover', settings.selector + '-mouseover', function(e)
{
trackEvent('mouseover', $(this));
});

_self.find(settings.selector + '-change').on('change', function(e)
_self.on('change', settings.selector + '-change', function(e)
{
trackEvent('change', $(this));
});
Expand All @@ -75,7 +75,7 @@

ga('send', 'event', category, action, label, value);
}
});
});

function log(message)
{
Expand All @@ -84,5 +84,5 @@
console.log(message);
}
}
}
}
}(jQuery));