Official Matomo Java Tracker
The Matomo Java Tracker functions as the official Java implementation for
the Matomo Tracking HTTP API. This versatile tracker empowers
you to monitor visits, goals, and ecommerce transactions and items. Specifically designed for integration into
server-side applications, it seamlessly integrates with Java-based web applications or web services.
Key features:
- Comprehensive tracking capabilities: Monitor page views, goals, ecommerce transactions, and items.
- Customization options: Support for custom dimensions and variables.
- Extensive tracking parameters: Capture data on campaigns, events, downloads, outlinks, site searches, devices, and
visitors.
- Java compatibility: Supports Java 8 and higher, with a dedicated artifact (matomo-java-tracker-java11) for Java 11 or newer.
- SSL certificate flexibility: Option to skip SSL certificate validation (caution: not recommended for production).
- Minimal runtime dependencies: Relies solely on SLF4J.
- Asynchronous request support: Permits non-blocking requests.
- Compatibility with Matomo versions 4 and 5.
- Versatile request handling: Send both single and multiple requests.
- Robust documentation: Thoroughly documented with Javadoc for easy reference.
- Data accuracy assurance: Ensures correct values are transmitted to the Matomo Tracking API.
- Logging capabilities: Include debug and error logging for effective troubleshooting.
- Seamless integration: Easily integrates into frameworks such as Spring by creating the MatomoTracker Spring bean for
use in other beans.
Please prefer the Java 11 or newer version as the Java 8 will become obsolete in the future.
You can find our Developer Guide here
Further information on Matomo and Matomo HTTP tracking:
Projects that use Matomo Java Tracker:
Table of Contents
What Is New?
Version 4.0.0
Added more tracking parameters for user agent data, ecommerce product, bot recording mode, HTTP status, bandwidth,
source label and media attributes.
The Spring Boot Starter now requires Spring Boot 4. The @NonNull annotation has been migrated from
org.springframework.lang.NonNull to org.jspecify.annotations.NonNull across the Spring module. The
PropertyMapper usage was updated to align with the Spring Boot 4 API (alwaysApplyingWhenNonNull() was removed).
Fixed a Java 8 compatibility issue in JavaxHttpServletWrapper where Enumeration.asIterator() (introduced in
Java 9) was used to iterate over HTTP header names. It has been replaced with a standard while loop.
Zero is now accepted as a valid value for numeric tracking parameters such as idGoal, revenue, and ecommerce
fields, where it was previously treated as absent and omitted from requests.
Several performance improvements were made to Java11Sender: URL construction no longer uses String.format,
the case-insensitive User-Agent header lookup no longer allocates a TreeMap, .trim().isEmpty() checks were
replaced with the Java 11 .isBlank() method, and debug log statements are now guarded to avoid allocating
cookie list copies when debug logging is disabled.
Several performance improvements were also made to the core module: hex encoding in VisitorId now uses a
lookup table instead of String.format per byte, String.format calls in DeviceResolution, AcceptLanguage,
EcommerceItem, and DaemonThreadFactory were replaced with string concatenation, ServletMatomoRequest now
computes cookieName.toLowerCase() once per cookie instead of six times, QueryCreator caches the
value.toString() result to avoid calling it twice, and redundant double-check patterns such as
isEmpty() || trim().isEmpty() were simplified throughout.
Spotless now automatically removes unused imports during the build.
Dependency updates: Spring Boot 3.4.2 → 4.0.5, JUnit Jupiter 5.11.4 → 6.0.3, SLF4J 2.0.16 → 2.0.17,
Jetty EE10 12.0.16 → 12.1.8, Jetty (javax) 10.0.24 → 10.0.26.
The local testing Docker setup now uses MariaDB 12 and Matomo 5.
All previously deprecated API has been removed as part of this major release. The following is a
summary of the breaking changes and the recommended replacements:
- The
org.piwik.java.tracking compatibility package has been removed entirely (PiwikRequest,
PiwikTracker, PiwikDate, PiwikLocale, CustomVariable, EcommerceItem). Use the
corresponding classes in org.matomo.java.tracking instead.
- The deprecated
MatomoDate and MatomoLocale classes have been removed. Use java.time.Instant
and org.matomo.java.tracking.parameters.Country respectively.
- The top-level
MatomoRequestBuilder class has been removed. Use MatomoRequest.request() or
MatomoRequest.MatomoRequestBuilder instead.
- The deprecated
MatomoRequest(int siteId, String actionUrl) constructor has been removed. Use
MatomoRequest.request() builder instead.
- Deprecated mutator methods on
MatomoRequest have been removed: setCustomTrackingParameter,
addCustomTrackingParameter, clearCustomTrackingParameter, enableEcommerce,
getEcommerceItem, addEcommerceItem, clearEcommerceItems, getPageCustomVariable,
setPageCustomVariable, getUserCustomVariable, getVisitCustomVariable,
setUserCustomVariable, setVisitCustomVariable, getRequestDatetime, setRequestDatetime,
setParameter, builder(), and setDeviceResolution(String). Use the builder API
(MatomoRequest.request()...build()) instead.
- Deprecated constructors on
MatomoTracker taking hostUrl, proxyHost, proxyPort, and
timeout as individual arguments have been removed. Use
MatomoTracker(TrackerConfiguration) instead.
- The
sendRequestAsync(MatomoRequest, Function) overload has been removed. Chain
CompletableFuture.thenApply() on sendRequestAsync(MatomoRequest) instead.
- The
sendBulkRequest(Iterable, String authToken) and
sendBulkRequestAsync(Collection, String, Consumer) / sendBulkRequestAsync(Collection, String)
overloads have been removed. Set the auth token in TrackerConfiguration or on the requests
directly, and chain CompletableFuture.thenAccept() for callbacks.
- Deprecated
Country(Locale) constructor and Country.getLocale() / Country.setLocale(Locale)
methods have been removed. Construct Country from a country code string instead.
Version 3.4.0
We fixed a synchronization issue in the Java 8 sender (https://github.com/matomo-org/matomo-java-tracker/issues/168).
To consume the exact amount of space needed for the queries to send to Matomo, we need the collection size of the incoming
requests. So we changed Iterable to Collection in some MatomoTracker. This could affect users, that use parameters
of type Iterable in the tracker. Please use Collection instead.
Version 3.3.1
Do you still use Matomo Java Tracker 2.x? We created version 3, that is compatible with Matomo 4 and 5 and contains
fewer
dependencies. Release notes can be found here: https://github.com/matomo-org/matomo-java-tracker/releases
Here are the most important changes:
- Matomo Java Tracker is compatible with Matomo 4 and 5
- less dependencies
- new dimension parameter
- special types allow to provide valid parameters now
- a new implementation for Java 11 or newer uses the HttpClient available since Java 11
See also the Developer Guide here
Javadoc
The Javadoc for all versions can be found
at javadoc.io. Thanks to
javadoc.io for hosting it.
Need help?
Using this API
See the following sections for information on how to use this API. For more information, see the Javadoc. We also
recommend to read the Tracking API User Guide.
The Matomo Tracking HTTP API is well
documented and contains many examples.
This project contains the following Maven artifacts:
- matomo-java-tracker-core: This artifact is the core module of the Matomo Java Tracker project. It provides the
main functionality of the Matomo Java Tracker, which is a Java implementation for the Matomo Tracking HTTP API. This
module is designed to be used as a base for other modules in the project that provide additional functionality or
integrations.
- matomo-java-tracker: This is a specific implementation of the core module designed for Java 8. It provides the
main functionality of the Matomo Java Tracker and is built upon the core. This artifact is
specifically designed for applications running on Java 8.
- matomo-java-tracker-java11: This artifact is a Java 11 or newer implementation of the Matomo Java Tracker. It uses the
HttpClient available since Java 11. It is recommended to use this version if you are using Java 11 or newer.
- matomo-java-tracker-spring-boot-starter: This artifact is a Spring Boot Starter for the Matomo Java Tracker. It
provides auto-configuration for the Matomo Java Tracker in a Spring Boot application. By including this artifact in
your project, you can take advantage of Spring Boot's auto-configuration features to automatically set up and
configure the Matomo Java Tracker.
- matomo-java-tracker-servlet-jakarta: This artifact is specifically designed for applications using the Jakarta
Servlet API (part of Jakarta EE).
- matomo-java-tracker-servlet-javax