Page MenuHomePhabricator

Enable analytics instruments to subscribe to thanks (giving and receiving)
Closed, ResolvedPublic

Description

Slack thread: https://wikimedia.slack.com/archives/C06M4A3SYMQ/p1788385976290989

We need a way for experiments in Test Kitchen to send thanks_given and thanks_received events to enable calculation of an engagement metric.

There are two approaches:

Notes

@Mooeypoo mentioned:

https://github.com/wikimedia/mediawiki-extensions-Thanks/blob/master/includes/Api/ApiCoreThank.php#L231 <-- probably best to insert this here, this seems to be the place a "thank" notification is created and a log is made.

However, we should not be partially instrumenting experiments in the Thanks extension code. It would be best if there was a hook (e.g. onThanksLogEntryInsertion) that would allow us to keep DE1.2 experiment instrumentation contained to WikimediaEvents extension.

As @phuedx said:

Updating MediaWiki\Extension\Thanks\Storage\LogStore to run a hook post log entry insertion would keep the domain logic and any instrumentation cleanly separated

This hook should expose two users: the thanker (the current user) and the thankee (the recipient of the thanks). We would then be able to leverage T436960: Allow sending experiment events and looking up experiment enrollment for another user to initialize two experiment managers – one for each of those users – and produce those events if the thanker and/or the recipient are enrolled in an active experiment.

For example, in /includes/WikimediaEventsHooks.php:

public function onThanksLogEntryInsertion( $thanker, $thankee ) {
  $experimentManager1 = $this->experimentManagerFactory->newForUser( $thanker );
  $experiment1 = $experimentManager1->getExperiment( 'my-experiment' );
  $experiment1->send( 'thanks_given' );
  $experimentManager2 = $this->experimentManagerFactory->newForUser( $thankee );
  $experiment2 = $experimentManager2->getExperiment( 'my-experiment' );
  $experiment2->send( 'thanks_received' );
}
NOTE: The example code is for a Hook-based approach, but would be similar if implemented with a DomainEvents + PubSub model.

Acceptance criteria

  • A way for a TK experiment instrumented in WikimediaEvents (or any other extension) to send thanks_given and thanks_received analytics events when one user thanks another

Related Objects

Event Timeline

In a related thread about responding to user creating or registering for an event, @Ottomata mentioned:

you'd create a listener function that would be called whenever that happens.  CampaignEvents (is that the correct extension?) would implement and fire the DomainEvent, you'd just implement the listener. in WikimediaEvents  PubSub FTW!
You can do the same with hooks, but using hooks for this use case is basically deprecated at this point.  Many disadvantages.  As long as you aren't trying to return anything to the caller (which Hooks can let you do), DomainEvents are probably superior

So maybe this task should be about adding a Thanks DomainEvent?

@phuedx: Do you concur with Andrew's recommendation of using DomainEvents? Would that be a better approach for the use case in this task?

Oh wow. We should sync up here. T433983: Make the AQS endpoints more usable for the ImpactModule extension is asking for a Thanks data product in AQS. In the Prep Pantry intake doc, we are asking Impact Module folks to instrument the Thanks extension so we can get the data.

cc @Snwachukwu @GGoncalves-WMF .

Oooh, yeah it would be awesome to have this solution (regardless of whether it's Hook-based or DomainEvents-based) so that we could have Experiments and a product health Instrument all using it to produce the desired analytics events.

mpopov renamed this task from Post log entry insertion hook for Thanks to Enable analytics instruments to subscribe to thanks (giving and receiving).Sep 4 2026, 7:12 PM
mpopov updated the task description. (Show Details)

Updated title, description, and AC to be like T437070: Enable analytics instruments to subscribe to event creation and participant registration – focused on outcome, less prescriptive of how that outcome should be achieved

@phuedx: Do you concur with Andrew's recommendation of using DomainEvents? Would that be a better approach for the use case in this task?

Yes 👍

In the Prep Pantry intake doc, we are asking Impact Module folks to instrument the Thanks extension so we can get the data.

Yep, and good to see that this will also help TK. cc @DMburugu and @Urbanecm_WMF for visibility.

I think the tracking ticket for the instrumentation is T71804: Thanks: add instrumentation to Thanks so I'm adding this as a child ticket to represent that it blocks this one.

I'd like to discuss if we want/can use the same emitted events as the data sources for both purposes: analytics & product API (timeseries of thanks counts). Data reusability FTW! Perhaps we don't want to do this (I can see why), but I'd prefer if we did!

Who should be working on this? I am not sure the connection team has background knowledge to work on this. I'll talk to @OBenhmida. As always, take things with a grain of salt. I could be wrong about this! ;)

I'd like to discuss if we want/can use the same emitted events as the data sources for both purposes: analytics & product API (timeseries of thanks counts)

We in DPE are hoping to discuss this next week and, assuming the answer to this is "yes", we'll give the Growth team some guidance on adding this instrumentation and it will happen in the context of DE1.3.10, primarily to enable the product API use case. If the answer is "no" -- that is, product API and TK should follow different integration paths --, then we'll at least have better guidance on how it should all fit together, but we'll need to talk about who-does-what for this ticket.

Change #1343609 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/extensions/Thanks@master] Emit a domain event upon thanking

https://gerrit.wikimedia.org/r/1343609

After discussion with the Growth team, this is currently blocked until the requirements of the instrument are refined (see e.g. T438493).

Hi @GGoncalves-WMF and @mpopov,

This work got to us as Mikhail is working on DE1.2.2 Enable metrics for motivational moments in Test Kitchen.

I do not know how this work intersects with what you are trying to do in DE1.3.10 and if this needs to block like @Daimona is suggesting above.

I will leave you all to discuss this.

Yes, please hold off on this for a couple of days if possible. Mikhail, myself and a couple of people from Data Engineering will meet on Thursday to work out what recommendation to give you.

At a high level, the intersection is that both this ticket and DE1.3.10 require propagating Thanks data to the Data Lake for different purposes. We want to find out whether we can advance those two purposes at once with a single patch.

Sounds good. Let us know, either the connection team can continue on this or the growth team. Ping @DMburugu or I.

(By the way the relationship was inverted, I fixed it. This enables T71804, not the other way around.)

Okay so we came to a shared understanding that we will have different instruments – individual experiments for DE 1.2 and, separately, production data for Thanks-based data products in Home, etc. – both subscribing to the Thanks domain events that will be emitted per this task.

In other words, this work is not blocked by anything and in fact unblocks downstream instrumentation.

Sounds good, I'll move it back to code reviews (instead of blocked)
cc: @Daimona

Change #1343609 merged by jenkins-bot:

[mediawiki/extensions/Thanks@master] Emit a domain event upon thanking

https://gerrit.wikimedia.org/r/1343609

Change #1351354 had a related patch set uploaded (by Ottomata; author: Ottomata):

[mediawiki/extensions/Thanks@master] Rename UserThank to UserThanked event

https://gerrit.wikimedia.org/r/1351354

Change #1351354 merged by jenkins-bot:

[mediawiki/extensions/Thanks@master] Rename UserThank to UserThanked event

https://gerrit.wikimedia.org/r/1351354