[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-12-08 Thread jenkins-bot (Code Review)
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
(cherry picked from commit 18a0e621b2ab24ddbef977a85aa63ccda5b101b5)
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 51 insertions(+), 0 deletions(-)

Approvals:
  Mattflaschen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index fd0f50c..3e4cfd5 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -53,6 +53,11 @@
'schema' => 'Edit',
'revision' => 10676603,
),
+   '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 000..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

[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-12-08 Thread jenkins-bot (Code Review)
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
(cherry picked from commit 18a0e621b2ab24ddbef977a85aa63ccda5b101b5)
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 51 insertions(+), 0 deletions(-)

Approvals:
  Mattflaschen: Looks good to me, approved
  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 000..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

[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-12-08 Thread Mattflaschen (Code Review)
Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178409

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
(cherry picked from commit 18a0e621b2ab24ddbef977a85aa63ccda5b101b5)
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 51 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents 
refs/changes/09/178409/1

diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index fd0f50c..3e4cfd5 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -53,6 +53,11 @@
'schema' => 'Edit',
'revision' => 10676603,
),
+   '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 000..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, th

[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-12-08 Thread Mattflaschen (Code Review)
Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178408

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
(cherry picked from commit 18a0e621b2ab24ddbef977a85aa63ccda5b101b5)
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
A modules/ext.wikimediaEvents.sendBeacon.js
3 files changed, 51 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents 
refs/changes/08/178408/1

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 000..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, th

[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-12-08 Thread jenkins-bot (Code Review)
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 000..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
+   

[MediaWiki-commits] [Gerrit] Add experiment for testing sendBeacon reliability - change (mediawiki...WikimediaEvents)

2014-11-25 Thread Mattflaschen (Code Review)
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 000..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 

___
MediaWiki