Merge "Inform anonymous A/B test by tracking time from navigationStart"

This commit is contained in:
jenkins-bot 2021-03-23 18:29:36 +00:00 committed by Gerrit Code Review
commit bd6770014e
2 changed files with 33 additions and 0 deletions

View File

@ -9,9 +9,16 @@ interface MwUri {
toString(): string;
}
interface MwEventLog {
eventInSample( population: Object ): () => boolean;
inSample( num: Number ): () => boolean;
logEvent( schema: string, data: Object ): () => void;
}
type UriConstructor = new( uri: string ) => MwUri;
interface MediaWiki {
eventLog?: MwEventLog,
util: {
/**
* @param {string} id of portlet
@ -80,6 +87,11 @@ interface MediaWiki {
*/
msg( messageName: string|null ): string;
/**
* Get current timestamp
*/
now(): number,
/**
* Track an analytic event.
*

View File

@ -42,6 +42,27 @@ function enableCssAnimations( document ) {
* @return {void}
*/
function main( window ) {
var now = mw.now();
// This is the earliest time we can run JS for users (and bucket anonymous
// users for A/B tests).
// Where the browser supports it, for a 10% sample of users
// we record a value to give us a sense of the expected delay in running A/B tests or
// disabling JS features. This will inform us on various things including what to expect
// with regards to delay while running A/B tests to anonymous users.
// When EventLogging is not available this will reject.
// This code can be removed by the end of the Desktop improvements project.
// https://www.mediawiki.org/wiki/Desktop_improvements
mw.loader.using( 'ext.eventLogging' ).then( function () {
if (
mw.eventLog &&
mw.eventLog.eventInSample( 100 /* 1 in 100 */ ) &&
window.performance &&
window.performance.timing &&
window.performance.timing.navigationStart
) {
mw.track( 'timing.Vector.ready', now - window.performance.timing.navigationStart ); // milliseconds
}
} );
enableCssAnimations( window.document );
collapsibleTabs.init();
sidebar.init( window );