Created
October 2, 2014 15:17
-
-
Save creativ/6590cb9b30a295b85d12 to your computer and use it in GitHub Desktop.
Google analytics event tracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Google analytics implementation | |
window.Analytics = (function(ga) { | |
function Analytics() { } | |
Analytics.prototype.trackEvent = function(category, action, label, value) { | |
ga.apply(this, ['send', 'event'].concat(Array.prototype.slice.call(arguments))); | |
}; | |
Analytics.prototype.trackPage = function(options) { | |
ga.apply(this, ['send', 'pageview'].concat(Array.prototype.slice.call(arguments))); | |
}; | |
return Analytics; | |
}(ga)); | |
// Initialize analytics | |
window.analytics = { | |
google: new window.Analytics(), | |
//clickView: new ClickViewAnalytics() | |
}; | |
$('*[data-analytics-category]').on('click', function() { | |
var $this = $(this); | |
// Get event data | |
var category = $this.data('analytics-category'); | |
var action = $this.data('analytics-action '); | |
var label = $this.data('analytics-label'); | |
var value = $this.data('analytics-value'); | |
// Track event | |
window.analytics.google.trackEvent(category, action, label, value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment