Skip to content

Instantly share code, notes, and snippets.

@denji
Forked from simondahla/logTimes.js
Created August 26, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denji/a0410fbe6afd54b7d7325aafbd01c3a1 to your computer and use it in GitHub Desktop.
Save denji/a0410fbe6afd54b7d7325aafbd01c3a1 to your computer and use it in GitHub Desktop.
#googleanalytics
function logTimes(message) {
if (window.performance) {
performance.mark(message); // this one is for WebPageTest
console.timeStamp(message); // this is for the Performance tab in Chrome DevTools
console.info(message, performance.now()); // this is for the console, duh
// this here is for Google Analytics
ga('send', {
hitType: 'timing',
timingCategory: 'Performance',
timingVar: message,
timingValue: Math.round(performance.now())
});
}
}
// use it like so
bindAllMyEventsOrWhateverGetsThePageReady();
logTimes('The page is really ready');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment