piwik-tracking is a library that helps sending tracking requests to a Piwik server from a Java application.
First create an instance of PiwikConfig to configure the tracker. Mandatory input is the name of the server that hosts Piwik.
PiwikConfig config = PiwikConfig.builder().addIdSite("1")
.host("mypiwik.host.com")
.authToken("ffffffffffffffffffffff")
.build();
Next create an instance of the PiwikTracker.
PiwikTracker tracker = new PiwikTracker(config);
The application then has to create an instance of PiwikRequest for every action it wants to send a tracking request to Piwik.
PiwikRequest request = PiwikRequest.builder().url("http://my.site.com/index.html")
.putParameter(QueryParameter.ACTION_NAME, "anAction")
.putParameter(QueryParameter.VISITOR_ID, 1)
.build();
and send the request to Piwik either synchronous (blocking) or asynchronous (non-blocking).
//send blocking request
tracker.send(request);
//send non blocking request
tracker.sendAsync(request);
When the application sends asynchronous requests the http library (OkHttp)
internally starts an ExecutorService. To properly shutdown this service an application can call the
shutdown method: tracker.shutdown();
For more information about the supported request parameters see the official documentation:
https://developer.piwik.org/api-reference/tracking-api
The library is hosted on the Central Maven Repository
<dependency>
<groupId>ch.rasc</groupId>
<artifactId>piwik-tracking</artifactId>
<version>1.0.3</version>
</dependency>
- Issue 1: token_auth shouldn't be mandatory
- Issue 2: path and scheme cannot be changed
- Issue 3: Cannot add path wish slashes
- Replace
javax.xml.bind.DatatypeConverter
code. This package no longer exists in Java 11
- Remove unnecessary System.out.println call
- Initial release
Code released under the Apache license.