Skip to content

Instantly share code, notes, and snippets.

@patrickfox
Created November 18, 2014 05:36
Show Gist options
  • Save patrickfox/6e3ac86b04c34a5a228f to your computer and use it in GitHub Desktop.
Save patrickfox/6e3ac86b04c34a5a228f to your computer and use it in GitHub Desktop.
a7s.js - an analytics framework
(function () {
var init, onclick_tracked_item, selector, track_event, track_page, tracked_actions;
selector = '[data-a7s]';
init = function() {
return $(selector).on('click', onclick_tracked_item);
};
onclick_tracked_item = function(e) {
var id, target;
target = $(e.target);
id = target.data('a7s');
if (tracked_actions[id]) {
return tracked_actions[id].call();
}
};
track_page = function(value) {
//_gaq.push(['_trackPageview', value])
return console.log('Page load: ' + value);
};
track_event = function(category, action, value) {
//_gaq.push(['_trackEvent', cat, action, value])
return console.log('Click tracked:' + category + action + value);
};
/*
Put all custom click and page load actions in tracked_actions
*/
tracked_actions = {
'adduser_pageload': function() {
return track_page('AddUser PageLoad');
},
'adduser_save': function() {
return track_event('AddUser', 'Click', 'Save');
},
'adduser_cancel': function() {
return track_event('AddUser', 'Click', 'Cancel');
}
};
$.a7s = init;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment