I’m developing an app which I plan on implementing Piwik Analytics into. Although there seems to be no real documentation (unless I’m blind) on how to use the Java Tracking API, I think I managed to figure it out, but when I try it, I get this error
WARNING: Warning:400 Bad Request
org.piwik.PiwikException: error:400 Bad Request
at org.piwik.SimplePiwikTracker.sendRequest(SimplePiwikTracker.java:878)
at net.aman207.test.Main.main(Main.java:32)
Here is my code
SimplePiwikTracker tracker = new SimplePiwikTracker("http://aman207.net/piwik/piwik.php");
tracker.setIdSite(2);
tracker.setPageUrl("http://aman207.net/javatest/test");
tracker.setPageCustomVariable("test", "10");
//This is line 32
tracker.sendRequest(tracker.getLinkTrackURL("http://aman207.net/piwik/piwik.php"));
I also tried this
String datURL = tracker.getLinkTrackURL("http://aman207.net/piwik/piwik.php").toString();
URL url = new URL(datURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
System.out.println(connection.getResponseCode());
connection.disconnect();
but this just prints out response code 404 which doesn’t make any sense because if I paste the link into my browser it works perfectly and logs correctly (I have debug mode on).
What am I doing wrong? Thanks!