- Notifications
You must be signed in to change notification settings - Fork38
Matomo Analytics Module for Magento 2
License
fnogatz/magento2-matomo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Chessio_Matomo is aMatomo web analytics module for theMagento 2 eCommerce platform. Matomo is an extensible free/libre analytics tool that can be self-hosted, giving you complete data ownership. Chessio_Matomo lets you integrate Matomo with your Magento 2 store front.
This module is the successor ofHenhed_Piwik and thus continues with its semantic versioning, beginning with versionv2.1.0
. If you're using a Magento version prior to 2.2, you'll need to stick to the 1.x releases of the original Henhed_Piwik. For manual installation, check out theReleases archive. For installation usingComposer, you can use thetilde orcaret version constraint operators (e.g.~1.3
or^1.3.1
).
To install Chessio_Matomo, download and extract themain zip archive and move the extracted folder toapp/code/Chessio/Matomo in your Magento 2 installation directory.
unzip magento2-matomo-main.zipmkdir app/code/Chessiomv magento2-matomo-main app/code/Chessio/Matomo
Alternatively, you can clone the Chessio_Matomo Git repository intoapp/code/Chessio_Matomo.
git clone https://github.com/fnogatz/magento2-matomo.git app/code/Chessio/Matomo
Or, if you prefer, install it usingComposer.
composer require chessio/module-matomo
Finally, enable the module with the Magento CLI tool.
php bin/magento module:enable Chessio_Matomo --clear-static-content
Once installed, configuration options can be found in the Magento 2 administration panel underStores/Configuration/Sales/Matomo API.To start tracking, setEnable Tracking toYes, enter theHostname of your Matomo installation and clickSave Config. If you have multiple websites in the same Matomo installation, make sure theSite ID configured in Magento is correct.
If you need to send some custom information to your Matomo server, Chessio_Matomo lets you do so using event observers.
To set custom data on each page, use thematomo_track_page_view_before
event. A tracker instance will be passed along with the event object to your observer'sexecute
method.
publicfunctionexecute(\Magento\Framework\Event\Observer$observer){$tracker =$observer->getEvent()->getTracker();/** @var \Chessio\Matomo\Model\Tracker $tracker */$tracker->setDocumentTitle('My Custom Title');}
If you only want to add data under some specific circumstance, find a suitable event and request the tracker singleton in your observer's constructor. Store the tracker in a class member variable for later use in theexecute
method.
publicfunction__construct(\Chessio\Matomo\Model\Tracker$matomoTracker){$this->_matomoTracker =$matomoTracker;}
Beware of tracking user specific information on the server side as it will most likely cause caching problems. Instead, use Javascript to retrieve the user data from a cookie, localStorage or some Ajax request and then push the data to Matomo using either the Chessio_Matomo JS component...
require(['Chessio_Matomo/js/tracker'],function(trackerComponent){trackerComponent.getTracker().done(function(tracker){// Do something with tracker});});
... or the vanilla Matomo approach:
var_paq=_paq||[];_paq.push(['setDocumentTitle','My Custom Title']);
See theMatomo Developer Docs or the\Chessio\Matomo\Model\Tracker source code for a list of all methods available in the Tracking API.
About
Matomo Analytics Module for Magento 2