From 3c4f3a0dddc94dc48781b2e35af733793c08427f Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Tue, 9 Jan 2018 16:40:36 +0100 Subject: [PATCH] Send events when user taps download icon To track "download" button interactions we have to notify EventLogging that button was clicked. The easiest approach is to use mw.track() and then in WikimediaEvents subscribe to the `minerva.downloadAsPdf` events and track page impressions. Bug: T181297 Change-Id: Iecbebe37c165dda3f26af47906662f6e5a81321d --- resources/skins.minerva.scripts/DownloadIcon.js | 11 ++++++++--- resources/skins.minerva.scripts/init.js | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/resources/skins.minerva.scripts/DownloadIcon.js b/resources/skins.minerva.scripts/DownloadIcon.js index bbaeda2..753ee9a 100644 --- a/resources/skins.minerva.scripts/DownloadIcon.js +++ b/resources/skins.minerva.scripts/DownloadIcon.js @@ -1,4 +1,4 @@ -( function ( M ) { +( function ( M, track ) { var msg = mw.msg, MAX_PRINT_TIMEOUT = 3000, @@ -47,13 +47,18 @@ function doPrint() { self.timeout = clearTimeout( self.timeout ); + track( 'minerva.downloadAsPDF', { + action: 'callPrint' + } ); window.print(); hideSpinner(); } - // The click handler may be invoked multiple times so if a pending print is occurring // do nothing. if ( !this.timeout ) { + track( 'minerva.downloadAsPDF', { + action: 'fetchImages' + } ); this.showSpinner(); // If all image downloads are taking longer to load then the MAX_PRINT_TIMEOUT // abort the spinner and print regardless. @@ -71,4 +76,4 @@ } ); M.define( 'skins.minerva.scripts/DownloadIcon', DownloadIcon ); -}( mw.mobileFrontend ) ); +}( mw.mobileFrontend, mw.track ) ); diff --git a/resources/skins.minerva.scripts/init.js b/resources/skins.minerva.scripts/init.js index b10229e..327399f 100644 --- a/resources/skins.minerva.scripts/init.js +++ b/resources/skins.minerva.scripts/init.js @@ -1,4 +1,4 @@ -( function ( M, $ ) { +( function ( M, track, $ ) { var config = mw.config, toast = M.require( 'mobile.startup/toast' ), @@ -245,8 +245,11 @@ // left-most in the display. Since we want the download button to be to // the left of the watchstar, we put it after it in the DOM. new DownloadIcon( skin ).$el.insertAfter( '#ca-watch' ); + track( 'minerva.downloadAsPDF', { + action: 'buttonVisible' + } ); } } ); M.define( 'skins.minerva.scripts/overlayManager', overlayManager ); -}( mw.mobileFrontend, jQuery ) ); +}( mw.mobileFrontend, mw.track, jQuery ) );