jenkins-bot has submitted this change and it was merged. Change subject: Track geo feature usage ......................................................................
Track geo feature usage Bug: T103017 Change-Id: Ifbc4ebaeb992e417dbe00da198987b0e83cb9a03 --- M WikimediaEvents.php M WikimediaEventsHooks.php A modules/ext.wikimediaEvents.geoFeatures.js 3 files changed, 124 insertions(+), 1 deletion(-) Approvals: Yurik: Looks good to me, approved Jdouglas: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/WikimediaEvents.php b/WikimediaEvents.php index edfe94a..c486d96 100644 --- a/WikimediaEvents.php +++ b/WikimediaEvents.php @@ -40,6 +40,11 @@ */ $wgWMEStatsdBaseUri = false; +/** + * @var bool: Whether geo/maps features specific to large Wikipedias should be tracked + */ +$wgWMETrackGeoFeatures = false; + // Messages $wgMessagesDirs['WikimediaEvents'] = __DIR__ . '/i18n'; @@ -122,6 +127,20 @@ 'mediawiki.user', ), ), + 'schema.GeoFeatures' => array( + 'class' => 'ResourceLoaderSchemaModule', + 'schema' => 'GeoFeatures', + 'revision' => 12518424, + ), + 'ext.wikimediaEvents.geoFeatures' => array( + 'scripts' => array( + 'ext.wikimediaEvents.geoFeatures.js', + ), + 'localBasePath' => __DIR__ . '/modules', + 'remoteExtPath' => 'WikimediaEvents/modules', + 'targets' => array( 'desktop', 'mobile' ), + 'dependencies' => array( 'schema.GeoFeatures' ), + ), ); // Autoloader diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php index d784cdc..8a4f9f4 100644 --- a/WikimediaEventsHooks.php +++ b/WikimediaEventsHooks.php @@ -16,11 +16,15 @@ public static function onBeforePageDisplay( &$out, &$skin ) { $out->addModules( 'ext.wikimediaEvents' ); - global $wgWMEStatsdBaseUri; + global $wgWMEStatsdBaseUri, $wgWMETrackGeoFeatures; if ( $wgWMEStatsdBaseUri !== false ) { $out->addModules( 'ext.wikimediaEvents.statsd' ); } + if ( $wgWMETrackGeoFeatures ) { + $out->addModules( 'ext.wikimediaEvents.geoFeatures' ); + } + $user = $out->getUser(); if ( $user->isLoggedIn() ) { $out->addModules( 'ext.wikimediaEvents.loggedin' ); diff --git a/modules/ext.wikimediaEvents.geoFeatures.js b/modules/ext.wikimediaEvents.geoFeatures.js new file mode 100644 index 0000000..557bf61 --- /dev/null +++ b/modules/ext.wikimediaEvents.geoFeatures.js @@ -0,0 +1,100 @@ +/** + * Track geo/mapping feature usage + * @see https://phabricator.wikimedia.org/T103017 + * @see https://meta.wikimedia.org/wiki/Schema:GeoFeatures + */ +( function( $, mw ) { + // Override hide() to track it + var oldHide = $.fn.hide; + $.fn.hide = function() { + $( this ).trigger( 'hide' ); + return oldHide.apply( this, arguments ); + }; + + /** + * Checks whether given element is part of a title (primary) coordinate + * + * @param {jQuery} $el + * @returns {bool} + */ + function isTitleCoordinate( $el ) { + return $el.is( '#coordinates *' ); + } + + /** + * Returns an unique token identifying current user + * Code borrowed from WikiGrok + * + * @returns {string} + */ + function getToken() { + var cookieName = 'GeoFeaturesUser', + token = mw.cookie.get( cookieName ); + + if ( token ) { + return token; + } + + token = mw.user.generateRandomSessionId(); + + mw.cookie.set( cookieName, token, { + expires: 90 * 24 * 3600 + } ); + + return token; + } + + /** + * Sends tracking information + * + * @param {string} feature Feature name + * @param {string} action Action performed + * @param {bool} titleCoordinate Whether feature is used with the title coordinate + * @param {string|undefined} [url] URL to follow once event has been logged + */ + function track( feature, action, titleCoordinate, url ) { + mw.eventLog.logEvent( 'GeoFeatures', { + 'feature': feature, + 'action': action, + 'titleCoordinate': titleCoordinate, + 'userToken': getToken() + } ); + // If the event was caused by a click on a link, follow this link after a delay to give + // the event time to be logged + if ( url ) { + setTimeout( + function() { + document.location = url; + }, + 200 + ); + } + } + + // Track GeoHack usage + $( 'a[href^=\'//tools.wmflabs.org/geohack/geohack.php\']' ).on( 'click', function( event ) { + var $this = $( this ); + track( 'GeoHack', 'open', isTitleCoordinate( $this ), $this.attr( 'href' ) ); + event.preventDefault(); + } ); + + // Track WikiMiniAtlas usage + $( '.wmamapbutton' ).on( 'click', function() { + var $this = $( this ), + isTitle = isTitleCoordinate( $this ), + $container = $( 'iframe[src^=\'//wma.wmflabs.org/iframe.html\']' ).parent(); + + if ( $container.is( ':visible' ) ) { + track( 'WikiMiniAtlas', 'open', isTitle ); + $container.one( 'hide', function() { + track( 'WikiMiniAtlas', 'close', isTitle ); + } ); + } + } ); + + // Track WIWOSM usage + $( '.osm-icon-coordinates' ).on( 'click', function() { + var mapShown = $( 'iframe#openstreetmap' ).is( ':visible' ); + track( 'WIWOSM', mapShown ? 'open' : 'close', true ); + } ); +}( jQuery, mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/221012 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifbc4ebaeb992e417dbe00da198987b0e83cb9a03 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/WikimediaEvents Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: BBlack <bbl...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Jdouglas <jdoug...@wikimedia.org> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: Yurik <yu...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits