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:
- [[ https://www.mediawiki.org/wiki/Manual:Hooks | Hooks ]] (deprecated?)
- [[ https://www.mediawiki.org/wiki/Manual:Domain_events | DomainEvents ]] (pending confirmation in T437053#12290055 that we can use PubSub in the context of Test Kitchen experiments)
## 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} 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`:
```lang=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