Created
May 30, 2013 17:31
-
-
Save rachelmyers/5679654 to your computer and use it in GitHub Desktop.
Front End Performance Monitoring
This file contains 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
TrackTiming = function(category, feature) { | |
this.category = category; | |
this.feature = feature; | |
this.startTime = new Date().getTime(); | |
this.endTime = null; | |
return this; | |
}; | |
TrackTiming.prototype.startTime = new Date().getTime(); // shared startTime | |
TrackTiming.prototype.setEnd = function() { | |
this.endTime = new Date().getTime(); | |
return this; | |
}; | |
TrackTiming.prototype.sendFeatureTiming = function() { | |
var time = this.endTime - this.startTime; | |
var twoMinutes = 1000 * 60 * 2; | |
if (time < twoMinutes && time > 0) { | |
window._gaq.push(['_trackTiming', | |
this.category, this.feature, time]); | |
} | |
return this; | |
}; | |
var tt = new TrackTiming(); // init | |
$(‘#myImg’).on('load', function() { | |
tt.setEndTime().sendFeatureTiming(); | |
}); |
This file contains 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
TrackTiming.prototype.sendFeatureTiming = function() { | |
var time = this.endTime - this.startTime; | |
var twoMinutes = 1000 * 60 * 2; | |
if (time < twoMinutes && time > 0) { | |
window._gaq.push(['_trackTiming', | |
this.category, this.feature, time]); | |
} | |
return this; | |
}; | |
var tt = new TrackTiming(); // init | |
$(‘#myImg’).on('load', function() { | |
tt.setEndTime().sendFeatureTiming(); | |
}); |
This file contains 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
var measurements = []; | |
var now = new Date(); | |
var checkTime = function(measurements) { | |
var newNow = new Date(); | |
measurements.push(newNow - now); | |
now = newNow; | |
setTimeout(checkTime,300); | |
}; | |
// collects an array of times: | |
// measurements = [357,300,300,424,404,300] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment