A jQuery plugin that helps you set up easy event Tracking With Google Analytics.
A jQuery plugin that helps you set up Event Tracking With Google Analytics.
$.data()
._gaq
variable set.The default behaviour of the plugin is to automagically search your page for any elements containing html5 data attributes that start with data-ga
.
This will then add tracking defaulting to the more commonly used _trackevent
method setting the parameters to pass to that method from the corresponding data attributes.
To alter that default behaviour a data api has been provided.
e.g.
// Unbind the default behaviour
$(document).off("ready.ga").on("ready", function () {
// Set some options the ones below are the defaults.
var options = {
event: "trackEvent", // The event name unprefixed.
handler: "click", // The eventhandler to trigger the tracking.
// Using 'load' will track immediately.
debug: false // Whether to run in debug mode.
};
// Bind using the custom selector.
$("selector").googleAnalytics(options);
});
handler A string containing one or more DOM event types, such as "click" or "submit," or custom event names.
debug Whether the plugin is in debug mode. If set to true the plugin will log the argument array to the development console.
<a class="trackEvent" href="#" data-ga-category="category" data-ga-action="action" data-ga-label="label" >
Click to test trackEvent
</a>
$("a.trackEvent").googleAnalytics({event:"trackEvent", handler:"click"});
Will bind the _trackEvent
analytics method to click event of the selected DOM object.
<a class="trackPageview" href="#" data-ga-url="/some other url">Click to test trackPageview</a>
$("a.trackPageview").googleAnalytics({event:"trackPageview", handler:"click"});
Will bind the _trackPageview
analytics method to click event of the selected DOM object.
Please use the GitHub issue tracker for bug reports and feature requests.