Official Java implementation of the Piwik Tracking HTTP API.
Java
Clone or download

README.md

Piwik Java Tracker

Maven Central

Code Status

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

Official Java implementation of the Piwik 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 Piwik 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 requre 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 that 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!

Contact

brett.csorba@gmail.com

License

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

Copyright

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