-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathBeforeTrackPageViewObserver.php
87 lines (77 loc) · 2.48 KB
/
BeforeTrackPageViewObserver.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Copyright 2016-2018 Henrik Hedelund
* Copyright 2020 Falco Nogatz
*
* This file is part of Chessio_Matomo.
*
* Chessio_Matomo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chessio_Matomo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Chessio_Matomo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chessio\Matomo\Observer;
use Magento\Framework\Event\ObserverInterface;
/**
* Observer for `matomo_track_page_view_before'
*
*/
class BeforeTrackPageViewObserver implements ObserverInterface
{
/**
* Matomo data helper
*
* @var \Chessio\Matomo\Helper\Data
*/
protected $_dataHelper;
/**
* Constructor
*
* @param \Chessio\Matomo\Helper\Data $dataHelper
*/
public function __construct(\Chessio\Matomo\Helper\Data $dataHelper)
{
$this->_dataHelper = $dataHelper;
}
/**
* Push additional actions to tracker before `trackPageView' is added
*
* @param \Magento\Framework\Event\Observer $observer
* @return \Chessio\Matomo\Observer\BeforeTrackPageViewObserver
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$tracker = $observer->getEvent()->getTracker();
/** @var \Chessio\Matomo\Model\Tracker $tracker */
$this->_pushLinkTracking($tracker);
return $this;
}
/**
* Push link tracking options to given tracker
*
* @param \Chessio\Matomo\Model\Tracker $tracker
* @return \Chessio\Matomo\Observer\BeforeTrackPageViewObserver
*/
protected function _pushLinkTracking(\Chessio\Matomo\Model\Tracker $tracker)
{
if ($this->_dataHelper->isContainerEnabled()) {
return $this;
}
if ($this->_dataHelper->isLinkTrackingEnabled()) {
$tracker->enableLinkTracking(true);
$delay = $this->_dataHelper->getLinkTrackingDelay();
if ($delay > 0) {
$tracker->setLinkTrackingTimer($delay);
}
}
return $this;
}
}