jenkins-bot has submitted this change and it was merged.
Change subject: search satisfaction: Check session is still active after page
load
......................................................................
search satisfaction: Check session is still active after page load
We were only checking if the session was still active when loading the
page. This opens the possibility for users to leave a page open for some
time and keep triggering events (perhaps by opening links in a new tab)
after their session has timed out. This checks session state on each
event rather than only once on page load.
Change-Id: I8155a4c2a985ff03c307b9cd19f28615173298d1
---
M modules/ext.wikimediaEvents.searchSatisfaction.js
1 file changed, 22 insertions(+), 11 deletions(-)
Approvals:
DCausse: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ext.wikimediaEvents.searchSatisfaction.js
b/modules/ext.wikimediaEvents.searchSatisfaction.js
index a2a1435..0605e4b 100644
--- a/modules/ext.wikimediaEvents.searchSatisfaction.js
+++ b/modules/ext.wikimediaEvents.searchSatisfaction.js
@@ -79,8 +79,7 @@
sessionId: 10 * 60 * 1000,
subTest: 10 * 60 * 1000,
token: 24 * 60 * 60 * 1000
- },
- now = new Date().getTime();
+ };
/**
* Generates a cache key specific to this session and key type.
@@ -139,19 +138,19 @@
if ( sessionId === 'rejected' ) {
// User was previously rejected
- return false;
+ return;
}
// If a sessionId exists the user was previously
accepted into the test
if ( !sessionId ) {
if ( !oneIn( sampleSize ) ) {
// user was not chosen in a sampling of
search results
session.set( 'sessionId', 'rejected' );
- return false;
+ return;
}
// User was chosen to participate in the test
and does not yet
// have a search session id, generate one.
if ( !session.set( 'sessionId', randomToken() )
) {
- return false;
+ return;
}
// Assign 50% of users to subTest
@@ -167,9 +166,12 @@
// Unique token per page load to know which events
occured
// within the exact same page.
session.set( 'pageViewId', randomToken() );
-
- return true;
}
+
+ this.isActive = function () {
+ var sessionId = this.get( 'sessionId' );
+ return sessionId && sessionId !== 'rejected';
+ };
this.has = function ( type ) {
return this.get( type ) !== null;
@@ -178,7 +180,8 @@
this.get = function ( type ) {
if ( !state.hasOwnProperty( type ) ) {
if ( ttl.hasOwnProperty( type ) ) {
- var endTime = parseInt( mw.storage.get(
key( type + 'EndTime' ) ), 10 );
+ var endTime = parseInt( mw.storage.get(
key( type + 'EndTime' ) ), 10 ),
+ now = new Date().getTime();
if ( endTime && endTime > now ) {
state[ type ] = mw.storage.get(
key( type ) );
} else {
@@ -195,6 +198,7 @@
this.set = function ( type, value ) {
if ( ttl.hasOwnProperty( type ) ) {
+ var now = new Date().getTime();
if ( !mw.storage.set( key( type + 'EndTime' ),
now + ttl[ type ] ) ) {
return false;
}
@@ -208,12 +212,13 @@
};
this.refresh = function ( type ) {
- if ( ttl.hasOwnProperty( type ) && mw.storage.get( key(
type ) ) !== null ) {
+ if ( this.isActive() && ttl.hasOwnProperty( type ) &&
mw.storage.get( key( type ) ) !== null ) {
+ var now = new Date().getTime();
mw.storage.set( key( type + 'EndTime' ), now +
ttl[ type ] );
}
};
- state.enabled = initialize( this );
+ initialize( this );
return this;
}
@@ -383,6 +388,12 @@
// not get completed before page unload
uniqueId: randomToken()
};
+
+ // Allow checkin events to fire after the session
closes, as those
+ // are still meaningful.
+ if ( action !== 'checkin' && !session.isActive() ) {
+ return;
+ }
lastScrollTop = scrollTop;
@@ -590,7 +601,7 @@
function setup( fn ) {
session = session || new SessionState();
- if ( session.get( 'enabled' ) ) {
+ if ( session.isActive() ) {
initSubTest( session );
fn( session );
}
--
To view, visit https://gerrit.wikimedia.org/r/294067
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8155a4c2a985ff03c307b9cd19f28615173298d1
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits