Download the PHP package pagemachine/matomo-tracking without Composer
On this page you can find all versions of the php package pagemachine/matomo-tracking. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pagemachine/matomo-tracking
More information about pagemachine/matomo-tracking
Files in pagemachine/matomo-tracking
Package matomo-tracking
Short Description Server-side Matomo tracking API with emphasis on privacy: consentless tracking, GDPR/TDDDG-compliant, respects DNT/GPC
License GPL-3.0-or-later
Informations about the package matomo-tracking
Matomo Tracking API
Server-side tracking of actions (e.g. page views) in Matomo using the Matomo Tracking HTTP API.
Features
- Framework-agnostic, uses PSR-7: HTTP message interfaces, PSR-17: HTTP Factories and PSR-18: HTTP Client
- Container/dependency injection friendly
- Track page views from server requests
- Track actions without requests
- Track visitor IP address (requires Matomo Auth Token)
- Attributes for tracking of Matomo Site Id, URL, etc.
- Add custom attributes
Privacy by design
- Visitor IDs are random
- No cookies are set or forwarded
- Action attributes are sent to Matomo via
POST
to prevent them from showing up in access logs (thus no Log Analytics) - Respects Do Not Track
- Respects Global Privacy Control
Installation
composer require pagemachine/matomo-tracking
Usage
Actions can be tracked with the Matomo
class. Make sure you have implementations
for UriFactoryInterface
, RequestFactoryInterface
, ClientInterface
and LoggerInterface
.
You should configure the HTTP client with a sane timeout. This ensures pages load quickly in case a Matomo instance is not responding. Tracking will be skipped in this case.
In case of most frameworks the dependency injection container will cover most dependencies and you only need to manually configure the URL of your Matomo instance. E.g. with Symfony:
Then have Matomo
injected:
Alternatively use standalone solutions like guzzlehttp/guzzle
, guzzlehttp/psr7
and some useful logger or the PSR NullLogger
:
Server requests
A PSR-7 ServerRequestInterface
can directly be tracked as page view:
As shown the custom matomo.attributes
request attribute can be set for
tracking attributes.
By default URLs (current, referrer) and client info (user agent, language) are determined from the server request.
Actions
Aside from PSR-7 server requests, actions not directly related to a request can
also be tracked. Use the ActionFactoryInterface
(frameworks) or the
ActionFactory
(standalone) to track an action with attributes:
You can also create an action from a PSR-7 ServerRequestInterface
if desired:
Action factories
If there are additional attributes which should be added to actions by default,
you can add a custom ActionFactoryInterface
. This should wrap or decorate
the default ActionFactory
to ensure all default attributes are added:
This pattern can be used to add the mandatory SiteId
attribute to all tracked actions.
Attributes
Attributes contain tracking values and cover one or more of the Matomo Tracking HTTP API parameters:
Attribute | Matomo API parameters |
---|---|
ActionName |
action_name |
ApiVersion (*) |
apiv |
AuthToken |
token_auth |
BotTracking |
bots |
CustomAction |
ca |
Download |
download , url , ca |
DownloadUrl |
download |
Language |
lang |
NoResponse (*) |
send_image |
Random (*) |
rand |
Recording (*) |
rec |
ReferrerUrl |
urlref |
Search |
search , search_count , search_cat , ca |
SearchCategory |
search_cat |
SearchKeyword |
search |
SearchResultCount |
search_count |
SiteId |
idsite |
Url |
url |
UserAgent |
ua |
VisitorId |
_id |
VisitorIpAddress |
cip |
(Attributes marked with * are added internally and always sent.)
You must at least add a SiteId
attribute for tracking in Matomo. All
other attributes may be used on demand.
Some attributes like VisitorIpAddress
require an auth token
which must be provided with the AuthToken
attribute. See
Matomo Tracking HTTP API: Other parameters
for details when an auth token is required.
Custom attributes
Custom attributes can be added by implementing the AttributeInterface
:
The keys of the iterable (array
, \Generator
, etc.) returned by toParameters()
must be parameters of the Matomo Tracking HTTP API.
All versions of matomo-tracking with dependencies
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/log Version ^1.0 || ^2.0 || ^3.0