[MediaWiki-commits] [Gerrit] mediawiki...RelatedArticles[wmf/1.30.0-wmf.6]: i13n: Don't sample by pageview

2017-06-27 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/361715 )

Change subject: i13n: Don't sample by pageview
..


i13n: Don't sample by pageview

Currently, the mw.eventLog.Schema class samples per pageview. However,
we expect that if a user is bucketed for a session, then all
EventLogging events logged during that session are in the sample.

Unlike Popups in I4f653bba, the RelatedArticles instrumentation does
rely on another mw.eventLog.Schema behavior: distinguishing between
static and dynamic data. This and the use of mw.eventLog.Schema could be
removed in a follow-on change.

Bug: T167236
Change-Id: I9583cb98264efd7dc46b45bbce5323036a100536
(cherry picked from commit 153573dbe5efd1803452c1f7e48af524af20fc17)
---
M resources/ext.relatedArticles.readMore.eventLogging/index.js
1 file changed, 57 insertions(+), 13 deletions(-)

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



diff --git a/resources/ext.relatedArticles.readMore.eventLogging/index.js 
b/resources/ext.relatedArticles.readMore.eventLogging/index.js
index afe721b..87ec230 100644
--- a/resources/ext.relatedArticles.readMore.eventLogging/index.js
+++ b/resources/ext.relatedArticles.readMore.eventLogging/index.js
@@ -5,9 +5,65 @@
skin = mw.config.get( 'skin' ),
$window = $( window );
 
-   if ( !$.isFunction( navigator.sendBeacon ) ) {
+   /**
+* Gets whether the UA supports [the Beacon API][0].
+*
+* [0]: https://www.w3.org/TR/beacon/
+*
+* @return {boolean}
+*/
+   function supportsBeacon() {
+   return $.isFunction( window.navigator.sendBeacon );
+   }
+
+   /**
+* Gets whether the instrumentation is enabled for the user.
+*
+* We sample at the feature level, not by pageview. If the 
instrumentation is
+* enabled for the user, then it's enabled for the duration of their 
session.
+*
+* @return {boolean}
+*/
+   function isEnabledForCurrentUser() {
+
+   // TODO: Rename this and other instances to bucketingRate.
+   var samplingRate = mw.config.get( 
'wgRelatedArticlesLoggingSamplingRate', 0 );
+
+   if ( !supportsBeacon() ) {
+   return false;
+   }
+
+   return mw.experiments.getBucket( {
+   name: 'ext.relatedArticles.instrumentation',
+   enabled: true,
+   buckets: {
+   control: 1 - samplingRate,
+   A: samplingRate
+   }
+   }, mw.user.sessionId() ) === 'A';
+   }
+
+   if ( !isEnabledForCurrentUser() ) {
return;
}
+
+   // ---
+   // BEGIN INSTRUMENTATION
+   // ---
+
+   schemaRelatedPages = new mw.eventLog.Schema(
+   'RelatedArticles',
+
+   // The instrumentation is enabled for the user's session. DON'T 
SAMPLE AT
+   // THE EVENT LEVEL.
+   1,
+
+   {
+   pageId: mw.config.get( 'wgArticleId' ),
+   skin: ( skin === 'minerva' ) ? skin + '-' + 
mw.config.get( 'wgMFMode' ) : skin,
+   userSessionToken: mw.user.sessionId()
+   }
+   );
 
/**
 * Log when ReadMore is seen by the user
@@ -18,18 +74,6 @@
schemaRelatedPages.log( { eventName: 'seen' } );
}
}
-
-   schemaRelatedPages = new mw.eventLog.Schema(
-   'RelatedArticles',
-   // not sampled if the config variable is not set
-   mw.config.get( 'wgRelatedArticlesLoggingSamplingRate', 0 ),
-   {
-   pageId: mw.config.get( 'wgArticleId' ),
-   skin: ( skin === 'minerva' ) ? skin + '-' + 
mw.config.get( 'wgMFMode' ) : skin,
-   // This should persist for a given user across their 
session.
-   userSessionToken: mw.user.sessionId()
-   }
-   );
 
mw.trackSubscribe( 'ext.relatedArticles.logEnabled', function ( _, data 
) {
schemaRelatedPages.log( {

-- 
To view, visit https://gerrit.wikimedia.org/r/361715
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9583cb98264efd7dc46b45bbce5323036a100536
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: wmf/1.30.0-wmf.6
Gerrit-Owner: Jdlrobson 
Gerrit-Reviewer: Chad 
Gerrit-Reviewer: Phuedx 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...RelatedArticles[wmf/1.30.0-wmf.6]: i13n: Don't sample by pageview

2017-06-27 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361715 )

Change subject: i13n: Don't sample by pageview
..

i13n: Don't sample by pageview

Currently, the mw.eventLog.Schema class samples per pageview. However,
we expect that if a user is bucketed for a session, then all
EventLogging events logged during that session are in the sample.

Unlike Popups in I4f653bba, the RelatedArticles instrumentation does
rely on another mw.eventLog.Schema behavior: distinguishing between
static and dynamic data. This and the use of mw.eventLog.Schema could be
removed in a follow-on change.

Bug: T167236
Change-Id: I9583cb98264efd7dc46b45bbce5323036a100536
(cherry picked from commit 153573dbe5efd1803452c1f7e48af524af20fc17)
---
M resources/ext.relatedArticles.readMore.eventLogging/index.js
1 file changed, 57 insertions(+), 13 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedArticles 
refs/changes/15/361715/1

diff --git a/resources/ext.relatedArticles.readMore.eventLogging/index.js 
b/resources/ext.relatedArticles.readMore.eventLogging/index.js
index afe721b..87ec230 100644
--- a/resources/ext.relatedArticles.readMore.eventLogging/index.js
+++ b/resources/ext.relatedArticles.readMore.eventLogging/index.js
@@ -5,9 +5,65 @@
skin = mw.config.get( 'skin' ),
$window = $( window );
 
-   if ( !$.isFunction( navigator.sendBeacon ) ) {
+   /**
+* Gets whether the UA supports [the Beacon API][0].
+*
+* [0]: https://www.w3.org/TR/beacon/
+*
+* @return {boolean}
+*/
+   function supportsBeacon() {
+   return $.isFunction( window.navigator.sendBeacon );
+   }
+
+   /**
+* Gets whether the instrumentation is enabled for the user.
+*
+* We sample at the feature level, not by pageview. If the 
instrumentation is
+* enabled for the user, then it's enabled for the duration of their 
session.
+*
+* @return {boolean}
+*/
+   function isEnabledForCurrentUser() {
+
+   // TODO: Rename this and other instances to bucketingRate.
+   var samplingRate = mw.config.get( 
'wgRelatedArticlesLoggingSamplingRate', 0 );
+
+   if ( !supportsBeacon() ) {
+   return false;
+   }
+
+   return mw.experiments.getBucket( {
+   name: 'ext.relatedArticles.instrumentation',
+   enabled: true,
+   buckets: {
+   control: 1 - samplingRate,
+   A: samplingRate
+   }
+   }, mw.user.sessionId() ) === 'A';
+   }
+
+   if ( !isEnabledForCurrentUser() ) {
return;
}
+
+   // ---
+   // BEGIN INSTRUMENTATION
+   // ---
+
+   schemaRelatedPages = new mw.eventLog.Schema(
+   'RelatedArticles',
+
+   // The instrumentation is enabled for the user's session. DON'T 
SAMPLE AT
+   // THE EVENT LEVEL.
+   1,
+
+   {
+   pageId: mw.config.get( 'wgArticleId' ),
+   skin: ( skin === 'minerva' ) ? skin + '-' + 
mw.config.get( 'wgMFMode' ) : skin,
+   userSessionToken: mw.user.sessionId()
+   }
+   );
 
/**
 * Log when ReadMore is seen by the user
@@ -18,18 +74,6 @@
schemaRelatedPages.log( { eventName: 'seen' } );
}
}
-
-   schemaRelatedPages = new mw.eventLog.Schema(
-   'RelatedArticles',
-   // not sampled if the config variable is not set
-   mw.config.get( 'wgRelatedArticlesLoggingSamplingRate', 0 ),
-   {
-   pageId: mw.config.get( 'wgArticleId' ),
-   skin: ( skin === 'minerva' ) ? skin + '-' + 
mw.config.get( 'wgMFMode' ) : skin,
-   // This should persist for a given user across their 
session.
-   userSessionToken: mw.user.sessionId()
-   }
-   );
 
mw.trackSubscribe( 'ext.relatedArticles.logEnabled', function ( _, data 
) {
schemaRelatedPages.log( {

-- 
To view, visit https://gerrit.wikimedia.org/r/361715
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9583cb98264efd7dc46b45bbce5323036a100536
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: wmf/1.30.0-wmf.6
Gerrit-Owner: Jdlrobson 
Gerrit-Reviewer: Phuedx 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits