Skip to content

Send metric only during loading event #1011

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Jul 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 36 additions & 39 deletions js/editor-libs/perf.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
(function() {
'use strict';
'use strict';

/**
* Posts a name to set as a mark to Kuma for
* processing and beaconing to GA
* @param {Object} perf - The performance object sent to Kuma
*/
function postToKuma(perf) {
window.parent.postMessage(perf, 'https://developer.mozilla.org');
}
/**
* Posts a name to set as a mark to Kuma for
* processing and beaconing to GA
* @param {Object} perf - The performance object sent to Kuma
*/
function postToKuma(perf) {
window.parent.postMessage(perf, 'https://developer.mozilla.org');
}

postToKuma({ markName: 'interactive-editor-loading' });

/**
* Posts marks to set on the Kuma side, based on certain
* events during document loading. These will then be made
* available in performance tools, and beaconed to GA
*/
document.addEventListener('readystatechange', function(event) {
switch (event.target.readyState) {
case 'loading':
postToKuma({ markName: 'interactive-editor-loading' });
break;
case 'interactive':
postToKuma({
markName: 'interactive-editor-interactive',
measureName: 'ie-time-to-interactive',
startMark: 'interactive-editor-loading',
endMark: 'interactive-editor-interactive'
});
break;
case 'complete':
postToKuma({
markName: 'interactive-editor-complete',
measureName: 'ie-time-to-complete',
startMark: 'interactive-editor-loading',
endMark: 'interactive-editor-complete'
});
break;
}
});
})();
/**
* Posts marks to set on the Kuma side, based on certain
* events during document loading. These will then be made
* available in performance tools, and beaconed to GA
*/
document.addEventListener('readystatechange', function(event) {
switch (event.target.readyState) {
case 'interactive':
postToKuma({
markName: 'interactive-editor-interactive',
measureName: 'ie-time-to-interactive',
startMark: 'interactive-editor-loading',
endMark: 'interactive-editor-interactive'
});
break;
case 'complete':
postToKuma({
markName: 'interactive-editor-complete',
measureName: 'ie-time-to-complete',
startMark: 'interactive-editor-loading',
endMark: 'interactive-editor-complete'
});
break;
}
});