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

Change subject: Story 1301: Measure infobox view time
......................................................................


Story 1301: Measure infobox view time

Use setInterval to avoid having to deal with debouncing
scroll events and effecting performance

Turn off by default (to be enabled by config variable)

Change-Id: I88998f2e96a48822183d6adfce97f5eccf4330a1
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/Resources.php
M includes/skins/SkinMobile.php
A javascripts/loggingSchemas/MobileWebInfobox.js
M javascripts/specials/uploads.js
6 files changed, 98 insertions(+), 0 deletions(-)

Approvals:
  JGonera: Looks good to me, approved
  Awjrichards: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/MobileFrontend.php b/MobileFrontend.php
index baff8f7..e4e81e8 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -423,3 +423,9 @@
  * on small screens
  */
 $wgMFDeviceWidthMobileSmall = 280;
+
+/**
+ * Temporary boolean variable to control EventLogging of viewing infoboxes 
(see loggingSchemas/MobileWebInfobox)
+ * @var bool
+ */
+$wgMFInfoboxLogging = false;
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 8cdae2c..eed8067 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -678,6 +678,10 @@
                                'schema' => 'MobileWebClickTracking',
                                'revision' => 5929948,
                        ),
+                       'schema.MobileWebInfobox' => array(
+                               'schema' => 'MobileWebInfobox',
+                               'revision' => 6221064,
+                       ),
                );
 
                if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
diff --git a/includes/Resources.php b/includes/Resources.php
index 34813fe..6cc16f5 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -74,6 +74,15 @@
        ),
 
        // EventLogging
+       'mobile.infoboxTracking' => $wgMFMobileResourceBoilerplate + array(
+               'dependencies' => array(
+                       'mobile.startup',
+               ),
+               'scripts' => array(
+                       'javascripts/loggingSchemas/MobileWebInfobox.js',
+               ),
+       ),
+
        'mobile.loggingSchemas' => $wgMFMobileResourceBoilerplate + array(
                'dependencies' => array(
                        'mobile.startup',
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index a8645cc..dedcaf2 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -131,6 +131,7 @@
        }
 
        public function getDefaultModules() {
+               global $wgMFInfoboxLogging;
                $out = $this->getOutput();
                $modules = parent::getDefaultModules();
 
@@ -148,6 +149,10 @@
                                'schema.MobileWebCta',
                                'schema.MobileWebClickTracking',
                        );
+                       if ( $wgMFInfoboxLogging ) {
+                               $modules['eventlogging'][] = 
'schema.MobileWebInfobox';
+                               $modules['eventlogging'][] = 
'mobile.infoboxTracking';
+                       }
                }
                return $modules;
        }
diff --git a/javascripts/loggingSchemas/MobileWebInfobox.js 
b/javascripts/loggingSchemas/MobileWebInfobox.js
new file mode 100644
index 0000000..2e0e1ac
--- /dev/null
+++ b/javascripts/loggingSchemas/MobileWebInfobox.js
@@ -0,0 +1,71 @@
+( function( M, $ ) {
+
+var $infobox = $( '.infobox' ).eq( 0 ),
+       infoboxTop, infoboxLength, infoboxBottom, interval, logData,
+       viewportHeight = $( window ).height(),
+       scrollingHasCommenced = false,
+       userScrolledToInfobox = false,
+       userScrolledPastInfobox = false,
+       recorded = false;
+
+function attemptLogEvent() {
+       if ( logData['in'] && logData.out && !recorded ) {
+               recorded = true;
+               clearInterval( interval );
+               return M.log( 'MobileWebInfobox', logData );
+       } else {
+               /* Hijack below expects a deferred object. We should only log 
on the first click to MobileWebInfobox
+               In the situation where you click a link in the infobox then 
click another the always handler should
+               still be able to fire so that the link can be navigated to.*/
+               return $.Deferred().resolve();
+       }
+}
+
+function detectInfobox() {
+       var scrollTop = $( 'body' ).scrollTop(),
+               scrollBottom = scrollTop + viewportHeight;
+       if ( scrollTop > 0 && !scrollingHasCommenced ) {
+               scrollingHasCommenced = true;
+               logData.start = new Date().getTime();
+       }
+
+       // The infobox is in view when the top is less than the bottom of the 
screen
+       if ( !userScrolledToInfobox && infoboxTop < scrollBottom ) {
+               userScrolledToInfobox = true;
+               logData['in'] = new Date().getTime();
+       } else if ( userScrolledToInfobox && !userScrolledPastInfobox && 
infoboxBottom < scrollTop ) {
+               userScrolledPastInfobox = true;
+               logData.out = new Date().getTime();
+       }
+       attemptLogEvent();
+}
+
+if ( $infobox.length > 0 ) {
+       infoboxTop = $infobox.offset().top;
+       infoboxLength = $infobox.height();
+       infoboxBottom = infoboxLength + infoboxTop;
+       logData = {
+               wasInteraction: false,
+               width: $( window ).width(),
+               height: $( window ).height(),
+               infoboxLength: infoboxLength,
+               userAgent: navigator.userAgent
+       };
+
+       // When something in infobox is clicked mark interaction
+       $infobox.find( 'a' ).on( 'click', function( ev ) {
+               var href = $( this ).attr( 'href' );
+               ev.preventDefault();
+               logData.out = new Date().getTime();
+               logData.wasInteraction = true;
+               attemptLogEvent().always( function() {
+                       window.location.href = href;
+               } );
+       } );
+       // window.scroll fires far too often and is unperformant to use for 
this sort of thing
+       // http://ejohn.org/blog/learning-from-twitter/
+       // "It’s a very, very, bad idea to attach handlers to the window scroll 
event."
+       interval = setInterval( detectInfobox, 500 );
+}
+
+}( mw.mobileFrontend, jQuery ));
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index d2222cd..929fb1b 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -81,6 +81,9 @@
                        this.$list = this.$( 'ul' );
 
                        this._loadPhotos();
+                       // FIXME: Consider using setInterval instead or some 
sort of dethrottling/debouncing to avoid performance
+                       // degradation
+                       // e.g. 
http://benalman.com/projects/jquery-throttle-debounce-plugin/
                        $( window ).on( 'scroll', $.proxy( this, '_loadPhotos' 
) );
                },
                isEmpty: function() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I88998f2e96a48822183d6adfce97f5eccf4330a1
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to