Last active
December 14, 2015 01:09
-
-
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
This file contains hidden or 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
/* | |
.track via @adamcbrewer | |
modernizr from http://jsfiddle.net/ejL3Q/3/ | |
*/ | |
var NS = NS || {}; | |
NS.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, GoogleAnalyticsQueue) { | |
var trackFeature = function (testName, testResult) { | |
var result = (testResult) ? 'Yes' : 'No'; | |
NS.track({ | |
category: 'modernizr', | |
action: testName, | |
label: result | |
}); | |
}, | |
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]) | |
tests.passed.push(d); | |
else | |
tests.failed.push(d); | |
trackFeature(d, Modernizr[d]); | |
} | |
return tests; | |
}; | |
return log(); | |
})(Modernizr, _gaq); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment