Page MenuHomePhabricator

logInteraction won't reliably work on links due to use of mw.loader.using
Closed, ResolvedPublic

Description

Given the following code:

$wrapper
	.click( function() {
		// Log the clickthrough
		mw.echo.logInteraction( 'notification-link-click', 'flyout', +data.id, data.type );
	} );
		logInteraction: function ( action, context, eventId, eventType, mobile ) {
			/* .. */
			mw.loader.using( 'ext.eventLogging', function() {
				mw.eventLog.logEvent( 'EchoInteraction', myEvt );
			} );
		},

While eventLog.logEvent is able to asynchronously send a message (using synchronous XHR or sendBeacon), because that method itself is asynchronously loaded via mw.loader.using, the event will not be logged on links because the script execution is terminated when the browser navigates away.

Event Timeline

Krinkle created this task.Jan 6 2015, 10:44 PM
Krinkle raised the priority of this task from to Needs Triage.
Krinkle updated the task description. (Show Details)
Krinkle added a project: Notifications.
Krinkle added subscribers: Krinkle, ori.

I think the report is correct, but EventLogging does not use XHR (synchronous or otherwise). The two underlying methods right now are an image (img src) and sendBeacon.

In T85968#958383, @Mattflaschen wrote:

I think the report is correct, but EventLogging does not use XHR (synchronous or otherwise). The two underlying methods right now are an image (img src) and sendBeacon.

sendBeacon is synchronous from its API surface. This is by design and for this very reason. The request is deferred to another thread by the browser. Thus not subject to script termination.

matthiasmullie triaged this task as Normal priority.Jan 7 2015, 6:46 PM
matthiasmullie added a subscriber: matthiasmullie.
DannyH set Security to None.
In T85968#958383, @Mattflaschen wrote:

I think the report is correct, but EventLogging does not use XHR (synchronous or otherwise). The two underlying methods right now are an image (img src) and sendBeacon.

sendBeacon is synchronous from its API surface. This is by design and for this very reason. The request is deferred to another thread by the browser. Thus not subject to script termination.

Correct. I said it did not use synchronous XMLHttpRequest (XHR) (in fact, it doesn't use XHR at all), not that it didn't use any synchronous methods.

Legoktm moved this task from Backlog to Needs code on the Notifications board.Jul 6 2015, 7:46 AM
Restricted Application added a project: Growth-Team. · View Herald TranscriptApr 2 2019, 3:29 AM
Krinkle closed this task as Resolved.Apr 2 2019, 3:29 AM
Krinkle claimed this task.