From b183ac3bf3693ec769cee074227bca0a73a7c6dd Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Wed, 17 Mar 2021 16:04:42 -0700 Subject: [PATCH] Inform anonymous A/B test by tracking time from navigationStart This will inform us on the approach taken in I315ea30b88e43f3df29b0a0b37907272ec77d0a7 Additional change: Flesh out TypeScript with eventLogging interface Bug: T275807 Change-Id: I9789cd1dfab5181fa093bce46c5c9b0d338339f5 --- resources/mediawiki.d.ts | 12 ++++++++++++ resources/skins.vector.js/skin.js | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/resources/mediawiki.d.ts b/resources/mediawiki.d.ts index b0ffcb1..ec22494 100644 --- a/resources/mediawiki.d.ts +++ b/resources/mediawiki.d.ts @@ -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. * diff --git a/resources/skins.vector.js/skin.js b/resources/skins.vector.js/skin.js index 7763f30..bf133d1 100644 --- a/resources/skins.vector.js/skin.js +++ b/resources/skins.vector.js/skin.js @@ -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 );