GaTrackEvents is a lightweight jQuery plugin to quickly tag Google Analytic events through data attributes via HTML markup.
For each element you wish to track an event on, add the following optional data attributes:
- data-ga-category
- data-ga-action
- data-ga-label
- data-ga-value
<a href="#" class="ga" data-ga-category="Category" data-ga-action="Action" data-ga-label="Label">Link</a>
Initialize the plugin, targeting a class, ID or element.
$('.ga').gaTrackEvents();
-
event: "type"
A string that defines what type of event is being triggered i.e. click, touch, etc. (default: 'Click'). -
linkOut: boolean
A boolean value that indicates whether or not the element needs to performs the default action of linking to an href value (default: true). -
category: "category"
A string that defines the default category (default: 'General'). -
action: "action"
A string that defines the default action i.e. click, touch, etc. (default: 'Click') -
label: "label"
A string that defines the default label (default: 'Unknown'). -
value: "type of event"
Description (default: 0). -
callback: function() {}
A callback function to run after the GA event has been tracked (default: null).