mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 00:03:56 +00:00
Record virtual image views
Soft-depends on Ie20ed8fc7041e89510a6558d9e2647c67a0a4bbf Bug: T89088 Change-Id: If1459bd9acde8b6e5040afbd89e2ceafc61dedc9
This commit is contained in:
parent
194876ba58
commit
2b1c1b2260
|
@ -117,12 +117,12 @@ if ( !isset( $wgMediaViewerImageQueryParameter ) ) {
|
|||
$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';
|
||||
|
|
|
@ -150,7 +150,7 @@ class MultimediaViewerHooks {
|
|||
$wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor,
|
||||
$wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor,
|
||||
$wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerImageQueryParameter,
|
||||
$wgMediaViewerRecordViewDuration;
|
||||
$wgMediaViewerRecordVirtualViewBeaconURI;
|
||||
|
||||
$vars['wgMultimediaViewer'] = array(
|
||||
'infoLink' => self::$infoLink,
|
||||
|
@ -164,7 +164,7 @@ class MultimediaViewerHooks {
|
|||
'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor,
|
||||
'dimensionSamplingFactor' => $wgMediaViewerDimensionLoggingSamplingFactor,
|
||||
'imageQueryParameter' => $wgMediaViewerImageQueryParameter,
|
||||
'recordViewDuration' => $wgMediaViewerRecordViewDuration,
|
||||
'recordVirtualViewBeaconURI' => $wgMediaViewerRecordVirtualViewBeaconURI,
|
||||
'tooltipDelay' => 1000,
|
||||
);
|
||||
$vars['wgMediaViewer'] = true;
|
||||
|
|
|
@ -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( uri.toString() );
|
||||
} 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;
|
||||
|
|
Loading…
Reference in a new issue