Skip to content

Latest commit

 

History

History
84 lines (68 loc) · 3.59 KB

File metadata and controls

84 lines (68 loc) · 3.59 KB

Piwik Java Tracker

Build Status

Java implementation of the Piwik Tracking HTTP API.

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 build by calling

ant

The built jars and javadoc can be found in dist/ The project also supports Pitest mutation testing. This report can be generated by calling

ant mutate

and will produce an html report at build/test/results/20.../index.html

Clean this project using

ant clean

Contact

brett.csorba@ge.com

License

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

Copyright

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