[MediaWiki-commits] [Gerrit] mediawiki...WikimediaEvents[master]: Introduce the reading depth schema
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/336447 ) Change subject: Introduce the reading depth schema .. Introduce the reading depth schema A reading depth schema is enabled on all pages and logs at a sampling rate (as defined in wgWMEReadingDepthSamplingRate) events on page load and page unload for all browsers which are beacon capable. In a follow up patch it will take into account the visibility time but for now visibleLength will always be the same as totalLength. A follow up patch will also track the time of first paint when available to give a more fair representation of session. Note times are rounded up to closest integer given milliseconds is more than enough precision. Bug: T155639 Change-Id: Ifb6ceb51bbb949ad17da17a3b38e9d04c3bf6457 --- M README M WikimediaEventsHooks.php M extension.json A modules/ext.wikimediaEvents.readingDepth.js 4 files changed, 147 insertions(+), 1 deletion(-) Approvals: Bmansurov: Looks good to me, approved jenkins-bot: Verified diff --git a/README b/README index 66a0668..176e1c3 100644 --- a/README +++ b/README @@ -11,3 +11,8 @@ Although the code in this extension was developed with Wikimedia use-cases in mind, you may find that the functionality it implements is useful. You are welcome to use and adapt this extension under the terms of its license. + +== Measuring reading depth == +Using the config value `wgWMEReadingDepthEnabled` it is possible to capture +information on user sessions. More information can be found at: +https://phabricator.wikimedia.org/T155639 diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php index 5e8d4b4..4df5d74 100644 --- a/WikimediaEventsHooks.php +++ b/WikimediaEventsHooks.php @@ -395,8 +395,10 @@ } public static function onResourceLoaderGetConfigVars( &$vars ) { - global $wgWMEStatsdBaseUri; + global $wgWMEStatsdBaseUri, $wgWMEReadingDepthSamplingRate, $wgWMEReadingDepthEnabled; $vars['wgWMEStatsdBaseUri'] = $wgWMEStatsdBaseUri; + $vars['wgWMEReadingDepthSamplingRate'] = $wgWMEReadingDepthSamplingRate; + $vars['wgWMEReadingDepthEnabled'] = $wgWMEReadingDepthEnabled; } /** diff --git a/extension.json b/extension.json index 1442680..d21cbdc 100644 --- a/extension.json +++ b/extension.json @@ -94,6 +94,11 @@ "schema": "DeprecatedUsage", "revision": 7906187 }, + "schema.ReadingDepth": { + "class": "ResourceLoaderSchemaModule", + "schema": "ReadingDepth", + "revision": 16325045 + }, "schema.ModuleLoadFailure": { "class": "ResourceLoaderSchemaModule", "schema": "ModuleLoadFailure", @@ -134,6 +139,7 @@ "ext.wikimediaEvents.events.js", "ext.wikimediaEvents.statsd.js", "ext.wikimediaEvents.kartographer.js", + "ext.wikimediaEvents.readingDepth.js", "ext.wikimediaEvents.rlfeature.js", "ext.wikimediaEvents.searchSatisfaction.js", "ext.wikimediaEvents.geoFeatures.js" @@ -142,6 +148,7 @@ "ext.eventLogging.subscriber", "mediawiki.user", "mediawiki.Uri", + "mediawiki.experiments", "mediawiki.storage" ], "targets": [ @@ -165,6 +172,8 @@ "remoteExtPath": "WikimediaEvents/modules" }, "config": { + "WMEReadingDepthSamplingRate": 0.005, + "WMEReadingDepthEnabled": false, "WMEStatsdBaseUri": false }, "manifest_version": 1 diff --git a/modules/ext.wikimediaEvents.readingDepth.js b/modules/ext.wikimediaEvents.readingDepth.js new file mode 100644 index 000..34c4379 --- /dev/null +++ b/modules/ext.wikimediaEvents.readingDepth.js @@ -0,0 +1,130 @@ +/*! + * Track reading session + * The reading depth schema is defined in https://phabricator.wikimedia.org/T155639 + * and intends to capture interactions across the Wikimedia site with regards to how + * many pages a user views and how much time they spend on pages. + * + * @see https://meta.wikimedia.org/wiki/Schema:ReadingDepth + */ +( function ( $, mw, config, user, mwExperiments ) { + + /** + * If available return the time in ms till first paint + * + * @param {PerformanceTiming} perf See + * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming. + * @param {Float} from time in ms a
[MediaWiki-commits] [Gerrit] mediawiki...WikimediaEvents[master]: Introduce the reading depth schema
Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/336447 ) Change subject: Introduce the reading depth schema .. Introduce the reading depth schema A reading depth schema is enabled on all pages and logs at a sampling rate (as defined in wgWMEReadingDepthSamplingRate) events on page load and page unload for all browsers which are beacon capable. In a follow up patch it will take into account the visibility time but for now visibleLength will always be the same as totalLength. Bug: T155639 Change-Id: Ifb6ceb51bbb949ad17da17a3b38e9d04c3bf6457 --- M WikimediaEventsHooks.php M extension.json A modules/ext.wikimediaEvents.readingDepth.js 3 files changed, 70 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents refs/changes/47/336447/1 diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php index 9eca2bb..4a81c46 100644 --- a/WikimediaEventsHooks.php +++ b/WikimediaEventsHooks.php @@ -395,8 +395,10 @@ } public static function onResourceLoaderGetConfigVars( &$vars ) { - global $wgWMEStatsdBaseUri; + global $wgWMEStatsdBaseUri, $wgWMEReadingDepthSamplingRate, $wgWMEReadingDepthEnabled; $vars['wgWMEStatsdBaseUri'] = $wgWMEStatsdBaseUri; + $vars['wgWMEReadingDepthSamplingRate'] = $wgWMEReadingDepthSamplingRate; + $vars['wgWMEReadingDepthEnabled'] = $wgWMEReadingDepthEnabled; } /** diff --git a/extension.json b/extension.json index 41a6767..90d15f6 100644 --- a/extension.json +++ b/extension.json @@ -94,6 +94,11 @@ "schema": "DeprecatedUsage", "revision": 7906187 }, + "schema.ReadingDepth": { + "class": "ResourceLoaderSchemaModule", + "schema": "ReadingDepth", + "revision": 16293542 + }, "schema.ModuleLoadFailure": { "class": "ResourceLoaderSchemaModule", "schema": "ModuleLoadFailure", @@ -134,11 +139,13 @@ "ext.wikimediaEvents.events.js", "ext.wikimediaEvents.statsd.js", "ext.wikimediaEvents.kartographer.js", + "ext.wikimediaEvents.readingDepth.js", "ext.wikimediaEvents.rlfeature.js", "ext.wikimediaEvents.searchSatisfaction.js", "ext.wikimediaEvents.geoFeatures.js" ], "dependencies": [ + "schema.ReadingDepth", "ext.eventLogging.subscriber", "mediawiki.user", "mediawiki.Uri", @@ -165,6 +172,8 @@ "remoteExtPath": "WikimediaEvents/modules" }, "config": { + "WMEReadingDepthSamplingRate": 1, + "WMEReadingDepthEnabled": true, "WMEStatsdBaseUri": false }, "manifest_version": 1 diff --git a/modules/ext.wikimediaEvents.readingDepth.js b/modules/ext.wikimediaEvents.readingDepth.js new file mode 100644 index 000..cdb9c56 --- /dev/null +++ b/modules/ext.wikimediaEvents.readingDepth.js @@ -0,0 +1,58 @@ +/*! + * Track reading session + * + * @see https://meta.wikimedia.org/wiki/Schema:ReadingDepth + */ +( function ( $, mw, conf, user, exp ) { + + var msPaused = 0, + from = new Date(); + + function logEvent( action ) { + var data, now; + + data = { + pageTitleSource: conf.get( 'wgTitle' ), + namespaceIdSource: conf.get( 'wgNamespaceNumber' ), + skin: conf.get('skin'), + action: action, + pageToken: user.generateRandomSessionId() + + Math.floor( mw.now() ).toString() + + user.generateRandomSessionId(), + sessionToken: user.sessionId() + }; + + if ( action === 'pageUnloaded' ) { + now = new Date(); + data.totalLength = now - from; + data.visibleLength = now - from - msPaused; + } + mw.eventLog.logEvent( 'ReadingDepth', data ); + } + + function isInSample( samplingRate ) { + var bucket = exp.getBucket( { + name: 'WME.ReadingDepth', + enabled: true, + buckets: { + control: 1 - samplingRate, + A: samplingRate + } +