matomo-java-tracker icon indicating copy to clipboard operation
matomo-java-tracker copied to clipboard

[BUG] Cannot pass 0 as eventValue

Open micvm opened this issue 5 months ago • 2 comments

Describe the bug I would like to send as event value the value 0, but constraints in the TrackingParameterMethod do not allow that and an Exception fires.

Code snippets

MatomoRequest request = MatomoRequest.request().eventCategory("category").eventAction("action")
						.eventValue(Double.valueOf(0)).build();

Expected behavior Sending the requests succeeds and an event with eventValue=0 is created on matomo.

Additional context Exception:

org.matomo.java.tracking.MatomoException: Invalid value for e_v. Must be greater or equal than 4.9E-324
	at org.matomo.java.tracking.TrackingParameterMethod.validateParameterValue(TrackingParameterMethod.java:50)
	at org.matomo.java.tracking.QueryCreator.appendParameter(QueryCreator.java:127)
	... 18 more

micvm avatar Aug 14 '25 14:08 micvm

We are having the same issue regarding some of the other number properties. It seems that the issue stems from the default value of min within the TrackingParameter annotation, seen in

https://github.com/matomo-org/matomo-java-tracker/blob/8dee99e6eddec1f89d0414924c58db8efc43a4e5/core/src/main/java/org/matomo/java/tracking/TrackingParameter.java#L22-L24

Double.min is the same as 4.9E-324 (at least in Java 21 version), which causes the default value of min to disallow 0.

There was a commit a few years ago that set the proper min, max values on the TrackingParameter annotation for some fields, see https://github.com/matomo-org/matomo-java-tracker/commit/d4f835704dcdc2a6be143b52354562d018839802.

However, it did not set min and max on the following fields:

  • ecommerceRevenue
  • eventValue
  • ecommerceSubtotal
  • ecommerceTax
  • ecommerceShippingCost
  • ecommerceDiscount

It would be nice to be able to specify 0 on these values.

aleximenes avatar Sep 23 '25 13:09 aleximenes

I have created a pull request, #362 , to try to fix this issue as well as fixing the build issues in master. If someone could have a look at that one that would be amazing.

aleximenes avatar Oct 09 '25 07:10 aleximenes