Skip to content

Commit

Permalink
Adopt changes made in former fork fnogatz/magento2-matomo (#50)
Browse files Browse the repository at this point in the history
* Update README to reflect new name and location

* Rename "master" branch to "main"

* Rename things from "Piwik" to "Matomo"

* Use "piwik" prefix for settings for compatibility with Henhed_Piwik

* Correct link to composer

* Add compatibility for Magento v2.4
  • Loading branch information
fnogatz authored Apr 29, 2021
1 parent ef9aa2a commit 8c83ed1
Show file tree
Hide file tree
Showing 46 changed files with 707 additions and 725 deletions.
47 changes: 24 additions & 23 deletions Block/Piwik.php → Block/Matomo.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?php
/**
* Copyright 2016-2018 Henrik Hedelund
* Copyright 2020 Falco Nogatz
*
* This file is part of Henhed_Piwik.
* This file is part of Chessio_Matomo.
*
* Henhed_Piwik is free software: you can redistribute it and/or modify
* 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.
*
* Henhed_Piwik is distributed in the hope that it will be useful,
* 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 Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>.
* along with Chessio_Matomo. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Henhed\Piwik\Block;
namespace Chessio\Matomo\Block;

/**
* Piwik page block
* Matomo page block
*
*/
class Piwik extends \Magento\Framework\View\Element\Template
class Matomo extends \Magento\Framework\View\Element\Template
{

/**
Expand All @@ -35,16 +36,16 @@ class Piwik extends \Magento\Framework\View\Element\Template
protected $_jsonEncoder;

/**
* Piwik tracker model
* Matomo tracker model
*
* @var \Henhed\Piwik\Model\Tracker $_tracker
* @var \Chessio\Matomo\Model\Tracker $_tracker
*/
protected $_tracker;

/**
* Piwik data helper
* Matomo data helper
*
* @var \Henhed\Piwik\Helper\Data
* @var \Chessio\Matomo\Helper\Data
*/
protected $_dataHelper = null;

Expand All @@ -53,15 +54,15 @@ class Piwik extends \Magento\Framework\View\Element\Template
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
* @param \Henhed\Piwik\Model\Tracker $tracker
* @param \Henhed\Piwik\Helper\Data $dataHelper
* @param \Chessio\Matomo\Model\Tracker $tracker
* @param \Chessio\Matomo\Helper\Data $dataHelper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Henhed\Piwik\Model\Tracker $tracker,
\Henhed\Piwik\Helper\Data $dataHelper,
\Chessio\Matomo\Model\Tracker $tracker,
\Chessio\Matomo\Helper\Data $dataHelper,
array $data = []
) {
$this->_jsonEncoder = $jsonEncoder;
Expand All @@ -71,9 +72,9 @@ public function __construct(
}

/**
* Get Piwik tracker actions
* Get Matomo tracker actions
*
* @return \Henhed\Piwik\Model\Tracker
* @return \Chessio\Matomo\Model\Tracker
*/
public function getTracker()
{
Expand All @@ -90,7 +91,7 @@ protected function _prepareTracker()
$tracker = $this->getTracker();

$this->_eventManager->dispatch(
'piwik_track_page_view_before',
'matomo_track_page_view_before',
['block' => $this, 'tracker' => $tracker]
);

Expand All @@ -99,7 +100,7 @@ protected function _prepareTracker()
}

$this->_eventManager->dispatch(
'piwik_track_page_view_after',
'matomo_track_page_view_after',
['block' => $this, 'tracker' => $tracker]
);
}
Expand All @@ -120,7 +121,7 @@ public function getJsOptions()
}

/**
* Get Piwik JS URL
* Get Matomo JS URL
*
* @return string
*/
Expand All @@ -130,7 +131,7 @@ public function getScriptUrl()
}

/**
* Get Piwik tracker URL
* Get Matomo tracker URL
*
* @return string
*/
Expand All @@ -140,7 +141,7 @@ public function getTrackerUrl()
}

/**
* Get Piwik site ID
* Get Matomo site ID
*
* @return int
*/
Expand Down Expand Up @@ -176,7 +177,7 @@ public function jsonEncode($data)
}

/**
* Generate Piwik tracking script
* Generate Matomo tracking script
*
* @return string
*/
Expand Down
33 changes: 17 additions & 16 deletions CustomerData/Checkout/CartPlugin.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
/**
* Copyright 2016-2018 Henrik Hedelund
* Copyright 2020 Falco Nogatz
*
* This file is part of Henhed_Piwik.
* This file is part of Chessio_Matomo.
*
* Henhed_Piwik is free software: you can redistribute it and/or modify
* 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.
*
* Henhed_Piwik is distributed in the hope that it will be useful,
* 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 Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>.
* along with Chessio_Matomo. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Henhed\Piwik\CustomerData\Checkout;
namespace Chessio\Matomo\CustomerData\Checkout;

/**
* Plugin for \Magento\Checkout\CustomerData\Cart
Expand All @@ -35,39 +36,39 @@ class CartPlugin
protected $_checkoutSession;

/**
* Piwik data helper
* Matomo data helper
*
* @var \Henhed\Piwik\Helper\Data $_dataHelper
* @var \Chessio\Matomo\Helper\Data $_dataHelper
*/
protected $_dataHelper;

/**
* Tracker helper
*
* @var \Henhed\Piwik\Helper\Tracker $_trackerHelper
* @var \Chessio\Matomo\Helper\Tracker $_trackerHelper
*/
protected $_trackerHelper;

/**
* Tracker factory
*
* @var \Henhed\Piwik\Model\TrackerFactory $_trackerFactory
* @var \Chessio\Matomo\Model\TrackerFactory $_trackerFactory
*/
protected $_trackerFactory;

/**
* Constructor
*
* @param \Magento\Checkout\Model\Session\Proxy $checkoutSession
* @param \Henhed\Piwik\Helper\Data $dataHelper
* @param \Henhed\Piwik\Helper\Tracker $trackerHelper
* @param \Henhed\Piwik\Model\TrackerFactory $trackerFactory
* @param \Chessio\Matomo\Helper\Data $dataHelper
* @param \Chessio\Matomo\Helper\Tracker $trackerHelper
* @param \Chessio\Matomo\Model\TrackerFactory $trackerFactory
*/
public function __construct(
\Magento\Checkout\Model\Session\Proxy $checkoutSession,
\Henhed\Piwik\Helper\Data $dataHelper,
\Henhed\Piwik\Helper\Tracker $trackerHelper,
\Henhed\Piwik\Model\TrackerFactory $trackerFactory
\Chessio\Matomo\Helper\Data $dataHelper,
\Chessio\Matomo\Helper\Tracker $trackerHelper,
\Chessio\Matomo\Model\TrackerFactory $trackerFactory
) {
$this->_checkoutSession = $checkoutSession;
$this->_dataHelper = $dataHelper;
Expand All @@ -92,7 +93,7 @@ public function afterGetSectionData(
if ($quote->getId()) {
$tracker = $this->_trackerFactory->create();
$this->_trackerHelper->addQuote($quote, $tracker);
$result['piwikActions'] = $tracker->toArray();
$result['matomoActions'] = $tracker->toArray();
}
}
return $result;
Expand Down
33 changes: 17 additions & 16 deletions CustomerData/Customer/CustomerPlugin.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
/**
* Copyright 2016-2018 Henrik Hedelund
* Copyright 2020 Falco Nogatz
*
* This file is part of Henhed_Piwik.
* This file is part of Chessio_Matomo.
*
* Henhed_Piwik is free software: you can redistribute it and/or modify
* 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.
*
* Henhed_Piwik is distributed in the hope that it will be useful,
* 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 Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>.
* along with Chessio_Matomo. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Henhed\Piwik\CustomerData\Customer;
namespace Chessio\Matomo\CustomerData\Customer;

/**
* Plugin for \Magento\Customer\CustomerData\Customer
Expand All @@ -35,40 +36,40 @@ class CustomerPlugin
protected $_currentCustomer;

/**
* Piwik data helper
* Matomo data helper
*
* @var \Henhed\Piwik\Helper\Data $_dataHelper
* @var \Chessio\Matomo\Helper\Data $_dataHelper
*/
protected $_dataHelper;

/**
* User ID provider pool
*
* @var \Henhed\Piwik\UserId\Provider\Pool $_uidProviderPool
* @var \Chessio\Matomo\UserId\Provider\Pool $_uidProviderPool
*/
protected $_uidProviderPool;

/**
* Constructor
*
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
* @param \Henhed\Piwik\Helper\Data $dataHelper
* @param \Henhed\Piwik\UserId\Provider\Pool $uidProviderPool
* @param \Chessio\Matomo\Helper\Data $dataHelper
* @param \Chessio\Matomo\UserId\Provider\Pool $uidProviderPool
*/
public function __construct(
\Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
\Henhed\Piwik\Helper\Data $dataHelper,
\Henhed\Piwik\UserId\Provider\Pool $uidProviderPool
\Chessio\Matomo\Helper\Data $dataHelper,
\Chessio\Matomo\UserId\Provider\Pool $uidProviderPool
) {
$this->_currentCustomer = $currentCustomer;
$this->_dataHelper = $dataHelper;
$this->_uidProviderPool = $uidProviderPool;
}

/**
* Get configured Piwik User ID provider or NULL
* Get configured Matomo User ID provider or NULL
*
* @return \Henhed\Piwik\UserId\Provider\ProviderInterface|null
* @return \Chessio\Matomo\UserId\Provider\ProviderInterface|null
*/
protected function _getUserIdProvider()
{
Expand All @@ -77,7 +78,7 @@ protected function _getUserIdProvider()
}

/**
* Get Piwik User ID for current customer
* Get Matomo User ID for current customer
*
* @return string
*/
Expand Down Expand Up @@ -105,7 +106,7 @@ public function afterGetSectionData(
if ($this->_dataHelper->isTrackingEnabled()) {
$userId = $this->_getUserId();
if ($userId !== '') {
$result['piwikUserId'] = $userId;
$result['matomoUserId'] = $userId;
}
}
return $result;
Expand Down
Loading

0 comments on commit 8c83ed1

Please sign in to comment.