From a6a06f70bf70b535c8a47f61935f1ddc29b6001e Mon Sep 17 00:00:00 2001 From: Marcel Ruiz Forns Date: Wed, 28 Apr 2021 16:28:11 +0200 Subject: [PATCH] Move VirtualPageViews back to mw.track Use mw.track instead of dedicated tracker for VirtualPageViews. This way we can migrate it to the new Event Platform client. The new client does not observe DNT, which was the reason this instrument was moved to a dedicated tracker on the first place. Bug: T279382 Change-Id: I8bb515eab337ffed686ba7522bc6153cfdd8ca8d --- resources/dist/index.js | Bin 45174 -> 44677 bytes resources/dist/index.js.map.json | Bin 215056 -> 210840 bytes src/changeListeners/pageviews.js | 25 ++-- src/getPageviewTracker.js | 111 ---------------- src/index.js | 20 +-- .../changeListeners/pageviews.test.js | 56 +++++---- tests/node-qunit/getPageviewTracker.test.js | 119 ------------------ 7 files changed, 56 insertions(+), 275 deletions(-) delete mode 100644 src/getPageviewTracker.js delete mode 100644 tests/node-qunit/getPageviewTracker.test.js diff --git a/resources/dist/index.js b/resources/dist/index.js index a735a7088a31335da7e9c67ed721a0a861b35cee..9e6c33e1f5d108b8d6fd795da54d16bb6f950c9b 100644 GIT binary patch delta 932 zcmZvaOK4L;6o$F6O7VeKYpKsBDGhgU9Bio|34={*Qd?>gYoG)v;ofAD+W9yf5vjjMqsMm(W+|(?U6@0sJ?!EXy6slb?E?UI@M^w9;+m~9Vz5%! z6p4-BckGhl4VIP?dRn8szD4T&#Z!y zV(S}!Kx6-xykE>d_V4iDQvY`_RompOb$N@5=^kXX8=q#h2Tw5Ci^Ghb2xJ^1Woz7U zkAeT5B_-hTy=f6f`2IU-5ZtpTnol!?uuUxZ^58IBncdPnu>lUjt-kGU?D5EkFD!7N zK80foJ5(bno-c5V;R3v!_3YDWQWox0+{kEIgfsM<2&Y743tHy z@+9(GaAWSI;IHP6Z}1CszHMF?d~$wT)Ljehd$M%&Z{<9dIRqB^Bo3Ds`dm2*!AcwS zRa#(eVWugMa1lO{Rycas3$H8tx2_ust)F|=6sPhS{HQ$HS;8BR5gx0(c;J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-M%C$7C;4fVi zv(h$+=h*7=W4(K>dsA>@kV#kDW746<`0qvr<;eE{4Ql(oIH=jPa3qjY{R1WRW8rzX T!*6~6O$VO(wd>yWwu%1+^Q|j^ diff --git a/src/changeListeners/pageviews.js b/src/changeListeners/pageviews.js index a0e799a84..c6769cb6e 100644 --- a/src/changeListeners/pageviews.js +++ b/src/changeListeners/pageviews.js @@ -17,20 +17,21 @@ export default function pageviews( boundActions, pageviewTracker ) { return ( oldState, newState ) => { - let page; + let page, pageview; if ( newState.pageviews && newState.pageviews.pageview && newState.pageviews.page ) { page = newState.pageviews.page; - pageviewTracker( 'event.VirtualPageView', $.extend( {}, - { - /* eslint-disable camelcase */ - source_page_id: page.id, - source_namespace: page.namespaceId, - source_title: page.title, - source_url: page.url - /* eslint-enable camelcase */ - }, - newState.pageviews.pageview ) - ); + pageview = newState.pageviews.pageview; + pageviewTracker( 'event.VirtualPageView', { + /* eslint-disable camelcase */ + source_page_id: page.id, + source_namespace: page.namespaceId, + source_title: mw.Title.newFromText( page.title ).getPrefixedDb(), + source_url: page.url, + page_id: pageview.page_id, + page_namespace: pageview.page_namespace, + page_title: mw.Title.newFromText( pageview.page_title ).getPrefixedDb() + /* eslint-enable camelcase */ + } ); // Clear the pageview now its been logged. boundActions.pageviewLogged(); } diff --git a/src/getPageviewTracker.js b/src/getPageviewTracker.js deleted file mode 100644 index 9f0554018..000000000 --- a/src/getPageviewTracker.js +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @module getPageviewTracker - */ - -/** - * @typedef {Object} MwCodeLoader - * - * Loads code from the server to the client on demand. - * - * @param {Array} dependencies to load - * @return {JQuery.Deferred} resolving when the code is loaded and - * can be used by the client. - * - * @global - */ - -/** - * Convert the first letter of a string to uppercase. - * - * @param {string} word - * @return {string} - */ -function titleCase( word ) { - return word[ 0 ].toUpperCase() + word.slice( 1 ); -} - -/** - * Truncates a string to a maximum length based on its URI encoded value. - * - * @param {string} sourceUrl source string - * @param {number} maxLength maximum length - * @return {string} string is returned in the same encoding as the input - */ -function limitByEncodedURILength( sourceUrl, maxLength ) { - let truncatedUrl = ''; - - sourceUrl.split( '' ).every( ( char ) => { - return ( encodeURIComponent( truncatedUrl + char ).length < maxLength ) ? - ( truncatedUrl += char ) : - false; - } ); - return truncatedUrl; -} - -/** - * Convert Title properties into mediawiki canonical form - * and limit the length of source_url. - * - * @param {Object} eventData - * @return {Object} - */ -function prepareEventData( eventData ) { - const data = eventData; - /* eslint-disable camelcase */ - data.source_title = mw.Title.newFromText( eventData.source_title ) - .getPrefixedDb(); - data.page_title = mw.Title.newFromText( eventData.page_title ) - .getPrefixedDb(); - // prevent source_url from exceeding varnish max-url size - T196904 - data.source_url = limitByEncodedURILength( eventData.source_url, 1000 ); - - /* eslint-enable camelcase */ - return data; -} - -/** - * Gets the appropriate analytics event tracker for logging virtual pageviews. - * Note this bypasses EventLogging in order to track virtual pageviews - * for pages where the DNT header (do not track) has been added. - * This is explained in https://phabricator.wikimedia.org/T187277. - * - * @param {Object} config - * @param {MwCodeLoader} loader that can source code that obeys the - * EventLogging api specification. - * @param {Function} trackerGetter when called returns an instance - * of MediaWiki's EventLogging client - * @param {Function} sendBeacon see - * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon - * @return {EventTracker} - */ -function getPageviewTracker( config, loader, trackerGetter, sendBeacon ) { - const pageviewTracker = function ( topic, eventData ) { - const schema = titleCase( topic.slice( topic.indexOf( '.' ) + 1 ) ); - const dependencies = [ 'ext.eventLogging' ]; - return loader( dependencies ).then( function () { - const evLog = trackerGetter(); - const payload = evLog.prepare( schema, prepareEventData( eventData ) ); - const url = evLog.makeBeaconUrl( payload ); - sendBeacon( url ); - } ); - }; - return config.get( 'wgPopupsVirtualPageViews' ) ? pageviewTracker : () => {}; -} - -/** - * Gets a function that can asynchronously transfer a small amount of data - * over HTTP to a web server. - * - * @param {Window.Navigator} navigatorObj - * @return {Function} - */ -function getSendBeacon( navigatorObj ) { - return navigatorObj.sendBeacon ? - navigatorObj.sendBeacon.bind( navigatorObj ) : - ( url ) => { - document.createElement( 'img' ).src = url; - }; -} - -export { getSendBeacon, limitByEncodedURILength }; -export default getPageviewTracker; diff --git a/src/index.js b/src/index.js index b4d3740ca..bd517e983 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,6 @@ import changeListeners from './changeListeners'; import * as actions from './actions'; import reducers from './reducers'; import createMediaWikiPopupsObject from './integrations/mwpopups'; -import getPageviewTracker, { getSendBeacon } from './getPageviewTracker'; import { previewTypes, getPreviewType } from './preview/model'; import isReferencePreviewsEnabled from './isReferencePreviewsEnabled'; import setUserConfigFlags from './setUserConfigFlags'; @@ -68,6 +67,18 @@ function getStatsvTracker( user, config, experiments ) { return isStatsvEnabled( user, config, experiments ) ? mw.track : () => {}; } +/** + * Gets the appropriate analytics event tracker for logging virtual pageviews. + * + * @param {Object} config + * @return {EventTracker} + */ +function getPageviewTracker( config ) { + return config.get( 'wgPopupsVirtualPageViews' ) ? mw.track : () => { + // NOP + }; +} + /** * Gets the appropriate analytics event tracker for logging EventLogging events * via [the "EventLogging subscriber" analytics event protocol][0]. @@ -173,12 +184,7 @@ function registerChangeListeners( settingsDialog = createSettingsDialogRenderer( mw.config ), experiments = createExperiments( mw.experiments ), statsvTracker = getStatsvTracker( mw.user, mw.config, experiments ), - // Virtual pageviews are always tracked. - pageviewTracker = getPageviewTracker( mw.config, - mw.loader.using, - () => mw.eventLog, - getSendBeacon( window.navigator ) - ), + pageviewTracker = getPageviewTracker( mw.config ), eventLoggingTracker = getEventLoggingTracker( mw.user, mw.config, diff --git a/tests/node-qunit/changeListeners/pageviews.test.js b/tests/node-qunit/changeListeners/pageviews.test.js index b3661b89c..afb4b3989 100644 --- a/tests/node-qunit/changeListeners/pageviews.test.js +++ b/tests/node-qunit/changeListeners/pageviews.test.js @@ -1,11 +1,22 @@ import pageviews from '../../../src/changeListeners/pageviews'; const REFERRER = 'https://en.m.wikipedia.org/wiki/Kittens', - page = { - namespaceId: 1, - id: 42, - title: 'Kittens', - url: REFERRER + newState = { + pageviews: { + page: { + id: 42, + namespaceId: 1, + title: 'Kittens', + url: REFERRER + }, + pageview: { + /* eslint-disable camelcase */ + page_id: 43, + page_namespace: 1, + page_title: 'Rainbows' + /* eslint-enable camelcase */ + } + } }; QUnit.module( 'ext.popups/pageviews', { @@ -19,27 +30,17 @@ QUnit.module( 'ext.popups/pageviews', { this.boundActions, this.pageviewTracker ); + + // Stub internal usage of mw.Title.newFromText + mw.Title.newFromText = ( str ) => { + return { + getPrefixedDb: () => { return str; } + }; + }; } } ); -function createState( title ) { - return title ? { - pageviews: { - page, - pageview: { - page_title: title // eslint-disable-line camelcase - } - } - } : { - pageviews: { - page, - pageview: undefined - } - }; -} QUnit.test( 'it should log the queued event', function ( assert ) { - const newState = createState( 'Rainbows' ); - this.changeListener( undefined, newState ); assert.ok( @@ -47,11 +48,13 @@ QUnit.test( 'it should log the queued event', function ( assert ) { 'event.VirtualPageView', { /* eslint-disable camelcase */ - page_title: 'Rainbows', - source_url: REFERRER, source_page_id: 42, source_namespace: 1, - source_title: 'Kittens' + source_title: 'Kittens', + source_url: REFERRER, + page_id: 43, + page_namespace: 1, + page_title: 'Rainbows' /* eslint-enable camelcase */ } ), @@ -64,7 +67,8 @@ QUnit.test( 'it should log the queued event', function ( assert ) { } ); QUnit.test( 'it should not log something that is not a pageview', function ( assert ) { - const newState = createState(); + const noPageviewState = $.extend( {}, newState ); + delete noPageviewState.pageviews.pageview; this.changeListener( undefined, newState ); diff --git a/tests/node-qunit/getPageviewTracker.test.js b/tests/node-qunit/getPageviewTracker.test.js deleted file mode 100644 index 20f6ce798..000000000 --- a/tests/node-qunit/getPageviewTracker.test.js +++ /dev/null @@ -1,119 +0,0 @@ -import getPageviewTracker, { getSendBeacon, limitByEncodedURILength } from '../../src/getPageviewTracker'; - -QUnit.module( 'ext.popups#getPageviewTracker', { - beforeEach() { - this.makeBeaconUrl = this.sandbox.stub(); - this.prepare = this.sandbox.stub(); - this.trackerGetter = () => ( { makeBeaconUrl: this.makeBeaconUrl, - prepare: this.prepare } ); - - this.loader = () => Promise.resolve(); - - this.Title = { - newFromText: this.sandbox.stub() - }; - mw.Title = this.Title; - }, - afterEach() { - mw.Title = null; - } -} ); - -const enabledConfig = { - get: () => true -}; - -QUnit.test( 'getPageviewTracker', function ( assert ) { - const loader = this.sandbox.stub(); - const sendBeacon = this.sandbox.stub(); - - /* eslint-disable camelcase */ - const data = { - page_title: 'Test title', - source_title: 'Source title', - page_namespace: 1, - source_url: 'http://some/url' - }; - const eventData = { - page_title: 'Test_title', - source_title: 'Source_title', - page_namespace: 1, - source_url: 'http://some/url' - }; - this.Title.newFromText.withArgs( data.page_title ).returns( { - getPrefixedDb: () => eventData.page_title - } ); - this.Title.newFromText.withArgs( data.source_title ).returns( { - getPrefixedDb: () => eventData.source_title - } ); - /* eslint-enable camelcase */ - const tracker = getPageviewTracker( enabledConfig, - loader, this.trackerGetter, sendBeacon ); - - loader.resolves(); - return tracker( 'event.VirtualPageView', data ).then( () => { - assert.strictEqual( loader.callCount, 1, 'loader called once' ); - assert.ok( loader.calledWith( [ 'ext.eventLogging' ] ), - 'appropriate code is loaded' ); - assert.strictEqual( - this.Title.newFromText.callCount, - 2, - 'The title factory was invoked twice.' - ); - assert.ok( this.prepare.calledWith( 'VirtualPageView', eventData ), - 'mw.eventLog.prepare called appropriately' ); - assert.strictEqual( this.makeBeaconUrl.callCount, 1, - 'makeBeacon called with result of prepare' ); - assert.strictEqual( sendBeacon.callCount, 1, - 'sendBeacon called with url from makeBeaconUrl' ); - } ); -} ); - -QUnit.test( 'getSendBeacon', function ( assert ) { - let success = false; - const navtr = { - successful: true, - sendBeacon: function () { - // This local variable helps test context. Don't refactor. - success = this.successful; - } - }; - const sendBeacon = getSendBeacon( navtr ); - sendBeacon(); - assert.ok( success, 'native sendBeacon is used when available and run in appropriate context' ); -} ); - -QUnit.test( 'getSendBeacon (fallback)', function ( assert ) { - const spy = this.sandbox.spy( document, 'createElement' ); - const sendBeacon = getSendBeacon( {} ); - sendBeacon(); - assert.strictEqual( spy.callCount, 1, 'an img element is used as fallback' ); -} ); - -QUnit.test( 'limitByEncodedURILength', function ( assert ) { - const shortUrl = 'https://en.wikipedia.org/wiki/banana', - longEncodedUrl = 'https://ka.wikipedia.org/wiki/%E1%83%95%E1%83%98%E1%83%99%E1%83%98%E1%83%9E%E1%83%94%E1%83%93%E1%83%98%E1%83%90:%E1%83%95%E1%83%98%E1%83%99%E1%83%98%E1%83%A1_%E1%83%A3%E1%83%A7%E1%83%95%E1%83%90%E1%83%A0%E1%83%A1_%E1%83%AB%E1%83%94%E1%83%92%E1%83%9A%E1%83%94%E1%83%91%E1%83%98/%E1%83%AB%E1%83%94%E1%83%92%E1%83%9A%E1%83%94%E1%83%91%E1%83%98%E1%83%A1_%E1%83%A1%E1%83%98%E1%83%90/%E1%83%99%E1%83%90%E1%83%AE%E1%83%94%E1%83%97%E1%83%98/%E1%83%A1%E1%83%90%E1%83%92%E1%83%90%E1%83%A0%E1%83%94%E1%83%AF%E1%83%9D%E1%83%A1_%E1%83%9B%E1%83%A3%E1%83%9C%E1%83%98%E1%83%AA%E1%83%98%E1%83%9E%E1%83%90%E1%83%9A%E1%83%98%E1%83%A2%E1%83%94%E1%83%A2%E1%83%98', - randomSequence = 'チプロ للا المتحة Добро пожаловат פעילה למען שוווв ВикипедиюA %20%F0%9F%A4%A8%20 IJ@_#*($PJOWR', - contentRg = new RegExp( limitByEncodedURILength( randomSequence, 326 ) ); - - assert.strictEqual( - limitByEncodedURILength( shortUrl, 1000 ), shortUrl, - 'short url is not truncated' ); - - assert.strictEqual( - encodeURIComponent( - limitByEncodedURILength( longEncodedUrl, 1000 ) - ).length < 1000, true, - 'long url is truncated to the correct length' ); - - assert.strictEqual( - encodeURIComponent( - limitByEncodedURILength( randomSequence, 50 ) - ).length < 50, true, - 'Random string is truncated to the correct length' ); - - assert.strictEqual( - contentRg.test( randomSequence ), true, - 'Truncated string contains the same content as the original' - ); -} );