Skip to content

Official Java implementation of the Matomo Tracking HTTP API.

License

Notifications You must be signed in to change notification settings

norbertroamsys/matomo-java-tracker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matomo Java Tracker

Maven Central

Code Status

Build Status Average time to resolve an issue Percentage of issues still open

Official Java implementation of the Matomo Tracking HTTP API.

Javadoc

The Javadoc for this project is hosted as a Github page for this repo. The latest Javadoc can be found here. Javadoc for the latest and all releases can be found here.

Using this API

Create a Request

Each PiwikRequest represents an action the user has taken that you want tracked by your Piwik server. Create a PiwikRequest through

PiwikRequest request = new PiwikRequest(siteId, actionUrl);

The following parameters are also enabled by default:

required = true;
visitorId = random 16 character hex string;
randomValue = random 20 character hex string;
apiVersion = 1;
responseAsImage = false;

Overwrite these properties as desired.

Note that if you want to be able to track campaigns using Referrers > Campaigns, you must add the correct URL parameters to your actionUrl. For example,

URL actionUrl = new URL("http://example.org/landing.html?pk_campaign=Email-Nov2011&pk_kwd=LearnMore");

See Tracking Campaigns for more information.

All HTTP query parameters denoted on the Matomo Tracking HTTP API can be set using the appropriate getters and setters. See PiwikRequest.java for the mappings of the parameters to their corresponding Java getters/setters.

Some parameters are dependent on the state of other parameters: EcommerceEnabled must be called before the following parameters are set: EcommerceId and EcommerceRevenue.

EcommerceId and EcommerceRevenue must be set before the following parameters are set: EcommerceDiscount, EcommerceItem, EcommerceLastOrderTimestamp, EcommerceShippingCost, EcommerceSubtotal, and EcommerceTax.

AuthToken must be set before the following parameters are set: VisitorCity, VisitorCountry, VisitorIp, VisitorLatitude, VisitorLongitude, and VisitorRegion.

Sending Requests

Create a PiwikTracker through

PiwikTracker tracker = new PiwikTracker(hostUrl);

where hostUrl is the url endpoint of the Piwik server. Usually in the format http://your-piwik-domain.tld/piwik.php.

To send a single request, call

HttpResponse response = tracker.sendRequest(request);

If you have multiple requests to wish to track, it may be more efficient to send them in a single HTTP call. To do this, send a bulk request. Place your requests in an Iterable data structure and call

HttpResponse response = tracker.sendBulkRequest(requests);

If some of the parameters that you've specified in the bulk request require AuthToken to be set, this can also be set in the bulk request through

HttpResponse response = tracker.sendBulkRequest(requests, authToken);

Install

This project can be tested and built by calling

mvn package

The built jars and javadoc can be found in target

Test this project using

mvn test

This project also supports Pitest mutation testing. This report can be generated by calling

mvn org.pitest:pitest-maven:mutationCoverage

and will produce an HTML report at target/pit-reports/YYYYMMDDHHMI

Clean this project using

mvn clean

Contribute

Have a fantastic feature idea? Spot a bug? We would absolutely love for you to contribute to this project! Please feel free to:

  • Fork this project
  • Create a feature branch from the dev branch
  • Write awesome code that does awesome things
  • Write awesome test to test your awesome code
  • Verify that everything is working as it should by running mvn test. If everything passes, you may want to make sure that your tests are covering everything you think they are! Run mvn org.pitest:pitest-maven:mutationCoverage to find out!
  • Commit this code to your repository
  • Submit a pull request from your branch to our dev branch and let us know why you made the changes you did
  • We'll take a look at your request and work to get it integrated with the repo!

License

This software is released under the BSD 3-Clause license. See LICENSE.

Copyright

Copyright (c) 2015 General Electric Company. All rights reserved.

About

Official Java implementation of the Matomo Tracking HTTP API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%