Jdlrobson has uploaded a new change for review.

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


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, 87 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/86/92986/1

diff --git a/MobileFrontend.php b/MobileFrontend.php
index d4bac31..29aa553 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -415,3 +415,9 @@
  * @var bool
  */
 $wgMFAjaxUploadProgressSupport = false;
+
+/**
+ * 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 d1ec534..0c3354e 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 07e5500..959d87c 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..5cd7b54
--- /dev/null
+++ b/javascripts/loggingSchemas/MobileWebInfobox.js
@@ -0,0 +1,62 @@
+( function( M, $ ) {
+
+var $infobox = $( '.infobox' ).eq( 0 ),
+       infoboxTop, infoboxLength, infoboxBottom, interval, logData,
+       recorded = false;
+
+
+function attemptLogEvent() {
+       if ( logData['in'] && logData.out && !recorded ) {
+               recorded = true;
+               clearInterval( interval );
+               return M.log( 'MobileWebInfobox', logData );
+       } else {
+               // in the case that 2 links are clicked simultaneously
+               return $.Deferred().resolve();
+       }
+}
+
+function detectInfobox() {
+       var scrollTop = document.documentElement.scrollTop ?
+               document.documentElement.scrollTop : document.body.scrollTop;
+
+       if ( scrollTop > 0 && !logData.startScroll ) {
+               logData.start = new Date().getTime();
+       }
+
+       // The infobox is in view when the top is less than the bottom of the 
screen
+       if ( !logData['in'] && infoboxTop < ( scrollTop + logData.height ) ) {
+               logData['in'] = new Date().getTime();
+       } else if ( !logData.out && scrollTop > infoboxBottom ) {
+               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
+       interval = setInterval( detectInfobox, 500 );
+}
+
+}( mw.mobileFrontend, jQuery ));
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index d2222cd..26ae8b6 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -81,6 +81,7 @@
                        this.$list = this.$( 'ul' );
 
                        this._loadPhotos();
+                       // add debouncing
                        $( 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: newchange
Gerrit-Change-Id: I88998f2e96a48822183d6adfce97f5eccf4330a1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to