mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-17 04:43:18 +00:00
Merge "Record virtual image views"
This commit is contained in:
commit
0464c2b9e7
|
@ -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