public
Last active

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

  • Download Gist
event-tracker-modernizr.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.