Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/175953
Change subject: Add experiment for testing sendBeacon reliability
......................................................................
Add experiment for testing sendBeacon reliability
The goals of the experiment are to get emperical data on
what browsers support sendBeacon, what proportion of our users
have these browsers, and the reliability of sendBeacon.
For browsers that do support it, we log the same event twice
(except noting which event is which) with the two methods
to allow correlating which events are not delivered.
For example, it will show what proportion of img events
come from a sendBeacon-supporting browser, but have no accompanying
sendBeacon event (or vice-versa).
For browsers without sendBeacon, there is nothing to correlate,
so if an img event is not delivered, we have no way to know.
As an optimization, only 1/1000 views do the logging.
Change-Id: I07ecbde39b5f1ce640f40430b198f8c160a89d13
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 42 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents
refs/changes/53/175953/1
diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index 267eaa9..95ec50a 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -53,6 +53,11 @@
'schema' => 'Edit',
'revision' => 10604157,
),
+ 'schema.SendBeaconReliability' => array(
+ 'class' => 'ResourceLoaderSchemaModule',
+ 'schema' => 'SendBeaconReliability',
+ 'revision' => '10643665',
+ ),
'ext.wikimediaEvents.ve' => array(
'scripts' => 'ext.wikimediaEvents.ve.js',
'dependencies' => 'ext.visualEditor.base',
@@ -66,6 +71,13 @@
'remoteExtPath' => 'WikimediaEvents/modules',
'targets' => array( 'desktop', 'mobile' ),
),
+ 'ext.wikimediaEvents.sendBeacon' => array(
+ 'scripts' => 'ext.wikimediaEvents.sendBeacon.js',
+ 'localBasePath' => __DIR__ . '/modules',
+ 'remoteExtPath' => 'WikimediaEvents/modules',
+ 'dependencies' => array(),
+ 'targets' => array( 'desktop', 'mobile' ),
+ ),
);
$wgVisualEditorPluginModules[] = 'ext.wikimediaEvents.ve';
diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index c0bb539..2d409e9 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -25,11 +25,15 @@
/**
* Adds 'ext.wikimediaEvents.deprecate' logging module for logged-in
users.
+ *
+ * Adds 'ext.wikimediaEvents.sendBeacon' for all users.
* @see https://meta.wikimedia.org/wiki/Schema:DeprecatedUsage
* @param OutputPage &$out
* @param Skin &$skin
*/
public static function onBeforePageDisplay( &$out, &$skin ) {
+ $out->addModules( 'ext.wikimediaEvents.sendBeacon' );
+
$user = $out->getUser();
if ( $user->isAnon() ) {
diff --git a/modules/ext.wikimediaEvents.sendBeacon.js
b/modules/ext.wikimediaEvents.sendBeacon.js
new file mode 100644
index 0000000..d55626e
--- /dev/null
+++ b/modules/ext.wikimediaEvents.sendBeacon.js
@@ -0,0 +1,26 @@
+( function ( mw, $ ) {
+ var ODDS, isBeaconAvailable, logId, baseEvent, imgEvent, beaconEvent;
+
+ ODDS = 0.001; // 1 in 1000 chance
+
+ if ( Math.random() < ODDS ) {
+ mw.loader.using( [ 'mediawiki.user',
'schema.SendBeaconReliability' ] ).done( function () {
+ isBeaconAvailable = !!navigator.sendBeacon;
+
+ baseEvent = {
+ browserSupportsSendBeacon: isBeaconAvailable,
+ userAgent: window.navigator.userAgent,
+ logId: mw.user.generateRandomSessionId()
+ };
+
+ imgEvent = $.extend( true, {}, baseEvent, { method:
'logEvent' } );
+ beaconEvent = $.extend( true, {}, baseEvent, { method:
'logPersistentEvent' } );
+
+ mw.eventLog.logEvent( 'SendBeaconReliability', imgEvent
);
+
+ if ( isBeaconAvailable ) {
+ mw.eventLog.logPersistentEvent(
'SendBeaconReliability', beaconEvent );
+ }
+ } );
+ }
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/175953
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I07ecbde39b5f1ce640f40430b198f8c160a89d13
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits