Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google analytics event tracker
// Google analytics implementation
window.Analytics = (function(ga) {
function Analytics() { }
Analytics.prototype.trackEvent = function(category, action, label, value) {
ga.apply(this, ['send', 'event'].concat(;
Analytics.prototype.trackPage = function(options) {
ga.apply(this, ['send', 'pageview'].concat(;
return Analytics;
// Initialize analytics = {
google: new window.Analytics(),
//clickView: new ClickViewAnalytics()
$('*[data-analytics-category]').on('click', function() {
var $this = $(this);
// Get event data
var category = $'analytics-category');
var action = $'analytics-action
var label = $'analytics-label');
var value = $'analytics-value');
// Track event, action, label, value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.