jenkins-bot has submitted this change and it was merged.

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/10,000 views do the logging.

To make future data-gathering like this roll on and off faster,
set up a convention of a 'ext.wikimediaEvents' module that is always
present for this purpose (with or without code).  This solves
ResourceLoader issues (mainly related to cached anon HTML).

Bug: T44815
Change-Id: I07ecbde39b5f1ce640f40430b198f8c160a89d13
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 51 insertions(+), 0 deletions(-)

Approvals:
  Krinkle: Looks good to me, but someone else must approve
  Catrope: Looks good to me, approved
  Prtksxna: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index 267eaa9..846e400 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -53,6 +53,11 @@
                'schema' => 'Edit',
                'revision' => 10604157,
        ),
+       'schema.SendBeaconReliability' => array(
+               'class' => 'ResourceLoaderSchemaModule',
+               'schema' => 'SendBeaconReliability',
+               'revision' => '10676430',
+       ),
        'ext.wikimediaEvents.ve' => array(
                'scripts'       => 'ext.wikimediaEvents.ve.js',
                'dependencies'  => 'ext.visualEditor.base',
@@ -66,6 +71,18 @@
                'remoteExtPath' => 'WikimediaEvents/modules',
                'targets' => array( 'desktop', 'mobile' ),
        ),
+       // This is for analytics code that is meant to load on all page views 
for both
+       // logged in and anonymous users.  It is intended that this module 
remain
+       // permanently (even if empty, to avoid errors on cached pages), and 
future code
+       // meeting this criteria be added to it.
+       'ext.wikimediaEvents' => array(
+               'scripts' => array(
+                       'ext.wikimediaEvents.sendBeacon.js',
+               ),
+               'localBasePath' => __DIR__ . '/modules',
+               'remoteExtPath' => 'WikimediaEvents/modules',
+               'targets' => array( 'desktop', 'mobile' ),
+       ),
 );
 
 $wgVisualEditorPluginModules[] = 'ext.wikimediaEvents.ve';
diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index c0bb539..731dd85 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -25,11 +25,15 @@
 
        /**
         * Adds 'ext.wikimediaEvents.deprecate' logging module for logged-in 
users.
+        *
+        * Adds 'ext.wikimediaEvents' 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' );
+
                $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..57c9724
--- /dev/null
+++ b/modules/ext.wikimediaEvents.sendBeacon.js
@@ -0,0 +1,30 @@
+( function ( mw, $ ) {
+       var odds, isBeaconAvailable, baseEvent, imgEvent, beaconEvent;
+
+       odds = 0.0001; // 1 in 10,000 chance
+
+       if ( Math.random() < odds ) {
+               mw.loader.using( [ 'mediawiki.user', 
'schema.SendBeaconReliability' ] ).done( function () {
+                       isBeaconAvailable = !!navigator.sendBeacon;
+
+                       baseEvent = {
+                               browserSupportsSendBeacon: isBeaconAvailable,
+                               logId: mw.user.generateRandomSessionId()
+                       };
+
+                       imgEvent = $.extend( { method: 'logEvent' }, baseEvent 
);
+
+                       // We always log via logEvent (to at least get data on 
user agent and whether
+                       // it supports sendBeacon).  If sendBeacon is 
available, we also log via
+                       // logPersistentEvent.  Since logId is the same for 
both events, this allows
+                       // us to determine how common it is to have logEvent 
without
+                       // logPersistentEvent, or vice-versa.
+                       mw.eventLog.logEvent( 'SendBeaconReliability', imgEvent 
);
+
+                       if ( isBeaconAvailable ) {
+                               beaconEvent = $.extend( { method: 
'logPersistentEvent' }, baseEvent );
+                               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: merged
Gerrit-Change-Id: I07ecbde39b5f1ce640f40430b198f8c160a89d13
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Halfak <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Nuria <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to