Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PingRequestProcessor.php « Tracker « Heartbeat « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e45e0c057bdcd5befbb58cd638e23931586501d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Plugins\Heartbeat\Tracker;

use Piwik\Common;
use Piwik\Tracker\Request;
use Piwik\Tracker\RequestProcessor;
use Piwik\Tracker\Visit\VisitProperties;

/**
 * TODO
 */
class PingRequestProcessor extends RequestProcessor
{
    public function processRequestParams(VisitProperties $visitProperties, Request $request)
    {
        if ($this->isPingRequest($request)) {
            // on a ping request that is received before the standard visit length, we just update the visit time w/o adding a new action
            Common::printDebug("-> ping=1 request: we do not track a new action nor a new visit nor any goal.");

            $visitProperties->setRequestMetadata('Actions', 'action', null);
        }
    }

    public function manipulateVisitProperties(VisitProperties $visitProperties, Request $request)
    {
        if ($this->isPingRequest($request)) {
            $visitProperties->setRequestMetadata('Goals', 'someGoalsConverted', false);
            $visitProperties->setRequestMetadata('Goals', 'visitIsConverted', false);
            // TODO: double check: can this be merged w/ setting action to null?

            // When a ping request is received more than 30 min after the last request/ping,
            // we choose not to create a new visit.
            if ($visitProperties->getRequestMetadata('CoreHome', 'isNewVisit')) {
                Common::printDebug("-> ping=1 request: we do _not_ create a new visit.");
                return true; // abort request
            }
        }

        return false;
    }

    private function isPingRequest(Request $request)
    {
        return $request->getParam('ping') == 1;
    }
}