Skip to content

Instantly share code, notes, and snippets.

@stugoo
Last active December 14, 2015 01:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stugoo/5003963 to your computer and use it in GitHub Desktop.
Save stugoo/5003963 to your computer and use it in GitHub Desktop.
Event tracking that also logs modernizr tests. - splits tests into passes & fails, with a variable to test if you want to track passes and/or fails
var SDM = SDM || {};
SDM.track = function (args) {
args = args || {};
var category = args.category,
action = args.action,
label = args.label,
value = args.value || null;
if (_gaq) {
_gaq.push(['_trackEvent', category, action, label, value]);
}
};
(function (Modernizr) {
var trackpasses = true,
trackfails = true,
trackFeature = function (results) {
if (trackpasses && results.passed.length > 0)
SDM.track({ category: 'modernizr', action: 'passes', label: results.passed });
if (trackfails && results.failed.length > 0)
SDM.track({ category: 'modernizr', action: 'fails', label: results.failed });
},
log = function() {
var tests = {passed: [], failed: [] };
for(d in Modernizr) {
if(typeof Modernizr[d] === 'function') continue;
if(typeof Modernizr[d] === 'array') continue;
if(typeof Modernizr[d] === 'object') continue;
if(Modernizr[d] && trackpasses)
tests.passed.push(d);
else if ( trackfails )
tests.failed.push(d);
}
tests.passed = tests.passed.join("|");
tests.failed = tests.failed.join("|");
trackFeature(tests);
};
if( trackpasses || trackfails) return log();
})(Modernizr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment