Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Separate init code path for events
......................................................................

Hygiene: Separate init code path for events

Change-Id: Icb5d0de14924a351a836eb31189956714b4bbcc0
---
M includes/MobileFrontend.hooks.php
M javascripts/loggingSchemas/MobileWebClickTracking.js
A javascripts/loggingSchemas/init.js
3 files changed, 87 insertions(+), 36 deletions(-)


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

diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 10c55ea..f5cc9d7 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -908,6 +908,7 @@
                        'javascripts/loggingSchemas/MobileWebClickTracking.js',
                        'javascripts/loggingSchemas/MobileWebWikiGrok.js',
                        'javascripts/loggingSchemas/MobileWebWikiGrokError.js',
+                       'javascripts/loggingSchemas/init.js',
                );
 
                $wgResourceModules['mobile.loggingSchemas'] = 
$wgMFResourceFileModuleBoilerplate + array(
diff --git a/javascripts/loggingSchemas/MobileWebClickTracking.js 
b/javascripts/loggingSchemas/MobileWebClickTracking.js
index 1b81870..6ebc3fb 100644
--- a/javascripts/loggingSchemas/MobileWebClickTracking.js
+++ b/javascripts/loggingSchemas/MobileWebClickTracking.js
@@ -1,6 +1,17 @@
+/**
+ * Utility library for tracking clicks on certain elements
+ * @class MobileWebClickTracking
+ */
 ( function ( M, $ ) {
-       var s = M.require( 'settings' ), name, href;
+       var s = M.require( 'settings' );
 
+       /**
+        * Track an event and record it
+        *
+        * @method
+        * @param {string} name of click tracking event to log
+        * @param {string} [destination] of the link that has been clicked if 
applicable.
+        */
        function log( name, destination ) {
                var
                        user = M.require( 'user' ),
@@ -17,56 +28,56 @@
                }
                return M.log( 'MobileWebClickTracking', data );
        }
+
+       /*
+        * Using localStorage track an event but delay recording it on the
+        * server until the next page load
+        *
+        * @method
+        * @param {string} name of click tracking event to log
+        * @param {string} href the link that has been clicked.
+        */
        function futureLog( name, href ) {
                s.save( 'MobileWebClickTracking-name', name );
                s.save( 'MobileWebClickTracking-href', href );
        }
 
+       /**
+        * Record a click to a link in the schema
+        *
+        * @method
+        * @param {string} selector of element
+        * @param {string} name unique to this click tracking event that will 
allow you to distinguish
+        *  it from others.
+        */
        function hijackLink( selector, name ) {
                $( selector ).on( 'click', function () {
                        futureLog( name, $( this ).attr( 'href' ) );
                } );
        }
 
-       // Deal with events requested on the preview page
-       name = s.get( 'MobileWebClickTracking-name' );
-       href = s.get( 'MobileWebClickTracking-href' );
-       // Make sure they do not log a second time...
-       if ( name && href ) {
-               s.save( 'MobileWebClickTracking-name', '' );
-               s.save( 'MobileWebClickTracking-href', '' );
-               // Since MobileWebEditing schema declares the dependencies to
-               // EventLogging and the schema we can be confident this will 
always log.
-               log( name, href );
+       /**
+        * Log a past click tracking event to the server.
+        *
+        * @method
+        */
+       function logPastEvent() {
+               var name = s.get( 'MobileWebClickTracking-name' ),
+                       href = s.get( 'MobileWebClickTracking-href' );
+
+               // Make sure they do not log a second time...
+               if ( name && href ) {
+                       s.remove( 'MobileWebClickTracking-name' );
+                       s.remove( 'MobileWebClickTracking-href' );
+                       // Since MobileWebEditing schema declares the 
dependencies to
+                       // EventLogging and the schema we can be confident this 
will always log.
+                       log( name, href );
+               }
        }
 
        M.define( 'loggingSchemas/MobileWebClickTracking', {
                log: log,
+               logPastEvent: logPastEvent,
                hijackLink: hijackLink
-       } );
-
-       // Add EventLogging to hamburger menu
-       $( function () {
-               var $profileLink = $( '#mw-mf-last-modified a' )
-                       .filter( function () {
-                               return $( this ).children().length === 0;
-                       } );
-
-               $( '#mw-mf-main-menu-button' ).on( 'click', function () {
-                       log( 'hamburger' );
-               } );
-
-               hijackLink( '#mw-mf-page-left .icon-home', 'hamburger-home' );
-               hijackLink( '#mw-mf-page-left .icon-random', 'hamburger-random' 
);
-               hijackLink( '#mw-mf-page-left .icon-nearby', 'hamburger-nearby' 
);
-               hijackLink( '#mw-mf-page-left .icon-watchlist', 
'hamburger-watchlist' );
-               hijackLink( '#mw-mf-page-left .icon-settings', 
'hamburger-settings' );
-               hijackLink( '#mw-mf-page-left .icon-uploads', 
'hamburger-uploads' );
-               hijackLink( '#mw-mf-page-left .icon-profile', 
'hamburger-profile' );
-               hijackLink( '#mw-mf-page-left .icon-anon', 'hamburger-login' );
-               hijackLink( '#mw-mf-page-left .icon-secondary-logout', 
'hamburger-logout' );
-               hijackLink( $( '#mw-mf-last-modified a span' ).parent(),
-                       'lastmodified-history' );
-               hijackLink( $profileLink, 'lastmodified-profile' );
        } );
 } )( mw.mobileFrontend, jQuery );
diff --git a/javascripts/loggingSchemas/init.js 
b/javascripts/loggingSchemas/init.js
new file mode 100644
index 0000000..a1c3eef
--- /dev/null
+++ b/javascripts/loggingSchemas/init.js
@@ -0,0 +1,39 @@
+// Add EventLogging to hamburger menu
+( function ( M, $ ) {
+       var MobileWebClickTracking = M.require( 
'loggingSchemas/MobileWebClickTracking' );
+
+       $( function () {
+               var $profileLink = $( '#mw-mf-last-modified a' )
+                       .filter( function () {
+                               return $( this ).children().length === 0;
+                       } );
+
+               $( '#mw-mf-main-menu-button' ).on( 'click', function () {
+                       MobileWebClickTracking.log( 'hamburger' );
+               } );
+
+               MobileWebClickTracking.hijackLink( '.icon-home',
+                       'hamburger-home' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-random',
+                       'hamburger-random' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-nearby',
+                       'hamburger-nearby' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-watchlist',
+                       'hamburger-watchlist' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-settings',
+                       'hamburger-settings' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-uploads',
+                       'hamburger-uploads' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-profile',
+                       'hamburger-profile' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-anon',
+                       'hamburger-login' );
+               MobileWebClickTracking.hijackLink( '#mw-mf-page-left 
.icon-secondary-logout',
+                       'hamburger-logout' );
+               MobileWebClickTracking.hijackLink( $( '#mw-mf-last-modified a 
span' ).parent(),
+                       'lastmodified-history' );
+               MobileWebClickTracking.hijackLink( $profileLink, 
'lastmodified-profile' );
+       } );
+
+       MobileWebClickTracking.logPastEvent();
+} )( mw.mobileFrontend, jQuery );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb5d0de14924a351a836eb31189956714b4bbcc0
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