Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialMentorDashboardLogger
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 log
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace GrowthExperiments\EventLogging;
4
5use MediaWiki\Extension\EventLogging\EventLogging;
6use MediaWiki\Request\WebRequest;
7use MediaWiki\User\UserIdentity;
8use MediaWiki\WikiMap\WikiMap;
9
10class SpecialMentorDashboardLogger {
11
12    /** @var string Versioned schema URL for $schema field */
13    private const SCHEMA_VERSIONED = '/analytics/mediawiki/mentor_dashboard/visit/1.1.0';
14
15    /** @var string Stream name for EventLogging::submit */
16    private const STREAM = 'mediawiki.mentor_dashboard.visit';
17
18    private string $pageviewToken;
19    private UserIdentity $user;
20    private WebRequest $request;
21    private bool $isMobile;
22
23    /**
24     * @param string $pageviewToken
25     * @param UserIdentity $user
26     * @param WebRequest $request
27     * @param bool $isMobile
28     */
29    public function __construct(
30        string $pageviewToken,
31        UserIdentity $user,
32        WebRequest $request,
33        bool $isMobile
34    ) {
35        $this->pageviewToken = $pageviewToken;
36        $this->user = $user;
37        $this->request = $request;
38        $this->isMobile = $isMobile;
39    }
40
41    /**
42     * @return void
43     */
44    public function log() {
45        $referer = $this->request->getHeader( 'REFERER' );
46        $event = [
47            '$schema' => self::SCHEMA_VERSIONED,
48            'wiki_db' => WikiMap::getCurrentWikiId(),
49            'user_id' => $this->user->getId(),
50            'is_mobile' => $this->isMobile,
51            'pageview_token' => $this->pageviewToken,
52        ];
53        $event['referer_route'] = $this->request->getVal(
54            'source',
55            // If there is no referer header and no source param, then assume the user went to the
56            // page directly from their browser history/bookmark/etc.
57            $referer ? 'other' : 'direct'
58        );
59        EventLogging::submit(
60            self::STREAM,
61            $event
62        );
63    }
64}