Gilles has uploaded a new change for review. https://gerrit.wikimedia.org/r/190823
Change subject: Record virtual image views ...................................................................... Record virtual image views Soft-depends on Ie20ed8fc7041e89510a6558d9e2647c67a0a4bbf Bug: T89088 Change-Id: If1459bd9acde8b6e5040afbd89e2ceafc61dedc9 --- M MultimediaViewer.php M MultimediaViewerHooks.php M resources/mmv/logging/mmv.logging.ViewLogger.js 3 files changed, 23 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer refs/changes/23/190823/1 diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 753d80a..adad382 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -117,12 +117,12 @@ $wgMediaViewerImageQueryParameter = false; } -if ( !isset( $wgMediaViewerRecordViewDuration ) ) { +if ( !isset( $wgMediaViewerRecordVirtualViewBeaconURI ) ) { /** - * If set, record the view duration via a HEAD request. - * @var bool + * If set, records a virtual view via the provided beacon URI. + * @var string|bool */ - $wgMediaViewerRecordViewDuration = false; + $wgMediaViewerRecordVirtualViewBeaconURI = false; } $wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n'; diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index dcd8960..1c5ac53 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -150,7 +150,7 @@ $wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor, $wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor, $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter, - $wgMediaViewerRecordViewDuration; + $wgMediaViewerRecordVirtualViewBeaconURI; $vars['wgMultimediaViewer'] = array( 'infoLink' => self::$infoLink, @@ -164,7 +164,7 @@ 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor, 'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor, 'imageQueryParameter' => $wgMediaViewerImageQueryParameter, - 'recordViewDuration' => $wgMediaViewerRecordViewDuration, + 'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI, 'tooltipDelay' => 1000, ); $vars['wgMediaViewer'] = true; diff --git a/resources/mmv/logging/mmv.logging.ViewLogger.js b/resources/mmv/logging/mmv.logging.ViewLogger.js index 205a52b..b2e95db 100644 --- a/resources/mmv/logging/mmv.logging.ViewLogger.js +++ b/resources/mmv/logging/mmv.logging.ViewLogger.js @@ -49,16 +49,16 @@ this.viewDuration = 0; /** - * The image URL to hit with a HEAD request + * The image URL to record a virtual view for * @property {string} */ this.url = ''; /** - * Should the view duration be recorded through a HEAD request - * @property {boolean} + * If set, URI to send the beacon request to in order to record the virtual view + * @property {string} */ - this.shouldRecordViewDuration = config ? config.recordViewDuration : false; + this.recordVirtualViewBeaconURI = config ? config.recordVirtualViewBeaconURI : false; /** * Browser window @@ -112,14 +112,19 @@ this.stopViewDuration(); - if ( this.shouldRecordViewDuration && this.viewDuration > 0 ) { - uri = new mw.Uri( this.url ); - uri.extend( { viewDuration: this.viewDuration } ); + if ( this.recordVirtualViewBeaconURI ) { + uri = new mw.Uri( this.recordVirtualViewBeaconURI ); + uri.extend( { duration: this.viewDuration, + uri: this.url } ); - $.ajax( { - type: 'HEAD', - url: uri.toString() - } ); + try { + navigator.sendBeacon( url ); + } catch ( e ) { + $.ajax( { + type: 'HEAD', + url: uri.toString() + } ); + } mw.log( 'Image has been viewed for ', this.viewDuration ); } @@ -131,7 +136,7 @@ /** * Sets up the view tracking for the current image - * @param {string} url URL of the image to send a HEAD request to + * @param {string} url URL of the image to record a virtual view for */ VL.attach = function ( url ) { var view = this; -- To view, visit https://gerrit.wikimedia.org/r/190823 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If1459bd9acde8b6e5040afbd89e2ceafc61dedc9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits