Skip to content

@stugoo /event-tracker-modernizr.js
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.