This will check whether the executor service is already terminated, and if not, it - * initiates a shutdown and waits a minute. If the minute expires, the executor service - * is shutdown immediately. + *
This will check whether the executor service is already terminated, and if not, it initiates + * a shutdown and waits a minute. If the minute expires, the executor service is shutdown + * immediately. * * @param executorService The executor service to close */ @@ -38,5 +36,4 @@ public static void close(@NonNull ExecutorService executorService) { } } } - } diff --git a/core/src/main/java/org/matomo/java/tracking/InvalidUrlException.java b/core/src/main/java/org/matomo/java/tracking/InvalidUrlException.java index 0b243ab0..2f4c56e9 100644 --- a/core/src/main/java/org/matomo/java/tracking/InvalidUrlException.java +++ b/core/src/main/java/org/matomo/java/tracking/InvalidUrlException.java @@ -7,9 +7,7 @@ package org.matomo.java.tracking; -/** - * Thrown when an invalid URL is passed to the tracker. - */ +/** Thrown when an invalid URL is passed to the tracker. */ public class InvalidUrlException extends RuntimeException { InvalidUrlException(Throwable cause) { diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoDate.java b/core/src/main/java/org/matomo/java/tracking/MatomoDate.java index 331f4923..3927dc2b 100644 --- a/core/src/main/java/org/matomo/java/tracking/MatomoDate.java +++ b/core/src/main/java/org/matomo/java/tracking/MatomoDate.java @@ -26,8 +26,8 @@ public class MatomoDate { private ZonedDateTime zonedDateTime; /** - * Allocates a Date object and initializes it so that it represents the time - * at which it was allocated, measured to the nearest millisecond. + * Allocates a Date object and initializes it so that it represents the time at which it was + * allocated, measured to the nearest millisecond. */ @Deprecated public MatomoDate() { @@ -35,9 +35,8 @@ public MatomoDate() { } /** - * Allocates a Date object and initializes it to represent the specified number - * of milliseconds since the standard base time known as "the epoch", namely - * January 1, 1970, 00:00:00 GMT. + * Allocates a Date object and initializes it to represent the specified number of milliseconds + * since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT. * * @param epochMilli the milliseconds since January 1, 1970, 00:00:00 GMT. */ @@ -47,8 +46,7 @@ public MatomoDate(long epochMilli) { } /** - * Sets the time zone of the String that will be returned by {@link #toString()}. - * Defaults to UTC. + * Sets the time zone of the String that will be returned by {@link #toString()}. Defaults to UTC. * * @param zone the TimeZone to set */ @@ -57,8 +55,7 @@ public void setTimeZone(ZoneId zone) { } /** - * Converts this datetime to the number of milliseconds from the epoch - * of 1970-01-01T00:00:00Z. + * Converts this datetime to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z. * * @return the number of milliseconds since the epoch of 1970-01-01T00:00:00Z * @throws ArithmeticException if numeric overflow occurs diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoException.java b/core/src/main/java/org/matomo/java/tracking/MatomoException.java index 1f94a08f..99a3e90b 100644 --- a/core/src/main/java/org/matomo/java/tracking/MatomoException.java +++ b/core/src/main/java/org/matomo/java/tracking/MatomoException.java @@ -8,7 +8,8 @@ package org.matomo.java.tracking; /** - * Thrown when an error occurs while communicating with the Matomo server or when the request is invalid. + * Thrown when an error occurs while communicating with the Matomo server or when the request is + * invalid. */ public class MatomoException extends RuntimeException { @@ -21,5 +22,4 @@ public class MatomoException extends RuntimeException { MatomoException(String message, Throwable cause) { super(message, cause); } - } diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoLocale.java b/core/src/main/java/org/matomo/java/tracking/MatomoLocale.java index d0dad67d..d7340351 100644 --- a/core/src/main/java/org/matomo/java/tracking/MatomoLocale.java +++ b/core/src/main/java/org/matomo/java/tracking/MatomoLocale.java @@ -33,11 +33,7 @@ public class MatomoLocale extends Country { * @deprecated Please use {@link Country} */ @Deprecated - public MatomoLocale( - @NonNull - Locale locale - ) { + public MatomoLocale(@NonNull Locale locale) { super(requireNonNull(locale, "Locale must not be null")); } - } diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoRequest.java b/core/src/main/java/org/matomo/java/tracking/MatomoRequest.java index 42ef0c29..8c17fd35 100644 --- a/core/src/main/java/org/matomo/java/tracking/MatomoRequest.java +++ b/core/src/main/java/org/matomo/java/tracking/MatomoRequest.java @@ -59,10 +59,7 @@ public class MatomoRequest { * The ID of the website we're tracking a visit/action for. Only needed, if no default site id is * configured. */ - @TrackingParameter( - name = "idsite", - min = 1 - ) + @TrackingParameter(name = "idsite", min = 1) private Integer siteId; /** @@ -74,15 +71,11 @@ public class MatomoRequest { @TrackingParameter(name = "action_name") private String actionName; - /** - * The full URL for the current action. - */ + /** The full URL for the current action. */ @TrackingParameter(name = "url") private String actionUrl; - /** - * Defines the API version to use (default: 1). - */ + /** Defines the API version to use (default: 1). */ @TrackingParameter(name = "apiv") @Default private String apiVersion = "1"; @@ -91,9 +84,9 @@ public class MatomoRequest { * The unique visitor ID. See {@link VisitorId}. Default is {@link VisitorId#random()} * *
Since version 3.0.0 this parameter is of type {@link VisitorId} and not a String anymore. - * Use {@link VisitorId#fromHex(String)} to create a VisitorId from a hex string, - * {@link VisitorId#fromUUID(UUID)} to create it from a UUID or {@link VisitorId#fromHash(long)} - * to create it from a long value. + * Use {@link VisitorId#fromHex(String)} to create a VisitorId from a hex string, {@link + * VisitorId#fromUUID(UUID)} to create it from a UUID or {@link VisitorId#fromHash(long)} to + * create it from a long value. */ @TrackingParameter(name = "_id") @Default @@ -144,121 +137,76 @@ public class MatomoRequest { @TrackingParameter(name = "_idts") private Instant visitorFirstVisitTimestamp; - /** - * The campaign name. This parameter will only be used for the first pageview of a visit. - */ + /** The campaign name. This parameter will only be used for the first pageview of a visit. */ @TrackingParameter(name = "_rcn") private String campaignName; /** - * The campaign keyword (see - * Tracking Campaigns). Used to - * populate the Referrers > Campaigns report (clicking on a campaign loads all - * keywords for this campaign). This parameter will only be used for the first pageview of a - * visit. + * The campaign keyword (see Tracking + * Campaigns). Used to populate the Referrers > Campaigns report (clicking on a + * campaign loads all keywords for this campaign). This parameter will only be used for the first + * pageview of a visit. */ @TrackingParameter(name = "_rck") private String campaignKeyword; - /** - * The resolution of the device the visitor is using. - */ + /** The resolution of the device the visitor is using. */ @TrackingParameter(name = "res") private DeviceResolution deviceResolution; - /** - * The current hour (local time). - */ - @TrackingParameter( - name = "h", - min = 0, - max = 23 - ) + /** The current hour (local time). */ + @TrackingParameter(name = "h", min = 0, max = 23) private Integer currentHour; - /** - * The current minute (local time). - */ - @TrackingParameter( - name = "m", - min = 0, - max = 59 - ) + /** The current minute (local time). */ + @TrackingParameter(name = "m", min = 0, max = 59) private Integer currentMinute; - /** - * The current second (local time). - */ - @TrackingParameter( - name = "s", - min = 0, - max = 59 - ) + /** The current second (local time). */ + @TrackingParameter(name = "s", min = 0, max = 59) private Integer currentSecond; - /** - * Does the visitor use the Adobe Flash Plugin. - */ + /** Does the visitor use the Adobe Flash Plugin. */ @TrackingParameter(name = "fla") private Boolean pluginFlash; - /** - * Does the visitor use the Java plugin. - */ + /** Does the visitor use the Java plugin. */ @TrackingParameter(name = "java") private Boolean pluginJava; - /** - * Does the visitor use Director plugin. - */ + /** Does the visitor use Director plugin. */ @TrackingParameter(name = "dir") private Boolean pluginDirector; - /** - * Does the visitor use Quicktime plugin. - */ + /** Does the visitor use Quicktime plugin. */ @TrackingParameter(name = "qt") private Boolean pluginQuicktime; - /** - * Does the visitor use Realplayer plugin. - */ + /** Does the visitor use Realplayer plugin. */ @TrackingParameter(name = "realp") private Boolean pluginRealPlayer; - /** - * Does the visitor use a PDF plugin. - */ + /** Does the visitor use a PDF plugin. */ @TrackingParameter(name = "pdf") private Boolean pluginPDF; - /** - * Does the visitor use a Windows Media plugin. - */ + /** Does the visitor use a Windows Media plugin. */ @TrackingParameter(name = "wma") private Boolean pluginWindowsMedia; - /** - * Does the visitor use a Gears plugin. - */ + /** Does the visitor use a Gears plugin. */ @TrackingParameter(name = "gears") private Boolean pluginGears; - /** - * Does the visitor use a Silverlight plugin. - */ + /** Does the visitor use a Silverlight plugin. */ @TrackingParameter(name = "ag") private Boolean pluginSilverlight; - /** - * Does the visitor's client is known to support cookies. - */ + /** Does the visitor's client is known to support cookies. */ @TrackingParameter(name = "cookie") private Boolean supportsCookies; - /** - * An override value for the User-Agent HTTP header field. - */ + /** An override value for the User-Agent HTTP header field. */ @TrackingParameter(name = "ua") private String headerUserAgent; @@ -279,15 +227,11 @@ public class MatomoRequest { @TrackingParameter(name = "uid") private String userId; - /** - * defines the visitor ID for this request. - */ + /** defines the visitor ID for this request. */ @TrackingParameter(name = "cid") private VisitorId visitorCustomId; - /** - * will force a new visit to be created for this action. - */ + /** will force a new visit to be created for this action. */ @TrackingParameter(name = "new_visit") private Boolean newVisit; @@ -319,9 +263,7 @@ public class MatomoRequest { @TrackingParameter(name = "search") private String searchQuery; - /** - * When search is specified, you can optionally specify a search category with this parameter. - */ + /** When search is specified, you can optionally specify a search category with this parameter. */ @TrackingParameter(name = "search_cat") private String searchCategory; @@ -330,10 +272,7 @@ public class MatomoRequest { * results displayed on the results page. When keywords are tracked with &search_count=0 they will * appear in the "No Result Search Keyword" report. */ - @TrackingParameter( - name = "search_count", - min = 0 - ) + @TrackingParameter(name = "search_count", min = 0) private Long searchResultsCount; /** @@ -352,9 +291,7 @@ public class MatomoRequest { @TrackingParameter(name = "idgoal", min = 0) private Integer goalId; - /** - * The grand total for the ecommerce order (required when tracking an ecommerce order). - */ + /** The grand total for the ecommerce order (required when tracking an ecommerce order). */ @TrackingParameter(name = "revenue", min = 0) private Double ecommerceRevenue; @@ -374,21 +311,15 @@ public class MatomoRequest { @TrackingParameter(name = "ca") private Boolean customAction; - /** - * How long it took to connect to server. - */ + /** How long it took to connect to server. */ @TrackingParameter(name = "pf_net", min = 0) private Long networkTime; - /** - * How long it took the server to generate page. - */ + /** How long it took the server to generate page. */ @TrackingParameter(name = "pf_srv", min = 0) private Long serverTime; - /** - * How long it takes the browser to download the response from the server. - */ + /** How long it takes the browser to download the response from the server. */ @TrackingParameter(name = "pf_tfr", min = 0) private Long transferTime; @@ -406,57 +337,39 @@ public class MatomoRequest { @TrackingParameter(name = "pf_dm2", min = 0) private Long domCompletionTime; - /** - * How long it takes the browser to execute Javascript code waiting for the window.load event. - */ + /** How long it takes the browser to execute Javascript code waiting for the window.load event. */ @TrackingParameter(name = "pf_onl", min = 0) private Long onloadTime; - /** - * eg. Videos, Music, Games... - */ + /** eg. Videos, Music, Games... */ @TrackingParameter(name = "e_c") private String eventCategory; - /** - * An event action like Play, Pause, Duration, Add Playlist, Downloaded, Clicked... - */ + /** An event action like Play, Pause, Duration, Add Playlist, Downloaded, Clicked... */ @TrackingParameter(name = "e_a") private String eventAction; - /** - * The event name for example a Movie name, or Song name, or File name... - */ + /** The event name for example a Movie name, or Song name, or File name... */ @TrackingParameter(name = "e_n") private String eventName; - /** - * Some numeric value that represents the event value. - */ + /** Some numeric value that represents the event value. */ @TrackingParameter(name = "e_v", min = 0) private Double eventValue; - /** - * The name of the content. For instance 'Ad Foo Bar' - */ + /** The name of the content. For instance 'Ad Foo Bar' */ @TrackingParameter(name = "c_n") private String contentName; - /** - * The actual content piece. For instance the path to an image, video, audio, any text - */ + /** The actual content piece. For instance the path to an image, video, audio, any text */ @TrackingParameter(name = "c_p") private String contentPiece; - /** - * The target of the content. For instance the URL of a landing page - */ + /** The target of the content. For instance the URL of a landing page */ @TrackingParameter(name = "c_t") private String contentTarget; - /** - * The name of the interaction with the content. For instance a 'click' - */ + /** The name of the interaction with the content. For instance a 'click' */ @TrackingParameter(name = "c_i") private String contentInteraction; @@ -467,33 +380,23 @@ public class MatomoRequest { @TrackingParameter(name = "ec_id") private String ecommerceId; - /** - * Items in the Ecommerce order. - */ + /** Items in the Ecommerce order. */ @TrackingParameter(name = "ec_items") private EcommerceItems ecommerceItems; - /** - * The subtotal of the order; excludes shipping. - */ + /** The subtotal of the order; excludes shipping. */ @TrackingParameter(name = "ec_st", min = 0) private Double ecommerceSubtotal; - /** - * Tax amount of the order. - */ + /** Tax amount of the order. */ @TrackingParameter(name = "ec_tx", min = 0) private Double ecommerceTax; - /** - * Shipping cost of the order. - */ + /** Shipping cost of the order. */ @TrackingParameter(name = "ec_sh", min = 0) private Double ecommerceShippingCost; - /** - * Discount offered. - */ + /** Discount offered. */ @TrackingParameter(name = "ec_dt", min = 0) private Double ecommerceDiscount; @@ -509,16 +412,10 @@ public class MatomoRequest { * user specifically for accessing the Tracking API, and give the user only write permission on * the website(s). */ - @TrackingParameter( - name = "token_auth", - regex = "[a-z0-9]{32}" - ) + @TrackingParameter(name = "token_auth", regex = "[a-z0-9]{32}") private String authToken; - - /** - * Override value for the visitor IP (both IPv4 and IPv6 notations supported). - */ + /** Override value for the visitor IP (both IPv4 and IPv6 notations supported). */ @TrackingParameter(name = "cip") private String visitorIp; @@ -529,40 +426,26 @@ public class MatomoRequest { @TrackingParameter(name = "cdt") private Instant requestTimestamp; - /** - * An override value for the country. Must be a two-letter ISO 3166 Alpha-2 country code. - */ - @TrackingParameter( - name = "country", - maxLength = 2 - ) + /** An override value for the country. Must be a two-letter ISO 3166 Alpha-2 country code. */ + @TrackingParameter(name = "country", maxLength = 2) private Country visitorCountry; /** * An override value for the region. Should be set to a ISO 3166-2 region code, which are used by * MaxMind's and DB-IP's GeoIP2 databases. See here for a list of them for every country. */ - @TrackingParameter( - name = "region", - maxLength = 2 - ) + @TrackingParameter(name = "region", maxLength = 2) private String visitorRegion; - /** - * An override value for the city. The name of the city the visitor is located in, eg, Tokyo. - */ + /** An override value for the city. The name of the city the visitor is located in, eg, Tokyo. */ @TrackingParameter(name = "city") private String visitorCity; - /** - * An override value for the visitor's latitude, eg 22.456. - */ + /** An override value for the visitor's latitude, eg 22.456. */ @TrackingParameter(name = "lat", min = -90, max = 90) private Double visitorLatitude; - /** - * An override value for the visitor's longitude, eg 22.456. - */ + /** An override value for the visitor's longitude, eg 22.456. */ @TrackingParameter(name = "long", min = -180, max = 180) private Double visitorLongitude; @@ -603,7 +486,6 @@ public class MatomoRequest { @TrackingParameter(name = "bots") private Boolean trackBotRequests; - /** * Meant to hold a random value that is generated before each request. Using it helps avoid the * tracking request being cached by the browser or a proxy. @@ -634,8 +516,8 @@ public class MatomoRequest { * *
Custom action must be enabled for this. * - *
Typically a fully qualified class name of the exception, e.g. - * {@code java.lang.NullPointerException}. + *
Typically a fully qualified class name of the exception, e.g. {@code + * java.lang.NullPointerException}. * *
Optional for crash analytics */ @@ -695,8 +577,8 @@ public class MatomoRequest { /** * The Matomo session ID sent as a cookie {@code MATOMO_SESSID}. * - *
If not null a cookie with the name {@code MATOMO_SESSID} will be sent with the value of - * this parameter. + *
If not null a cookie with the name {@code MATOMO_SESSID} will be sent with the value of this + * parameter. */ private String sessionId; @@ -704,9 +586,8 @@ public class MatomoRequest { * Custom Dimension values for specific Custom Dimension IDs. * *
Custom Dimensions plugin must be
- * installed. See the
- * Custom Dimensions guide. Requires
- * Matomo at least 2.15.1
+ * installed. See the Custom Dimensions
+ * guide. Requires Matomo at least 2.15.1
*/
private Map {@code Required = true Visior Id = random 16 character hex string Random Value = random 20
+ * character hex string API version = 1 Response as Image = false }
*
+ * Overwrite these values yourself as desired.
+ *
+ * @param siteId the id of the website we're tracking a visit/action for
+ * @param actionUrl the full URL for the current action
* @deprecated Please use {@link MatomoRequest#request()}
*/
@Deprecated
@@ -765,11 +640,10 @@ public MatomoRequest(int siteId, String actionUrl) {
}
/**
- * Gets the list of objects currently stored at the specified custom tracking parameter. An empty
+ * Gets the list of objects currently stored at the specified custom tracking parameter. An empty
* list will be returned if there are no objects set at that key.
*
- * @param key the key of the parameter whose list of objects to get. Cannot be null
- *
+ * @param key the key of the parameter whose list of objects to get. Cannot be null
* @return the parameter at the specified key, null if nothing at this key
*/
@Nullable
@@ -786,15 +660,12 @@ public Object getCustomTrackingParameter(@NonNull String key) {
* overwrite or clear named Matomo parameters with this method. A custom parameter that has the
* same name as a named Matomo parameter will be sent in addition to that named parameter.
*
- * @param key the parameter's key. Cannot be null
- * @param value the parameter's value. Removes the parameter if null
- *
+ * @param key the parameter's key. Cannot be null
+ * @param value the parameter's value. Removes the parameter if null
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead.
*/
@Deprecated
- public void setCustomTrackingParameter(
- @NonNull String key, @Nullable Object value
- ) {
+ public void setCustomTrackingParameter(@NonNull String key, @Nullable Object value) {
if (value == null) {
if (additionalParameters != null) {
@@ -809,12 +680,11 @@ public void setCustomTrackingParameter(
}
/**
- * Add a custom tracking parameter to the specified key. If there is already a parameter at this
+ * Add a custom tracking parameter to the specified key. If there is already a parameter at this
* key, the new value replaces the old value.
*
- * @param key the parameter's key. Cannot be null
- * @param value the parameter's value. May be null
- *
+ * @param key the parameter's key. Cannot be null
+ * @param value the parameter's value. May be null
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead.
*/
@Deprecated
@@ -829,7 +699,7 @@ public void addCustomTrackingParameter(@NonNull String key, @Nullable Object val
* Removes all custom tracking parameters.
*
* @deprecated Please use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)}
- * instead so that you can manage the map yourself.
+ * instead so that you can manage the map yourself.
*/
@Deprecated
public void clearCustomTrackingParameter() {
@@ -851,10 +721,9 @@ public void enableEcommerce() {
* Get the {@link EcommerceItem} at the specified index.
*
* @param index the index of the {@link EcommerceItem} to return
- *
* @return the {@link EcommerceItem} at the specified index
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
- * instead
+ * instead
*/
@Nullable
@Deprecated
@@ -866,13 +735,12 @@ public EcommerceItem getEcommerceItem(int index) {
}
/**
- * Add an {@link EcommerceItem} to this order. Ecommerce must be enabled, and EcommerceId and
+ * Add an {@link EcommerceItem} to this order. Ecommerce must be enabled, and EcommerceId and
* EcommerceRevenue must first be set.
*
- * @param item the {@link EcommerceItem} to add. Cannot be null
- *
+ * @param item the {@link EcommerceItem} to add. Cannot be null
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
- * instead
+ * instead
*/
@Deprecated
public void addEcommerceItem(@NonNull EcommerceItem item) {
@@ -886,7 +754,7 @@ public void addEcommerceItem(@NonNull EcommerceItem item) {
* Clears all {@link EcommerceItem} from this order.
*
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
- * instead
+ * instead
*/
@Deprecated
public void clearEcommerceItems() {
@@ -897,7 +765,6 @@ public void clearEcommerceItems() {
* Get the page custom variable at the specified key.
*
* @param key the key of the variable to get
- *
* @return the variable at the specified key, null if key is not present
* @deprecated Use the {@link #getPageCustomVariables()} method instead.
*/
@@ -913,8 +780,7 @@ public String getPageCustomVariable(String key) {
/**
* Get the page custom variable at the specified index.
*
- * @param index the index of the variable to get. Must be greater than 0
- *
+ * @param index the index of the variable to get. Must be greater than 0
* @return the variable at the specified key, null if nothing at this index
* @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead
*/
@@ -937,16 +803,13 @@ private static CustomVariable getCustomVariable(CustomVariables customVariables,
* Set a page custom variable with the specified key and value at the first available index. All
* page custom variables with this key will be overwritten or deleted
*
- * @param key the key of the variable to set
- * @param value the value of the variable to set at the specified key. A null value will remove
- * this custom variable
- *
+ * @param key the key of the variable to set
+ * @param value the value of the variable to set at the specified key. A null value will remove
+ * this custom variable
* @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead
*/
@Deprecated
- public void setPageCustomVariable(
- @NonNull String key, @Nullable String value
- ) {
+ public void setPageCustomVariable(@NonNull String key, @Nullable String value) {
if (value == null) {
if (pageCustomVariables == null) {
return;
@@ -964,16 +827,13 @@ public void setPageCustomVariable(
/**
* Set a page custom variable at the specified index.
*
- * @param customVariable the CustomVariable to set. A null value will remove the CustomVariable
- * at the specified index
- * @param index the index of he CustomVariable to set
- *
+ * @param customVariable the CustomVariable to set. A null value will remove the CustomVariable at
+ * the specified index
+ * @param index the index of he CustomVariable to set
* @deprecated Use {@link #getPageCustomVariables()} instead
*/
@Deprecated
- public void setPageCustomVariable(
- @Nullable CustomVariable customVariable, int index
- ) {
+ public void setPageCustomVariable(@Nullable CustomVariable customVariable, int index) {
if (pageCustomVariables == null) {
if (customVariable == null) {
return;
@@ -985,8 +845,7 @@ public void setPageCustomVariable(
@Deprecated
private static void setCustomVariable(
- CustomVariables customVariables, @Nullable CustomVariable customVariable, int index
- ) {
+ CustomVariables customVariables, @Nullable CustomVariable customVariable, int index) {
if (customVariable == null) {
customVariables.remove(index);
} else {
@@ -1012,12 +871,10 @@ public MatomoDate getRequestDatetime() {
* record data in the past, you will need to force
* Matomo to re-process reports for the past dates. If you set the Request
* Datetime to a datetime older than four hours then Auth Token must be set. If you
- * set
- * Request Datetime with a datetime in the last four hours then you
- * don't need to pass Auth Token.
- *
- * @param matomoDate the datetime of the request to set. A null value will remove this parameter
+ * set Request Datetime with a datetime in the last four hours then you don't need to
+ * pass Auth Token.
*
+ * @param matomoDate the datetime of the request to set. A null value will remove this parameter
* @deprecated Use {@link #setRequestTimestamp(Instant)} instead
*/
@Deprecated
@@ -1029,12 +886,10 @@ public void setRequestDatetime(MatomoDate matomoDate) {
}
}
-
/**
* Get the visit custom variable at the specified key.
*
* @param key the key of the variable to get
- *
* @return the variable at the specified key, null if key is not present
* @deprecated Use the {@link #getVisitCustomVariables()} method instead.
*/
@@ -1051,7 +906,6 @@ public String getUserCustomVariable(String key) {
* Get the visit custom variable at the specified index.
*
* @param index the index of the variable to get
- *
* @return the variable at the specified index, null if nothing at this index
* @deprecated Use {@link #getVisitCustomVariables()} instead
*/
@@ -1065,16 +919,13 @@ public CustomVariable getVisitCustomVariable(int index) {
* Set a visit custom variable with the specified key and value at the first available index. All
* visit custom variables with this key will be overwritten or deleted
*
- * @param key the key of the variable to set
- * @param value the value of the variable to set at the specified key. A null value will remove
- * this parameter
- *
+ * @param key the key of the variable to set
+ * @param value the value of the variable to set at the specified key. A null value will remove
+ * this parameter
* @deprecated Use {@link #setVisitCustomVariables(CustomVariables)} instead
*/
@Deprecated
- public void setUserCustomVariable(
- @NonNull String key, @Nullable String value
- ) {
+ public void setUserCustomVariable(@NonNull String key, @Nullable String value) {
if (value == null) {
if (visitCustomVariables == null) {
return;
@@ -1092,16 +943,13 @@ public void setUserCustomVariable(
/**
* Set a user custom variable at the specified key.
*
- * @param customVariable the CustomVariable to set. A null value will remove the custom variable
- * at the specified index
- * @param index the index to set the customVariable at.
- *
+ * @param customVariable the CustomVariable to set. A null value will remove the custom variable
+ * at the specified index
+ * @param index the index to set the customVariable at.
* @deprecated Use {@link #setVisitCustomVariables(CustomVariables)} instead
*/
@Deprecated
- public void setVisitCustomVariable(
- @Nullable CustomVariable customVariable, int index
- ) {
+ public void setVisitCustomVariable(@Nullable CustomVariable customVariable, int index) {
if (visitCustomVariables == null) {
if (customVariable == null) {
return;
@@ -1117,11 +965,9 @@ public void setVisitCustomVariable(
* Attention: If a parameter with the same name already exists, it will be appended twice!
*
* @param parameterName The name of the query parameter to append. Must not be null or empty.
- * @param value The value of the query parameter to append. To remove the parameter, pass
- * null.
- *
+ * @param value The value of the query parameter to append. To remove the parameter, pass null.
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)}
- * instead
+ * instead
*/
@Deprecated
public void setParameter(@NonNull String parameterName, Object value) {
@@ -1155,7 +1001,6 @@ public static org.matomo.java.tracking.MatomoRequestBuilder builder() {
* Parses the given device resolution string and sets the {@link #deviceResolution} field.
*
* @param deviceResolution the device resolution string to parse. Format: "WIDTHxHEIGHT"
- *
* @deprecated Use {@link #setDeviceResolution(DeviceResolution)} instead.
*/
@Tolerate
@@ -1167,5 +1012,4 @@ public void setDeviceResolution(@Nullable String deviceResolution) {
this.deviceResolution = DeviceResolution.fromString(deviceResolution);
}
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java b/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java
index 01c43cd2..963e6916 100644
--- a/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java
+++ b/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java
@@ -5,24 +5,23 @@
import org.matomo.java.tracking.parameters.AcceptLanguage;
/**
- * The former MatomoRequestBuilder class has been moved to MatomoRequest.MatomoRequestBuilder.
- * This class is only here for backwards compatibility.
+ * The former MatomoRequestBuilder class has been moved to MatomoRequest.MatomoRequestBuilder. This
+ * class is only here for backwards compatibility.
*
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder} instead.
*/
@Deprecated
public class MatomoRequestBuilder extends MatomoRequest.MatomoRequestBuilder {
-
/**
* Sets the tracking parameter for the accept languages of a user. Only here for backwards
* compatibility.
*
* @param headerAcceptLanguage The accept language header of a user. Must be in the format
- * specified in RFC 2616.
+ * specified in RFC 2616.
* @return This builder
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#headerAcceptLanguage(AcceptLanguage)}
- * in combination with {@link AcceptLanguage#fromHeader(String)} instead.
+ * in combination with {@link AcceptLanguage#fromHeader(String)} instead.
*/
@Deprecated
public MatomoRequestBuilder headerAcceptLanguage(@Nullable String headerAcceptLanguage) {
@@ -45,5 +44,4 @@ public MatomoRequestBuilder customTrackingParameters(@Nullable Map Make sure you have tracked a content impression using the same content name and
- * content piece, otherwise it will not count.
+ * Make sure you have tracked a content impression using the same content name and content
+ * piece, otherwise it will not count.
*
* A content interaction is an interaction with a content piece. The content piece can be a
* product, an article, a video, a banner, etc. The content piece can be specified by the
@@ -69,11 +65,10 @@ public static MatomoRequest.MatomoRequestBuilder contentImpression(
* should be the type of the interaction, like "click" or "add-to-cart".
*
* @param interaction The type of the interaction. Must not be null. Example: "click".
- * @param name The name of the content piece, like the name of a product or an article.
- * @param piece The content piece. Can be null. Example: "Blog Article XYZ".
- * @param target The target of the content piece, like the URL of a product or an article.
- * Can be null. Example: "https://example.com/blog/article-xyz".
- *
+ * @param name The name of the content piece, like the name of a product or an article.
+ * @param piece The content piece. Can be null. Example: "Blog Article XYZ".
+ * @param target The target of the content piece, like the URL of a product or an article. Can be
+ * null. Example: "https://example.com/blog/article-xyz".
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
@@ -81,10 +76,8 @@ public static MatomoRequest.MatomoRequestBuilder contentInteraction(
@NonNull String interaction,
@NonNull String name,
@Nullable String piece,
- @Nullable String target
- ) {
- return MatomoRequest
- .request()
+ @Nullable String target) {
+ return MatomoRequest.request()
.contentInteraction(interaction)
.contentName(name)
.contentPiece(piece)
@@ -97,23 +90,21 @@ public static MatomoRequest.MatomoRequestBuilder contentInteraction(
* Requires Crash Analytics plugin to be enabled in the target Matomo instance.
*
* A crash is an error that causes the application to stop working. The parameters {@code
- * message} and {@code stackTrace} are required. The other parameters are optional. The
- * {@code type} parameter can be used to specify the type of the crash, like
- * {@code NullPointerException}. The {@code category} parameter can be used to specify the
- * category of the crash, like payment failure. The {@code location}, {@code line} and
- * {@code column} can be used to specify the location of the crash. The {@code location} parameter
- * should be the name of the file where the crash occurred. The {@code line} and {@code column}
- * parameters should be the line and column number of the crash.
- *
- * @param message The message of the crash. Must not be null.
- * @param type The type of the crash. Can be null. Example:
- * {@code java.lang.NullPointerException}
- * @param category The category of the crash. Can be null. Example: "payment failure".
+ * message} and {@code stackTrace} are required. The other parameters are optional. The {@code
+ * type} parameter can be used to specify the type of the crash, like {@code
+ * NullPointerException}. The {@code category} parameter can be used to specify the category of
+ * the crash, like payment failure. The {@code location}, {@code line} and {@code column} can be
+ * used to specify the location of the crash. The {@code location} parameter should be the name of
+ * the file where the crash occurred. The {@code line} and {@code column} parameters should be the
+ * line and column number of the crash.
+ *
+ * @param message The message of the crash. Must not be null.
+ * @param type The type of the crash. Can be null. Example: {@code java.lang.NullPointerException}
+ * @param category The category of the crash. Can be null. Example: "payment failure".
* @param stackTrace The stack trace of the crash. Must not be null.
- * @param location The location of the crash. Can be null. Example: "MainActivity.java".
- * @param line The line number of the crash. Can be null. Example: 42.
- * @param column The column number of the crash. Can be null. Example: 23.
- *
+ * @param location The location of the crash. Can be null. Example: "MainActivity.java".
+ * @param line The line number of the crash. Can be null. Example: 42.
+ * @param column The column number of the crash. Can be null. Example: 23.
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
@@ -124,16 +115,15 @@ public static MatomoRequest.MatomoRequestBuilder crash(
@Nullable String stackTrace,
@Nullable String location,
@Nullable Integer line,
- @Nullable Integer column
- ) {
+ @Nullable Integer column) {
return MatomoRequest.request()
- .crashMessage(message)
- .crashType(type)
- .crashCategory(category)
- .crashStackTrace(stackTrace)
- .crashLocation(location)
- .crashLine(line)
- .crashColumn(column);
+ .crashMessage(message)
+ .crashType(type)
+ .crashCategory(category)
+ .crashStackTrace(stackTrace)
+ .crashLocation(location)
+ .crashLine(line)
+ .crashColumn(column);
}
/**
@@ -145,24 +135,19 @@ public static MatomoRequest.MatomoRequestBuilder crash(
* payment failure.
*
* @param throwable The throwable that caused the crash. Must not be null.
- * @param category The category of the crash. Can be null. Example: "payment failure".
- *
+ * @param category The category of the crash. Can be null. Example: "payment failure".
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
public static MatomoRequest.MatomoRequestBuilder crash(
- @NonNull Throwable throwable, @Nullable String category
- ) {
- return MatomoRequest
- .request()
+ @NonNull Throwable throwable, @Nullable String category) {
+ return MatomoRequest.request()
.crashMessage(throwable.getMessage())
.crashCategory(category)
.crashStackTrace(formatStackTrace(throwable))
.crashType(throwable.getClass().getName())
.crashLocation(
- getFirstStackTraceElement(throwable)
- .map(StackTraceElement::getFileName)
- .orElse(null))
+ getFirstStackTraceElement(throwable).map(StackTraceElement::getFileName).orElse(null))
.crashLine(
getFirstStackTraceElement(throwable)
.map(StackTraceElement::getLineNumber)
@@ -178,8 +163,7 @@ private static String formatStackTrace(@Nullable Throwable throwable) {
@edu.umd.cs.findbugs.annotations.NonNull
private static Optional The {@code revenue} parameter is required and should be the total revenue of the cart.
*
* @param revenue The total revenue of the cart. Must not be null.
- *
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
- public static MatomoRequest.MatomoRequestBuilder ecommerceCartUpdate(
- @NonNull Double revenue
- ) {
+ public static MatomoRequest.MatomoRequestBuilder ecommerceCartUpdate(@NonNull Double revenue) {
return MatomoRequest.request().ecommerceRevenue(revenue);
}
@@ -211,22 +192,20 @@ public static MatomoRequest.MatomoRequestBuilder ecommerceCartUpdate(
* and reported in Matomo reports.
*
* The {@code id} and {@code revenue} parameters are required and should be the order ID and
- * the total revenue of the order. The other parameters are optional. The {@code subtotal},
- * {@code tax}, {@code shippingCost} and {@code discount} parameters should be the subtotal, tax,
+ * the total revenue of the order. The other parameters are optional. The {@code subtotal}, {@code
+ * tax}, {@code shippingCost} and {@code discount} parameters should be the subtotal, tax,
* shipping cost and discount of the order.
*
- * If the Ecommerce order contains items (products), you must call
- * {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)} to add the items to
- * the request.
+ * If the Ecommerce order contains items (products), you must call {@link
+ * MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)} to add the items to the
+ * request.
*
- * @param id An order ID. Can be a stock keeping unit (SKU) or a unique ID. Must not be
- * null.
- * @param revenue The total revenue of the order. Must not be null.
- * @param subtotal The subtotal of the order. Can be null.
- * @param tax The tax of the order. Can be null.
+ * @param id An order ID. Can be a stock keeping unit (SKU) or a unique ID. Must not be null.
+ * @param revenue The total revenue of the order. Must not be null.
+ * @param subtotal The subtotal of the order. Can be null.
+ * @param tax The tax of the order. Can be null.
* @param shippingCost The shipping cost of the order. Can be null.
- * @param discount The discount of the order. Can be null.
- *
+ * @param discount The discount of the order. Can be null.
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
@@ -236,32 +215,30 @@ public static MatomoRequest.MatomoRequestBuilder ecommerceOrder(
@Nullable Double subtotal,
@Nullable Double tax,
@Nullable Double shippingCost,
- @Nullable Double discount
- ) {
+ @Nullable Double discount) {
return MatomoRequest.request()
- .ecommerceId(id)
- .ecommerceRevenue(revenue)
- .ecommerceSubtotal(subtotal)
- .ecommerceTax(tax)
- .ecommerceShippingCost(shippingCost)
- .ecommerceDiscount(discount);
+ .ecommerceId(id)
+ .ecommerceRevenue(revenue)
+ .ecommerceSubtotal(subtotal)
+ .ecommerceTax(tax)
+ .ecommerceShippingCost(shippingCost)
+ .ecommerceDiscount(discount);
}
/**
* Creates a {@link MatomoRequest} object for an event.
*
* The {@code category} and {@code action} parameters are required and should be the category
- * and action of the event. The {@code name} and {@code value} parameters are optional. The
- * {@code category} parameter should be a category of the event, like "Travel". The {@code action}
+ * and action of the event. The {@code name} and {@code value} parameters are optional. The {@code
+ * category} parameter should be a category of the event, like "Travel". The {@code action}
* parameter should be an action of the event, like "Book flight". The {@code name} parameter
* should be the name of the event, like "Flight to Berlin". The {@code value} parameter should be
* the value of the event, like the price of the flight.
*
* @param category The category of the event. Must not be null. Example: "Music"
- * @param action The action of the event. Must not be null. Example: "Play"
- * @param name The name of the event. Can be null. Example: "Edvard Grieg - The Death of Ase"
- * @param value The value of the event. Can be null. Example: 9.99
- *
+ * @param action The action of the event. Must not be null. Example: "Play"
+ * @param name The name of the event. Can be null. Example: "Edvard Grieg - The Death of Ase"
+ * @param value The value of the event. Can be null. Example: 9.99
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
@@ -269,13 +246,12 @@ public static MatomoRequest.MatomoRequestBuilder event(
@NonNull String category,
@NonNull String action,
@Nullable String name,
- @Nullable Double value
- ) {
+ @Nullable Double value) {
return MatomoRequest.request()
- .eventCategory(category)
- .eventAction(action)
- .eventName(name)
- .eventValue(value);
+ .eventCategory(category)
+ .eventAction(action)
+ .eventName(name)
+ .eventValue(value);
}
/**
@@ -286,15 +262,12 @@ public static MatomoRequest.MatomoRequestBuilder event(
* the revenue of the conversion. The {@code name} parameter should be the name of the conversion.
* The {@code value} parameter should be the value of the conversion.
*
- * @param id The ID of the goal. Must not be null. Example: 1
+ * @param id The ID of the goal. Must not be null. Example: 1
* @param revenue The revenue of the conversion. Can be null. Example: 9.99
- *
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
- public static MatomoRequest.MatomoRequestBuilder goal(
- int id, @Nullable Double revenue
- ) {
+ public static MatomoRequest.MatomoRequestBuilder goal(int id, @Nullable Double revenue) {
return MatomoRequest.request().goalId(id).ecommerceRevenue(revenue);
}
@@ -304,13 +277,10 @@ public static MatomoRequest.MatomoRequestBuilder goal(
* The {@code name} parameter is required and should be the name of the page.
*
* @param name The name of the page. Must not be null. Example: "Home"
- *
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
- public static MatomoRequest.MatomoRequestBuilder pageView(
- @NonNull String name
- ) {
+ public static MatomoRequest.MatomoRequestBuilder pageView(@NonNull String name) {
return MatomoRequest.request().actionName(name);
}
@@ -319,34 +289,32 @@ public static MatomoRequest.MatomoRequestBuilder pageView(
*
* These are used to populate reports in Actions > Site Search.
*
- * The {@code query} parameter is required and should be the search query. The {@code
- * category} and {@code resultsCount} parameters are optional. The {@code category} parameter
- * should be the category of the search, like "Music". The {@code resultsCount} parameter should
- * be the number of results of the search.
+ * The {@code query} parameter is required and should be the search query. The {@code category}
+ * and {@code resultsCount} parameters are optional. The {@code category} parameter should be the
+ * category of the search, like "Music". The {@code resultsCount} parameter should be the number
+ * of results of the search.
*
- * @param query The search query. Must not be null. Example: "Edvard Grieg"
- * @param category The category of the search. Can be null. Example: "Music"
+ * @param query The search query. Must not be null. Example: "Edvard Grieg"
+ * @param category The category of the search. Can be null. Example: "Music"
* @param resultsCount The number of results of the search. Can be null. Example: 42
- *
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@edu.umd.cs.findbugs.annotations.NonNull
public static MatomoRequest.MatomoRequestBuilder siteSearch(
- @NonNull String query, @Nullable String category, @Nullable Long resultsCount
- ) {
+ @NonNull String query, @Nullable String category, @Nullable Long resultsCount) {
return MatomoRequest.request()
- .searchQuery(query)
- .searchCategory(category)
- .searchResultsCount(resultsCount);
+ .searchQuery(query)
+ .searchCategory(category)
+ .searchResultsCount(resultsCount);
}
/**
* Creates a {@link MatomoRequest} object for a ping.
*
- * Ping requests do not track new actions. If they are sent within the standard visit
- * length (see global.ini.php), they will extend the existing visit and the current last action
- * for the visit. If after the standard visit length, ping requests will create a new visit using
- * the last action in the last known visit.
+ * Ping requests do not track new actions. If they are sent within the standard visit length
+ * (see global.ini.php), they will extend the existing visit and the current last action for the
+ * visit. If after the standard visit length, ping requests will create a new visit using the last
+ * action in the last known visit.
*
* @return A {@link MatomoRequest.MatomoRequestBuilder} object to add additional parameters.
*/
@@ -354,6 +322,4 @@ public static MatomoRequest.MatomoRequestBuilder siteSearch(
public static MatomoRequest.MatomoRequestBuilder ping() {
return MatomoRequest.request().ping(true);
}
-
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java b/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
index 3c38d017..0b382ecc 100644
--- a/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
+++ b/core/src/main/java/org/matomo/java/tracking/MatomoTracker.java
@@ -23,13 +23,14 @@
/**
* The main class that sends {@link MatomoRequest}s to a specified Matomo server.
*
- * Contains several methods to send requests synchronously and asynchronously. The asynchronous methods return a
- * {@link CompletableFuture} that can be used to wait for the request to finish. The synchronous methods block until
- * the request is finished. The asynchronous methods are more efficient if you want to send multiple requests at once.
+ * Contains several methods to send requests synchronously and asynchronously. The asynchronous
+ * methods return a {@link CompletableFuture} that can be used to wait for the request to finish.
+ * The synchronous methods block until the request is finished. The asynchronous methods are more
+ * efficient if you want to send multiple requests at once.
*
- * Configure this tracker using the {@link TrackerConfiguration} class. You can use the
- * {@link TrackerConfiguration#builder()} to create a new configuration. The configuration is immutable and can be
- * reused for multiple trackers.
+ * Configure this tracker using the {@link TrackerConfiguration} class. You can use the {@link
+ * TrackerConfiguration#builder()} to create a new configuration. The configuration is immutable and
+ * can be reused for multiple trackers.
*
* The tracker is thread-safe and can be used by multiple threads at once.
*
@@ -46,60 +47,55 @@ public class MatomoTracker implements AutoCloseable {
private Sender sender;
/**
- * Creates a tracker that will send {@link MatomoRequest}s to the specified
- * Tracking HTTP API endpoint.
+ * Creates a tracker that will send {@link MatomoRequest}s to the specified Tracking HTTP API
+ * endpoint.
*
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * https://your-matomo-domain.tld/matomo.php. Must not be null
+ * @param hostUrl url endpoint to send requests to. Usually in the format
+ * https://your-matomo-domain.tld/matomo.php. Must not be null
* @deprecated Please use {@link MatomoTracker#MatomoTracker(TrackerConfiguration)}
*/
@Deprecated
- public MatomoTracker(
- @NonNull String hostUrl
- ) {
+ public MatomoTracker(@NonNull String hostUrl) {
this(hostUrl, 0);
}
/**
- * Creates a tracker that will send {@link MatomoRequest}s to the specified
- * Tracking HTTP API endpoint.
+ * Creates a tracker that will send {@link MatomoRequest}s to the specified Tracking HTTP API
+ * endpoint.
*
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * https://your-matomo-domain.tld/matomo.php.
+ * @param hostUrl url endpoint to send requests to. Usually in the format
+ * https://your-matomo-domain.tld/matomo.php.
* @param timeout the timeout of the sent request in milliseconds or -1 if not set
* @deprecated Please use {@link MatomoTracker#MatomoTracker(TrackerConfiguration)}
*/
@Deprecated
- public MatomoTracker(
- @NonNull String hostUrl, int timeout
- ) {
+ public MatomoTracker(@NonNull String hostUrl, int timeout) {
this(hostUrl, null, 0, timeout);
}
/**
- * Creates a tracker that will send {@link MatomoRequest}s to the specified
- * Tracking HTTP API endpoint.
+ * Creates a tracker that will send {@link MatomoRequest}s to the specified Tracking HTTP API
+ * endpoint.
*
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * https://your-matomo-domain.tld/matomo.php.
+ * @param hostUrl url endpoint to send requests to. Usually in the format
+ * https://your-matomo-domain.tld/matomo.php.
* @param proxyHost The hostname or IP address of an optional HTTP proxy, null allowed
* @param proxyPort The port of an HTTP proxy or -1 if not set
- * @param timeout the timeout of the request in milliseconds or -1 if not set
+ * @param timeout the timeout of the request in milliseconds or -1 if not set
* @deprecated Please use {@link MatomoTracker#MatomoTracker(TrackerConfiguration)}
*/
@Deprecated
public MatomoTracker(
- @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort, int timeout
- ) {
- this(TrackerConfiguration
- .builder()
- .enabled(true)
- .apiEndpoint(URI.create(hostUrl))
- .proxyHost(proxyHost)
- .proxyPort(proxyPort)
- .connectTimeout(timeout == -1 ? Duration.ofSeconds(5L) : Duration.ofSeconds(timeout))
- .socketTimeout(timeout == -1 ? Duration.ofSeconds(5L) : Duration.ofSeconds(timeout))
- .build());
+ @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort, int timeout) {
+ this(
+ TrackerConfiguration.builder()
+ .enabled(true)
+ .apiEndpoint(URI.create(hostUrl))
+ .proxyHost(proxyHost)
+ .proxyPort(proxyPort)
+ .connectTimeout(timeout == -1 ? Duration.ofSeconds(5L) : Duration.ofSeconds(timeout))
+ .socketTimeout(timeout == -1 ? Duration.ofSeconds(5L) : Duration.ofSeconds(timeout))
+ .build());
}
/**
@@ -107,36 +103,33 @@ public MatomoTracker(
*
* @param trackerConfiguration Configurations parameters (you can use a builder)
*/
- public MatomoTracker(
- @NonNull TrackerConfiguration trackerConfiguration
- ) {
+ public MatomoTracker(@NonNull TrackerConfiguration trackerConfiguration) {
trackerConfiguration.validate();
this.trackerConfiguration = trackerConfiguration;
}
/**
- * Creates a tracker that will send {@link MatomoRequest}s to the specified
- * Tracking HTTP API endpoint via the provided proxy.
+ * Creates a tracker that will send {@link MatomoRequest}s to the specified Tracking HTTP API
+ * endpoint via the provided proxy.
*
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * https://your-matomo-domain.tld/matomo.php.
+ * @param hostUrl url endpoint to send requests to. Usually in the format
+ * https://your-matomo-domain.tld/matomo.php.
* @param proxyHost url endpoint for the proxy, null allowed
* @param proxyPort proxy server port number or -1 if not set
* @deprecated Please use {@link MatomoTracker#MatomoTracker(TrackerConfiguration)}
*/
@Deprecated
- public MatomoTracker(
- @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort
- ) {
+ public MatomoTracker(@NonNull String hostUrl, @Nullable String proxyHost, int proxyPort) {
this(hostUrl, proxyHost, proxyPort, -1);
}
/**
* Sends a tracking request to Matomo using the HTTP GET method.
*
- * Use this method if you want to send a single request. If you want to send multiple requests at once, use
- * {@link #sendBulkRequest(Iterable)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendRequestAsync(MatomoRequest)} or {@link #sendBulkRequestAsync(Collection)} instead.
+ * Use this method if you want to send a single request. If you want to send multiple requests
+ * at once, use {@link #sendBulkRequest(Iterable)} instead. If you want to send multiple requests
+ * asynchronously, use {@link #sendRequestAsync(MatomoRequest)} or {@link
+ * #sendBulkRequestAsync(Collection)} instead.
*
* @param request request to send. must not be null
*/
@@ -153,45 +146,45 @@ public void sendRequest(@NonNull MatomoRequest request) {
private void initializeSender() {
if (sender == null) {
- sender = senderFactory.createSender(trackerConfiguration, new QueryCreator(trackerConfiguration));
+ sender =
+ senderFactory.createSender(trackerConfiguration, new QueryCreator(trackerConfiguration));
}
}
/**
* Send a request asynchronously via HTTP GET.
*
- * Use this method if you want to send a single request. If you want to send multiple requests at once, use
- * {@link #sendBulkRequestAsync(Collection)} instead. If you want to send multiple requests synchronously, use
- * {@link #sendRequest(MatomoRequest)} or {@link #sendBulkRequest(Iterable)} instead.
+ * Use this method if you want to send a single request. If you want to send multiple requests
+ * at once, use {@link #sendBulkRequestAsync(Collection)} instead. If you want to send multiple
+ * requests synchronously, use {@link #sendRequest(MatomoRequest)} or {@link
+ * #sendBulkRequest(Iterable)} instead.
*
* @param request request to send
* @return completable future to let you know when the request is done. Contains the request.
*/
- public CompletableFuture Use this method if you want to send a single request. If you want to send multiple requests at once, use
- * {@link #sendBulkRequestAsync(Collection, Consumer)} instead. If you want to send multiple requests synchronously,
- * use {@link #sendRequest(MatomoRequest)} or {@link #sendBulkRequest(Iterable)} instead.
+ * Use this method if you want to send a single request. If you want to send multiple requests
+ * at once, use {@link #sendBulkRequestAsync(Collection, Consumer)} instead. If you want to send
+ * multiple requests synchronously, use {@link #sendRequest(MatomoRequest)} or {@link
+ * #sendBulkRequest(Iterable)} instead.
*
- * @param request request to send
+ * @param request request to send
* @param callback callback that gets executed when response arrives, must not be null
- * @return a completable future to let you know when the request is done. The future contains
- * the callback result.
- * @deprecated Please use {@link MatomoTracker#sendRequestAsync(MatomoRequest)} in combination with
- * {@link CompletableFuture#thenAccept(Consumer)} instead
+ * @return a completable future to let you know when the request is done. The future contains the
+ * callback result.
+ * @deprecated Please use {@link MatomoTracker#sendRequestAsync(MatomoRequest)} in combination
+ * with {@link CompletableFuture#thenAccept(Consumer)} instead
*/
@Deprecated
public More efficient than sending several individual requests. If you want to send a single request, use
- * {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Collection)} instead.
+ * More efficient than sending several individual requests. If you want to send a single
+ * request, use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests
+ * asynchronously, use {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param requests the requests to send
*/
@@ -235,9 +229,9 @@ public void sendBulkRequest(MatomoRequest... requests) {
/**
* Send multiple requests in a single HTTP POST call.
*
- * More efficient than sending several individual requests. If you want to send a single request, use
- * {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Collection)} instead.
+ * More efficient than sending several individual requests. If you want to send a single
+ * request, use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests
+ * asynchronously, use {@link #sendBulkRequestAsync(Collection)} instead.
*
* @param requests the requests to send
*/
@@ -246,23 +240,22 @@ public void sendBulkRequest(@NonNull Iterable extends MatomoRequest> requests)
}
/**
- * Send multiple requests in a single HTTP POST call. More efficient than sending
- * several individual requests.
+ * Send multiple requests in a single HTTP POST call. More efficient than sending several
+ * individual requests.
*
- * Specify the AuthToken if parameters that require an auth token is used. If you want to send a single request,
- * use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple requests asynchronously, use
- * {@link #sendBulkRequestAsync(Collection)} instead.
+ * Specify the AuthToken if parameters that require an auth token is used. If you want to send
+ * a single request, use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple
+ * requests asynchronously, use {@link #sendBulkRequestAsync(Collection)} instead.
*
- * @param requests the requests to send
- * @param authToken specify if any of the parameters use require AuthToken, if null the default auth token from the
- * request or the tracker configuration is used.
- * @deprecated use {@link #sendBulkRequest(Iterable)} instead and set the auth token in the tracker configuration or
- * the requests directly.
+ * @param requests the requests to send
+ * @param authToken specify if any of the parameters use require AuthToken, if null the default
+ * auth token from the request or the tracker configuration is used.
+ * @deprecated use {@link #sendBulkRequest(Iterable)} instead and set the auth token in the
+ * tracker configuration or the requests directly.
*/
@Deprecated
public void sendBulkRequest(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String authToken
- ) {
+ @NonNull Iterable extends MatomoRequest> requests, @Nullable String authToken) {
if (trackerConfiguration.isEnabled()) {
for (MatomoRequest request : requests) {
applyGoalIdAndCheckSiteId(request);
@@ -276,8 +269,8 @@ public void sendBulkRequest(
}
/**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests.
+ * Send multiple requests in a single HTTP call. More efficient than sending several individual
+ * requests.
*
* @param requests the requests to send
* @return completable future to let you know when the request is done
@@ -287,37 +280,34 @@ public CompletableFuture A timeout value of zero is interpreted as an infinite timeout.
- * A `null` value is interpreted as undefined (system default if applicable). A timeout value of zero is interpreted as an infinite timeout. A `null` value is interpreted
+ * as undefined (system default if applicable).
*
- * Default: 5 seconds Default: 5 seconds
*/
- @Builder.Default
- Duration connectTimeout = Duration.ofSeconds(5L);
+ @Builder.Default Duration connectTimeout = Duration.ofSeconds(5L);
/**
- * The socket timeout ({@code SO_TIMEOUT}), which is the timeout for waiting for data or, put differently, a maximum
- * period inactivity between two consecutive data packets.
+ * The socket timeout ({@code SO_TIMEOUT}), which is the timeout for waiting for data or, put
+ * differently, a maximum period inactivity between two consecutive data packets.
*
- * A timeout value of zero is interpreted as an infinite timeout.
- * A `null value is interpreted as undefined (system default if applicable). A timeout value of zero is interpreted as an infinite timeout. A `null value is interpreted
+ * as undefined (system default if applicable).
*
- * Default: 5 seconds Default: 5 seconds
*/
- @Builder.Default
- Duration socketTimeout = Duration.ofSeconds(5L);
+ @Builder.Default Duration socketTimeout = Duration.ofSeconds(5L);
/**
- * The hostname or IP address of an optional HTTP proxy. {@code proxyPort} must be configured as well
+ * The hostname or IP address of an optional HTTP proxy. {@code proxyPort} must be configured as
+ * well
*/
- @Nullable
- String proxyHost;
+ @Nullable String proxyHost;
- /**
- * The port of an HTTP proxy. {@code proxyHost} must be configured as well.
- */
+ /** The port of an HTTP proxy. {@code proxyHost} must be configured as well. */
int proxyPort;
/**
- * If the HTTP proxy requires a username for basic authentication, it can be configured here. Proxy host, port and
- * password must also be set.
+ * If the HTTP proxy requires a username for basic authentication, it can be configured here.
+ * Proxy host, port and password must also be set.
*/
- @Nullable
- String proxyUsername;
+ @Nullable String proxyUsername;
/**
- * The corresponding password for the basic auth proxy user. The proxy host, port and username must be set as well.
+ * The corresponding password for the basic auth proxy user. The proxy host, port and username
+ * must be set as well.
*/
- @Nullable
- String proxyPassword;
+ @Nullable String proxyPassword;
- /**
- * A custom user agent to be set. Defaults to "MatomoJavaClient"
- */
- @Builder.Default
- String userAgent = "MatomoJavaClient";
+ /** A custom user agent to be set. Defaults to "MatomoJavaClient" */
+ @Builder.Default String userAgent = "MatomoJavaClient";
/**
* Logs if the Matomo Tracking API endpoint responds with an erroneous HTTP code. Defaults to
@@ -108,7 +91,7 @@ public class TrackerConfiguration {
* Do not use in production environments. Defaults to false.
*
* Attention: This slows down performance
-
+ *
* @see #disableSslHostVerification
*/
boolean disableSslCertValidation;
@@ -119,8 +102,8 @@ public class TrackerConfiguration {
*
* If you use the Java 11 of the Matomo Java Tracker, this setting is ignored. Instead, you
* have to set the system property {@code jdk.internal.httpclient.disableHostnameVerification} as
- * described in the
- * Module
+ * described in the Module
* java.net.http.
*
* @see #disableSslCertValidation
@@ -131,15 +114,11 @@ public class TrackerConfiguration {
* The thread pool size for the async sender. Defaults to 2.
*
* Attention: If you use this library in a web application, make sure that this thread pool
- * does not exceed the thread pool of the web application. Otherwise, you might run into
- * problems.
+ * does not exceed the thread pool of the web application. Otherwise, you might run into problems.
*/
- @Builder.Default
- int threadPoolSize = 2;
+ @Builder.Default int threadPoolSize = 2;
- /**
- * Validates the auth token. The auth token must be exactly 32 characters long.
- */
+ /** Validates the auth token. The auth token must be exactly 32 characters long. */
public void validate() {
if (apiEndpoint == null) {
throw new IllegalArgumentException("API endpoint must not be null");
diff --git a/core/src/main/java/org/matomo/java/tracking/TrackingParameter.java b/core/src/main/java/org/matomo/java/tracking/TrackingParameter.java
index 0b9d82bc..1e11181f 100644
--- a/core/src/main/java/org/matomo/java/tracking/TrackingParameter.java
+++ b/core/src/main/java/org/matomo/java/tracking/TrackingParameter.java
@@ -25,5 +25,4 @@
double max() default Double.MAX_VALUE;
int maxLength() default Integer.MAX_VALUE;
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/TrackingParameterMethod.java b/core/src/main/java/org/matomo/java/tracking/TrackingParameterMethod.java
index 2540ea0c..82556dba 100644
--- a/core/src/main/java/org/matomo/java/tracking/TrackingParameterMethod.java
+++ b/core/src/main/java/org/matomo/java/tracking/TrackingParameterMethod.java
@@ -30,38 +30,32 @@ class TrackingParameterMethod {
int maxLength;
void validateParameterValue(@NonNull Object parameterValue) {
- if (pattern != null && parameterValue instanceof CharSequence && !pattern
- .matcher((CharSequence) parameterValue)
- .matches()) {
- throw new MatomoException(String.format("Invalid value for %s. Must match regex %s",
- parameterName,
- pattern
- ));
+ if (pattern != null
+ && parameterValue instanceof CharSequence
+ && !pattern.matcher((CharSequence) parameterValue).matches()) {
+ throw new MatomoException(
+ String.format("Invalid value for %s. Must match regex %s", parameterName, pattern));
}
if (maxLength != 0 && parameterValue.toString().length() > maxLength) {
- throw new MatomoException(String.format("Invalid value for %s. Must be less or equal than %d characters",
- parameterName,
- maxLength
- ));
+ throw new MatomoException(
+ String.format(
+ "Invalid value for %s. Must be less or equal than %d characters",
+ parameterName, maxLength));
}
if (parameterValue instanceof Number) {
Number number = (Number) parameterValue;
if (number.doubleValue() < min) {
- throw new MatomoException(String.format(
- "Invalid value for %s. Must be greater or equal than %s",
- parameterName,
- min % 1 == 0 ? Long.toString((long) min) : min
- ));
-
+ throw new MatomoException(
+ String.format(
+ "Invalid value for %s. Must be greater or equal than %s",
+ parameterName, min % 1 == 0 ? Long.toString((long) min) : min));
}
if (number.doubleValue() > max) {
- throw new MatomoException(String.format(
- "Invalid value for %s. Must be less or equal than %s",
- parameterName,
- max % 1 == 0 ? Long.toString((long) max) : max
- ));
+ throw new MatomoException(
+ String.format(
+ "Invalid value for %s. Must be less or equal than %s",
+ parameterName, max % 1 == 0 ? Long.toString((long) max) : max));
}
}
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/TrustingX509TrustManager.java b/core/src/main/java/org/matomo/java/tracking/TrustingX509TrustManager.java
index 790db746..3e742f9f 100644
--- a/core/src/main/java/org/matomo/java/tracking/TrustingX509TrustManager.java
+++ b/core/src/main/java/org/matomo/java/tracking/TrustingX509TrustManager.java
@@ -13,16 +13,12 @@ public X509Certificate[] getAcceptedIssuers() {
}
@Override
- public void checkClientTrusted(
- @Nullable X509Certificate[] chain, @Nullable String authType
- ) {
+ public void checkClientTrusted(@Nullable X509Certificate[] chain, @Nullable String authType) {
// no operation
}
@Override
- public void checkServerTrusted(
- @Nullable X509Certificate[] chain, @Nullable String authType
- ) {
+ public void checkServerTrusted(@Nullable X509Certificate[] chain, @Nullable String authType) {
// no operation
}
}
diff --git a/core/src/main/java/org/matomo/java/tracking/package-info.java b/core/src/main/java/org/matomo/java/tracking/package-info.java
index 5c08c6dc..3a56acd9 100644
--- a/core/src/main/java/org/matomo/java/tracking/package-info.java
+++ b/core/src/main/java/org/matomo/java/tracking/package-info.java
@@ -1,13 +1,12 @@
/**
- * This package contains classes that allow you to specify a {@link org.matomo.java.tracking.MatomoTracker}
- * with the corresponding {@link org.matomo.java.tracking.TrackerConfiguration}. You can then send a
- * {@link org.matomo.java.tracking.MatomoRequest} as a single HTTP GET request or multiple requests as a bulk HTTP POST
- * request synchronously or asynchronously. If an exception occurs, {@link org.matomo.java.tracking.MatomoException}
- * will be thrown.
+ * This package contains classes that allow you to specify a {@link
+ * org.matomo.java.tracking.MatomoTracker} with the corresponding {@link
+ * org.matomo.java.tracking.TrackerConfiguration}. You can then send a {@link
+ * org.matomo.java.tracking.MatomoRequest} as a single HTTP GET request or multiple requests as a
+ * bulk HTTP POST request synchronously or asynchronously. If an exception occurs, {@link
+ * org.matomo.java.tracking.MatomoException} will be thrown.
*
- * For more information about the Matomo Tracking HTTP API, see the Matomo Tracking HTTP API.
+ * For more information about the Matomo Tracking HTTP API, see the Matomo Tracking HTTP API.
*/
-
package org.matomo.java.tracking;
-
-
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/AcceptLanguage.java b/core/src/main/java/org/matomo/java/tracking/parameters/AcceptLanguage.java
index 0ecee82d..cb4ea46e 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/AcceptLanguage.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/AcceptLanguage.java
@@ -18,8 +18,9 @@
import lombok.Value;
/**
- * Describes the content for the Accept-Language header field that can be overridden by a custom parameter. The format
- * is specified in the corresponding RFC 4647 Matching of Language Tags
+ * Describes the content for the Accept-Language header field that can be overridden by a custom
+ * parameter. The format is specified in the corresponding RFC 4647 Matching of Language Tags
*
* Example: "en-US,en;q=0.8,de;q=0.6"
*/
@@ -27,23 +28,20 @@
@Value
public class AcceptLanguage {
- @Singular
- List Please see {@link LanguageRange#parse(String)} for more information. Example: "en-US,en;q=0.8,de;q=0.6"
+ * Please see {@link LanguageRange#parse(String)} for more information. Example:
+ * "en-US,en;q=0.8,de;q=0.6"
*
* @param header A header that can be null
* @return The parsed header (probably reformatted). null if the header is null.
* @see LanguageRange#parse(String)
*/
@Nullable
- public static AcceptLanguage fromHeader(
- @Nullable
- String header
- ) {
+ public static AcceptLanguage fromHeader(@Nullable String header) {
if (header == null || header.trim().isEmpty()) {
return null;
}
@@ -57,19 +55,15 @@ public static AcceptLanguage fromHeader(
*/
@NonNull
public String toString() {
- return languageRanges
- .stream()
+ return languageRanges.stream()
.filter(Objects::nonNull)
.map(AcceptLanguage::format)
.collect(Collectors.joining(","));
}
- private static String format(
- @NonNull
- LanguageRange languageRange
- ) {
- return languageRange.getWeight() == LanguageRange.MAX_WEIGHT ? languageRange.getRange() :
- String.format("%s;q=%s", languageRange.getRange(), languageRange.getWeight());
+ private static String format(@NonNull LanguageRange languageRange) {
+ return languageRange.getWeight() == LanguageRange.MAX_WEIGHT
+ ? languageRange.getRange()
+ : String.format("%s;q=%s", languageRange.getRange(), languageRange.getWeight());
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/Country.java b/core/src/main/java/org/matomo/java/tracking/parameters/Country.java
index ab51e14f..aff24465 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/Country.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/Country.java
@@ -18,24 +18,22 @@
/**
* A two-letter country code representing a country.
*
- * See ISO 3166-1 alpha-2 for a list of valid codes.
+ * See ISO 3166-1 alpha-2 for a
+ * list of valid codes.
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class Country {
- @NonNull
- private String code;
+ @NonNull private String code;
/**
- * Only for internal use to grant downwards compatibility to {@link org.matomo.java.tracking.MatomoLocale}.
+ * Only for internal use to grant downwards compatibility to {@link
+ * org.matomo.java.tracking.MatomoLocale}.
*
* @param locale A locale that must contain a country code
*/
@Deprecated
- protected Country(
- @edu.umd.cs.findbugs.annotations.NonNull
- Locale locale
- ) {
+ protected Country(@edu.umd.cs.findbugs.annotations.NonNull Locale locale) {
setLocale(locale);
}
@@ -46,10 +44,7 @@ protected Country(
* @return The country or null if code was null
*/
@Nullable
- public static Country fromCode(
- @Nullable
- String code
- ) {
+ public static Country fromCode(@Nullable String code) {
if (code == null || code.isEmpty() || code.trim().isEmpty()) {
return null;
}
@@ -66,10 +61,7 @@ public static Country fromCode(
* @return The country or null if ranges was null
*/
@Nullable
- public static Country fromLanguageRanges(
- @Nullable
- String ranges
- ) {
+ public static Country fromLanguageRanges(@Nullable String ranges) {
if (ranges == null || ranges.isEmpty() || ranges.trim().isEmpty()) {
return null;
}
@@ -89,8 +81,8 @@ public static Country fromLanguageRanges(
*
* @return The locale for this country
* @see Locale#forLanguageTag(String)
- * @deprecated Since you instantiate this class, you can determine the language on your own
- * using {@link Locale#forLanguageTag(String)}
+ * @deprecated Since you instantiate this class, you can determine the language on your own using
+ * {@link Locale#forLanguageTag(String)}
*/
@Deprecated
public Locale getLocale() {
@@ -102,8 +94,8 @@ public Locale getLocale() {
*
* @param locale A locale that must contain a country code
* @see Locale#getCountry()
- * @deprecated Since you instantiate this class, you can determine the language on your own
- * using {@link Locale#getCountry()}
+ * @deprecated Since you instantiate this class, you can determine the language on your own using
+ * {@link Locale#getCountry()}
*/
@Deprecated
public final void setLocale(Locale locale) {
@@ -117,5 +109,4 @@ public final void setLocale(Locale locale) {
public String toString() {
return code;
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariable.java b/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariable.java
index 0f6a3fa9..45cbf58a 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariable.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariable.java
@@ -15,15 +15,18 @@
import lombok.ToString;
/**
- * A key-value pair that represents custom information. See
- * How do I use Custom Variables?
+ * A key-value pair that represents custom information. See How do I use
+ * Custom Variables?
*
- * If you are not already using Custom Variables to measure your custom data, Matomo recommends to use the
- * Custom Dimensions feature instead.
- * There are many advantages of Custom Dimensions over Custom
- * variables. Custom variables will be deprecated in the future.
+ * If you are not already using Custom Variables to measure your custom data, Matomo recommends
+ * to use the Custom Dimensions feature
+ * instead. There are many advantages of Custom
+ * Dimensions over Custom variables. Custom variables will be deprecated in the future.
*
- * @deprecated Should not be used according to the Matomo FAQ: How do I use Custom Variables?
+ * @deprecated Should not be used according to the Matomo FAQ: How do I use
+ * Custom Variables?
*/
@Getter
@Setter
@@ -35,16 +38,14 @@ public class CustomVariable {
private int index;
- @NonNull
- private String key;
+ @NonNull private String key;
- @NonNull
- private String value;
+ @NonNull private String value;
/**
* Instantiates a new custom variable.
*
- * @param key the key of the custom variable (required)
+ * @param key the key of the custom variable (required)
* @param value the value of the custom variable (required)
*/
public CustomVariable(@NonNull String key, @NonNull String value) {
@@ -52,6 +53,3 @@ public CustomVariable(@NonNull String key, @NonNull String value) {
this.value = value;
}
}
-
-
-
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariables.java b/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariables.java
index 4fee72df..acd2e041 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariables.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/CustomVariables.java
@@ -17,9 +17,13 @@
import lombok.NonNull;
/**
- * A bunch of key-value pairs that represent custom information. See How do I use Custom Variables?
+ * A bunch of key-value pairs that represent custom information. See How do I use
+ * Custom Variables?
*
- * @deprecated Should not be used according to the Matomo FAQ: How do I use Custom Variables?
+ * @deprecated Should not be used according to the Matomo FAQ: How do I use
+ * Custom Variables?
*/
@EqualsAndHashCode
@Deprecated
@@ -60,7 +64,7 @@ public CustomVariables add(@NonNull CustomVariable variable) {
/**
* Adds a custom variable to the list with the given index.
*
- * @param cv The custom variable to add
+ * @param cv The custom variable to add
* @param index The index to add the custom variable at
* @return This object for method chaining
*/
@@ -89,20 +93,20 @@ public CustomVariable get(int index) {
}
/**
- * Returns the value of the custom variable with the given key. If there are multiple custom variables with the same
- * key, the first one is returned. If there is no custom variable with the given key, null is returned.
+ * Returns the value of the custom variable with the given key. If there are multiple custom
+ * variables with the same key, the first one is returned. If there is no custom variable with the
+ * given key, null is returned.
*
* @param key The key of the custom variable. Must not be null.
- * @return The value of the custom variable with the given key. null if there is no variable with the given key.
+ * @return The value of the custom variable with the given key. null if there is no variable with
+ * the given key.
*/
@Nullable
public String get(@NonNull String key) {
if (key.isEmpty()) {
throw new IllegalArgumentException("key must not be null or empty");
}
- return variables
- .values()
- .stream()
+ return variables.values().stream()
.filter(variable -> variable.getKey().equals(key))
.findFirst()
.map(CustomVariable::getValue)
@@ -110,7 +114,8 @@ public String get(@NonNull String key) {
}
/**
- * Removes the custom variable at the given index. If there is no custom variable at the given index, nothing happens.
+ * Removes the custom variable at the given index. If there is no custom variable at the given
+ * index, nothing happens.
*
* @param index The index of the custom variable to remove. Must be greater than 0.
*/
@@ -120,7 +125,8 @@ public void remove(int index) {
}
/**
- * Removes the custom variable with the given key. If there is no custom variable with the given key, nothing happens.
+ * Removes the custom variable with the given key. If there is no custom variable with the given
+ * key, nothing happens.
*
* @param key The key of the custom variable to remove. Must not be null.
*/
@@ -132,7 +138,6 @@ boolean isEmpty() {
return variables.isEmpty();
}
-
/**
* Parses a JSON representation of custom variables.
*
@@ -179,8 +184,8 @@ public static CustomVariables parse(@Nullable String value) {
}
/**
- * Creates a JSON representation of the custom variables. The format is as follows:
- * {@code {"1":["key1","value1"],"2":["key2","value2"]}}
+ * Creates a JSON representation of the custom variables. The format is as follows: {@code
+ * {"1":["key1","value1"],"2":["key2","value2"]}}
*
* @return A JSON representation of the custom variables
*/
@@ -205,5 +210,4 @@ public String toString() {
stringBuilder.append('}');
return stringBuilder.toString();
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/DeviceResolution.java b/core/src/main/java/org/matomo/java/tracking/parameters/DeviceResolution.java
index 6729443c..f466dd83 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/DeviceResolution.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/DeviceResolution.java
@@ -11,9 +11,7 @@
import lombok.Builder;
import lombok.RequiredArgsConstructor;
-/**
- * The resolution (width and height) of the user's output device (monitor / phone).
- */
+/** The resolution (width and height) of the user's output device (monitor / phone). */
@Builder
@RequiredArgsConstructor
public class DeviceResolution {
@@ -31,10 +29,7 @@ public class DeviceResolution {
* @return The device resolution representation
*/
@Nullable
- public static DeviceResolution fromString(
- @Nullable
- String deviceResolution
- ) {
+ public static DeviceResolution fromString(@Nullable String deviceResolution) {
if (deviceResolution == null || deviceResolution.trim().isEmpty()) {
return null;
}
@@ -55,5 +50,4 @@ public static DeviceResolution fromString(
public String toString() {
return String.format("%dx%d", width, height);
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItem.java b/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItem.java
index 7f5ba051..124158f8 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItem.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItem.java
@@ -12,9 +12,7 @@
import lombok.Getter;
import lombok.Setter;
-/**
- * Represents an item in an ecommerce order.
- */
+/** Represents an item in an ecommerce order. */
@Builder
@AllArgsConstructor
@Getter
@@ -23,17 +21,13 @@ public class EcommerceItem {
private String sku;
- @Builder.Default
- private String name = "";
+ @Builder.Default private String name = "";
- @Builder.Default
- private String category = "";
+ @Builder.Default private String category = "";
- @Builder.Default
- private Double price = 0.0;
+ @Builder.Default private Double price = 0.0;
- @Builder.Default
- private Integer quantity = 0;
+ @Builder.Default private Integer quantity = 0;
public String toString() {
return String.format("[\"%s\",\"%s\",\"%s\",%s,%d]", sku, name, category, price, quantity);
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItems.java b/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItems.java
index 7000ded7..8cf47357 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItems.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/EcommerceItems.java
@@ -19,9 +19,7 @@
import lombok.Singular;
import lombok.experimental.Delegate;
-/**
- * Multiple things that you can buy online.
- */
+/** Multiple things that you can buy online. */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@@ -30,12 +28,9 @@
@Setter
public class EcommerceItems {
- @Delegate
- @Singular
- private List Please consider creating a fixed id for each visitor by getting a hash code from e.g. the username and
- * using {@link #fromHash(long)} or {@link #fromString(String)} instead of using this method.
+ * Please consider creating a fixed id for each visitor by getting a hash code from e.g. the
+ * username and using {@link #fromHash(long)} or {@link #fromString(String)} instead of using this
+ * method.
*
* @return A randomly generated visitor id
*/
@@ -44,8 +45,8 @@ public static VisitorId random() {
/**
* Creates always the same visitor id for the given input.
*
- * You can use e.g. {@link Object#hashCode()} to generate a hash code for an object, e.g. a username
- * string as input.
+ * You can use e.g. {@link Object#hashCode()} to generate a hash code for an object, e.g. a
+ * username string as input.
*
* @param hash A number (a hash code) to create the visitor id from
* @return Always the same visitor id for the same input
@@ -77,8 +78,8 @@ public static VisitorId fromUUID(@NonNull UUID uuid) {
/**
* Creates a visitor id from a hexadecimal string.
*
- * The input must be a valid hexadecimal string with a maximum length of 16 characters. If the input is shorter
- * than 16 characters it will be padded with zeros. The input must be a valid hexadecimal string with a maximum length of 16 characters. If the
+ * input is shorter than 16 characters it will be padded with zeros.
*
* @param inputHex A hexadecimal string to create the visitor id from
* @return The visitor id for the given input
@@ -95,10 +96,10 @@ public static VisitorId fromHex(@NonNull String inputHex) {
throw new IllegalArgumentException("Input must be a valid hex string");
}
VisitorId visitorId = new VisitorId();
- for (int charIndex = inputHex.length() - 1, representationIndex =
- visitorId.representation.length - 1;
- charIndex >= 0;
- charIndex -= 2, representationIndex--) {
+ for (int charIndex = inputHex.length() - 1,
+ representationIndex = visitorId.representation.length - 1;
+ charIndex >= 0;
+ charIndex -= 2, representationIndex--) {
String hex = inputHex.substring(Math.max(0, charIndex - 1), charIndex + 1);
try {
visitorId.representation[representationIndex] = (byte) Integer.parseInt(hex, 16);
@@ -128,5 +129,4 @@ public static VisitorId fromString(@Nullable String str) {
public String toString() {
return Hex.fromBytes(representation);
}
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/parameters/package-info.java b/core/src/main/java/org/matomo/java/tracking/parameters/package-info.java
index f709edce..89f96f81 100644
--- a/core/src/main/java/org/matomo/java/tracking/parameters/package-info.java
+++ b/core/src/main/java/org/matomo/java/tracking/parameters/package-info.java
@@ -1,9 +1,9 @@
/**
- * Contains types for Matomo Tracking Parameters according to
- * the Matomo Tracking HTTP API.
+ * Contains types for Matomo Tracking Parameters according to the Matomo Tracking HTTP API.
*
- * The types help you to use the correct format for the tracking parameters. The package was introduced in Matomo
- * Java Tracker version 3 to let the tracker be more self-explanatory and better maintainable.
+ * The types help you to use the correct format for the tracking parameters. The package was
+ * introduced in Matomo Java Tracker version 3 to let the tracker be more self-explanatory and
+ * better maintainable.
*/
-
package org.matomo.java.tracking.parameters;
diff --git a/core/src/main/java/org/matomo/java/tracking/servlet/CookieWrapper.java b/core/src/main/java/org/matomo/java/tracking/servlet/CookieWrapper.java
index 4c29ae3d..a4debe13 100644
--- a/core/src/main/java/org/matomo/java/tracking/servlet/CookieWrapper.java
+++ b/core/src/main/java/org/matomo/java/tracking/servlet/CookieWrapper.java
@@ -2,14 +2,11 @@
import lombok.Value;
-/**
- * Wrapper for the cookie name and value.
- */
+/** Wrapper for the cookie name and value. */
@Value
public class CookieWrapper {
String name;
String value;
-
}
diff --git a/core/src/main/java/org/matomo/java/tracking/servlet/HttpServletRequestWrapper.java b/core/src/main/java/org/matomo/java/tracking/servlet/HttpServletRequestWrapper.java
index b72c087b..15a7dc2f 100644
--- a/core/src/main/java/org/matomo/java/tracking/servlet/HttpServletRequestWrapper.java
+++ b/core/src/main/java/org/matomo/java/tracking/servlet/HttpServletRequestWrapper.java
@@ -9,27 +9,20 @@
import lombok.NonNull;
import lombok.Value;
-/**
- * Wraps a HttpServletRequest to be compatible with both the Jakarta and the Java EE API.
- */
+/** Wraps a HttpServletRequest to be compatible with both the Jakarta and the Java EE API. */
@Builder
@Value
public class HttpServletRequestWrapper {
- @Nullable
- StringBuffer requestURL;
+ @Nullable StringBuffer requestURL;
- @Nullable
- String remoteAddr;
+ @Nullable String remoteAddr;
- @Nullable
- String remoteUser;
+ @Nullable String remoteUser;
- @Nullable
- Map Use #fromServletRequest(HttpServletRequestWrapper) to create a new builder with the headers from the
- * request or #addServletRequestHeaders(MatomoRequest.MatomoRequestBuilder, HttpServletRequestWrapper) to
- * add the headers to an existing builder.
+ * Use #fromServletRequest(HttpServletRequestWrapper) to create a new builder with the headers
+ * from the request or #addServletRequestHeaders(MatomoRequest.MatomoRequestBuilder,
+ * HttpServletRequestWrapper) to add the headers to an existing builder.
*/
public final class ServletMatomoRequest {
- /**
- * Please ensure these values are always lower case.
- */
+ /** Please ensure these values are always lower case. */
private static final Set Use #addServletRequestHeaders(MatomoRequest.MatomoRequestBuilder, HttpServletRequestWrapper) to
- * add the headers to an existing builder.
+ * Use #addServletRequestHeaders(MatomoRequest.MatomoRequestBuilder, HttpServletRequestWrapper)
+ * to add the headers to an existing builder.
*
* @param request the request to get the headers from (must not be null)
- *
* @return a new builder with the headers from the request (never null)
*/
@edu.umd.cs.findbugs.annotations.NonNull
- public static MatomoRequest.MatomoRequestBuilder fromServletRequest(@NonNull HttpServletRequestWrapper request) {
+ public static MatomoRequest.MatomoRequestBuilder fromServletRequest(
+ @NonNull HttpServletRequestWrapper request) {
return addServletRequestHeaders(MatomoRequest.request(), request);
}
/**
* Adds the headers from the request to an existing builder.
*
- * Use #fromServletRequest(HttpServletRequestWrapper) to create a new builder with the headers from
- * the request.
+ * Use #fromServletRequest(HttpServletRequestWrapper) to create a new builder with the headers
+ * from the request.
*
* @param builder the builder to add the headers to (must not be null)
* @param request the request to get the headers from (must not be null)
- *
* @return the builder with the headers added (never null)
*/
@edu.umd.cs.findbugs.annotations.NonNull
public static MatomoRequest.MatomoRequestBuilder addServletRequestHeaders(
- @NonNull MatomoRequest.MatomoRequestBuilder builder, @NonNull HttpServletRequestWrapper request
- ) {
+ @NonNull MatomoRequest.MatomoRequestBuilder builder,
+ @NonNull HttpServletRequestWrapper request) {
return builder
.actionUrl(request.getRequestURL() == null ? null : request.getRequestURL().toString())
.headers(collectHeaders(request))
@@ -83,15 +74,14 @@ public static MatomoRequest.MatomoRequestBuilder addServletRequestHeaders(
@edu.umd.cs.findbugs.annotations.NonNull
private static Map This class is intended for testing purposes only. It does not send anything to the Matomo server. Instead, it
- * stores the requests and queries in collections that can be accessed via {@link #getRequests()} and {@link
- * #getQueries()}.
+ * This class is intended for testing purposes only. It does not send anything to the Matomo
+ * server. Instead, it stores the requests and queries in collections that can be accessed via
+ * {@link #getRequests()} and {@link #getQueries()}.
*/
@RequiredArgsConstructor
@Getter
@@ -43,8 +43,7 @@ public void sendSingle(@NonNull MatomoRequest request) {
@Override
public void sendBulk(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
- ) {
+ @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken) {
for (MatomoRequest request : requests) {
createQueryAndAddRequest(request, overrideAuthToken);
}
@@ -53,18 +52,17 @@ public void sendBulk(
@NonNull
@Override
public CompletableFuture This implementation uses a thread pool to send requests asynchronously. The thread pool is configured using
- * {@link TrackerConfiguration#getThreadPoolSize()}. The thread pool uses daemon threads. This means that the JVM will
- * exit even if the thread pool is not shut down.
+ * This implementation uses a thread pool to send requests asynchronously. The thread pool is
+ * configured using {@link TrackerConfiguration#getThreadPoolSize()}. The thread pool uses daemon
+ * threads. This means that the JVM will exit even if the thread pool is not shut down.
*
- * If you use a newer Java version, please use the newer Java implementation from the Matomo Java Tracker for
- * Java 11.
+ * If you use a newer Java version, please use the newer Java implementation from the Matomo Java
+ * Tracker for Java 11.
*/
@Slf4j
@RequiredArgsConstructor
@@ -64,27 +65,30 @@ class Java8Sender implements Sender {
@Override
@NonNull
- public CompletableFuture
- * {@code
- * Required = true
- * Visior Id = random 16 character hex string
- * Random Value = random 20 character hex string
- * API version = 1
- * Response as Image = false
- * }
- *
- * Overwrite these values yourself as desired.
+ * action. This constructor also sets:
*
- * @param siteId the id of the website we're tracking a visit/action for
- * @param actionUrl the full URL for the current action
+ *
This class is intended for testing purposes only. It does not send anything to the Matomo server. Instead, it - * stores the requests and queries in collections that can be accessed via {@link #getRequests()}. + *
This class is intended for testing purposes only. It does not send anything to the Matomo
+ * server. Instead, it stores the requests and queries in collections that can be accessed via
+ * {@link #getRequests()}.
*/
@RequiredArgsConstructor
@Getter
@@ -38,16 +39,14 @@ public void sendSingle(@NonNull MatomoRequest request) {
@Override
public void sendBulk(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
- ) {
+ @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken) {
throw new UnsupportedOperationException();
}
@NonNull
@Override
public CompletableFuture This class is intended for testing purposes only. It does not send anything to the Matomo server. Instead, it
- * stores the requests and queries in collections that can be accessed via {@link #getRequests()}.
+ * This class is intended for testing purposes only. It does not send anything to the Matomo
+ * server. Instead, it stores the requests and queries in collections that can be accessed via
+ * {@link #getRequests()}.
*/
@RequiredArgsConstructor
@Getter
@@ -38,16 +39,14 @@ public void sendSingle(@NonNull MatomoRequest request) {
@Override
public void sendBulk(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken
- ) {
+ @NonNull Iterable extends MatomoRequest> requests, @Nullable String overrideAuthToken) {
throw new UnsupportedOperationException();
}
@NonNull
@Override
public CompletableFuture If you define your own {@link TrackerConfiguration} bean, please don't forget to set the
- * API endpoint.
+ * If you define your own {@link TrackerConfiguration} bean, please don't forget to set the API
+ * endpoint.
*
- * @param builder the {@link TrackerConfiguration.TrackerConfigurationBuilder} instance (never {@code null})
+ * @param builder the {@link TrackerConfiguration.TrackerConfigurationBuilder} instance (never
+ * {@code null})
* @return the {@link TrackerConfiguration} instance (never {@code null})
* @see TrackerConfiguration#builder()
* @see TrackerConfiguration.TrackerConfigurationBuilder#apiEndpoint(URI)
@@ -67,14 +67,13 @@ public TrackerConfiguration.TrackerConfigurationBuilder trackerConfigurationBuil
@ConditionalOnMissingBean
@NonNull
public TrackerConfiguration trackerConfiguration(
- TrackerConfiguration.TrackerConfigurationBuilder builder
- ) {
+ TrackerConfiguration.TrackerConfigurationBuilder builder) {
return builder.build();
}
/**
- * Configures the {@link TrackerConfiguration.TrackerConfigurationBuilder} with the properties from
- * {@link MatomoTrackerProperties}.
+ * Configures the {@link TrackerConfiguration.TrackerConfigurationBuilder} with the properties
+ * from {@link MatomoTrackerProperties}.
*
* @param properties the {@link MatomoTrackerProperties} instance (never {@code null})
* @return the {@link StandardTrackerConfigurationBuilderCustomizer} instance (never {@code null})
@@ -83,15 +82,14 @@ public TrackerConfiguration trackerConfiguration(
*/
@Bean
@NonNull
- public StandardTrackerConfigurationBuilderCustomizer standardTrackerConfigurationBuilderCustomizer(
- @NonNull MatomoTrackerProperties properties
- ) {
+ public StandardTrackerConfigurationBuilderCustomizer
+ standardTrackerConfigurationBuilderCustomizer(@NonNull MatomoTrackerProperties properties) {
return new StandardTrackerConfigurationBuilderCustomizer(properties);
}
/**
- * A {@link MatomoTracker} instance based on the current configuration. Only created if a bean of the same type is not
- * already configured.
+ * A {@link MatomoTracker} instance based on the current configuration. Only created if a bean of
+ * the same type is not already configured.
*
* @param trackerConfiguration the {@link TrackerConfiguration} instance (never {@code null})
* @return the {@link MatomoTracker} instance (never {@code null})
@@ -108,8 +106,8 @@ public MatomoTracker matomoTracker(@NonNull TrackerConfiguration trackerConfigur
/**
* A {@link FilterRegistrationBean} for the {@link MatomoTrackerFilter}.
*
- * Only created if a bean of the same type is not already configured. The filter is only registered if
- * {@code matomo.tracker.filter.enabled} is set to {@code true}.
+ * Only created if a bean of the same type is not already configured. The filter is only
+ * registered if {@code matomo.tracker.filter.enabled} is set to {@code true}.
*
* @param matomoTracker the {@link MatomoTracker} instance (never {@code null})
* @return the {@link FilterRegistrationBean} instance (never {@code null})
@@ -118,9 +116,7 @@ public MatomoTracker matomoTracker(@NonNull TrackerConfiguration trackerConfigur
@ConditionalOnProperty(value = "matomo.tracker.filter.enabled", havingValue = "true")
@NonNull
public FilterRegistrationBean These properties can be configured in the application.properties file. For example:
+ *
* A timeout value of zero is interpreted as an infinite timeout.
- * A `null` value is interpreted as undefined (system default if applicable). A timeout value of zero is interpreted as an infinite timeout. A `null` value is interpreted
+ * as undefined (system default if applicable).
*
- * Default: 10 seconds Default: 10 seconds
*/
private Duration connectTimeout = Duration.ofSeconds(5L);
/**
- * The socket timeout ({@code SO_TIMEOUT}), which is the timeout for waiting for data or, put differently, a maximum
- * period inactivity between two consecutive data packets.
+ * The socket timeout ({@code SO_TIMEOUT}), which is the timeout for waiting for data or, put
+ * differently, a maximum period inactivity between two consecutive data packets.
*
- * A timeout value of zero is interpreted as an infinite timeout.
- * A `null value is interpreted as undefined (system default if applicable). A timeout value of zero is interpreted as an infinite timeout. A `null value is interpreted
+ * as undefined (system default if applicable).
*
- * Default: 30 seconds Default: 30 seconds
*/
private Duration socketTimeout = Duration.ofSeconds(5L);
/**
- * The hostname or IP address of an optional HTTP proxy. {@code proxyPort} must be configured as well
+ * The hostname or IP address of an optional HTTP proxy. {@code proxyPort} must be configured as
+ * well
*/
private String proxyHost;
- /**
- * The port of an HTTP proxy. {@code proxyHost} must be configured as well.
- */
+ /** The port of an HTTP proxy. {@code proxyHost} must be configured as well. */
private Integer proxyPort;
/**
- * If the HTTP proxy requires a username for basic authentication, it can be configured here. Proxy host, port and
- * password must also be set.
+ * If the HTTP proxy requires a username for basic authentication, it can be configured here.
+ * Proxy host, port and password must also be set.
*/
private String proxyUsername;
/**
- * The corresponding password for the basic auth proxy user. The proxy host, port and username must be set as well.
+ * The corresponding password for the basic auth proxy user. The proxy host, port and username
+ * must be set as well.
*/
private String proxyPassword;
- /**
- * A custom user agent to be set. Defaults to "MatomoJavaClient"
- */
+ /** A custom user agent to be set. Defaults to "MatomoJavaClient" */
private String userAgent = "MatomoJavaClient";
/**
@@ -121,7 +114,7 @@ public class MatomoTrackerProperties {
* Do not use in production environments. Defaults to false.
*
* Attention: This slows down performance
-
+ *
* @see #disableSslHostVerification
*/
private Boolean disableSslCertValidation;
@@ -140,9 +133,7 @@ public class MatomoTrackerProperties {
* The thread pool size for the async sender. Defaults to 2.
*
* Attention: If you use this library in a web application, make sure that this thread pool
- * does not exceed the thread pool of the web application. Otherwise, you might run into
- * problems.
+ * does not exceed the thread pool of the web application. Otherwise, you might run into problems.
*/
private Integer threadPoolSize = 2;
-
}
diff --git a/spring/src/main/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizer.java b/spring/src/main/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizer.java
index e9f1acd2..afd00d33 100644
--- a/spring/src/main/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizer.java
+++ b/spring/src/main/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizer.java
@@ -8,12 +8,13 @@
package org.matomo.java.tracking.spring;
import java.net.URI;
+import org.jspecify.annotations.NonNull;
import org.matomo.java.tracking.TrackerConfiguration;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.core.Ordered;
-import org.springframework.lang.NonNull;
-class StandardTrackerConfigurationBuilderCustomizer implements TrackerConfigurationBuilderCustomizer, Ordered {
+class StandardTrackerConfigurationBuilderCustomizer
+ implements TrackerConfigurationBuilderCustomizer, Ordered {
private final MatomoTrackerProperties properties;
@@ -27,8 +28,8 @@ public int getOrder() {
}
@Override
- public void customize(@NonNull TrackerConfiguration.TrackerConfigurationBuilder builder) {
- PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
+ public void customize(TrackerConfiguration.@NonNull TrackerConfigurationBuilder builder) {
+ PropertyMapper map = PropertyMapper.get();
map.from(properties::getApiEndpoint).as(URI::create).to(builder::apiEndpoint);
map.from(properties::getDefaultSiteId).to(builder::defaultSiteId);
map.from(properties::getDefaultAuthToken).to(builder::defaultAuthToken);
@@ -45,6 +46,4 @@ public void customize(@NonNull TrackerConfiguration.TrackerConfigurationBuilder
map.from(properties::getDisableSslHostVerification).to(builder::disableSslHostVerification);
map.from(properties::getThreadPoolSize).to(builder::threadPoolSize);
}
-
-
-}
\ No newline at end of file
+}
diff --git a/spring/src/main/java/org/matomo/java/tracking/spring/TrackerConfigurationBuilderCustomizer.java b/spring/src/main/java/org/matomo/java/tracking/spring/TrackerConfigurationBuilderCustomizer.java
index e147a64f..621cc4b1 100644
--- a/spring/src/main/java/org/matomo/java/tracking/spring/TrackerConfigurationBuilderCustomizer.java
+++ b/spring/src/main/java/org/matomo/java/tracking/spring/TrackerConfigurationBuilderCustomizer.java
@@ -7,13 +7,15 @@
package org.matomo.java.tracking.spring;
+import org.jspecify.annotations.NonNull;
import org.matomo.java.tracking.TrackerConfiguration;
-import org.springframework.lang.NonNull;
/**
- * Allows to customize the {@link TrackerConfiguration.TrackerConfigurationBuilder} with additional properties.
+ * Allows to customize the {@link TrackerConfiguration.TrackerConfigurationBuilder} with additional
+ * properties.
*
- * Implementations of this interface are detected automatically by the {@link MatomoTrackerAutoConfiguration}.
+ * Implementations of this interface are detected automatically by the {@link
+ * MatomoTrackerAutoConfiguration}.
*
* @see MatomoTrackerAutoConfiguration
* @see TrackerConfiguration
@@ -25,10 +27,10 @@ public interface TrackerConfigurationBuilderCustomizer {
/**
* Customize the {@link TrackerConfiguration.TrackerConfigurationBuilder}.
*
- * @param builder the {@link TrackerConfiguration.TrackerConfigurationBuilder} instance (never {@code null})
+ * @param builder the {@link TrackerConfiguration.TrackerConfigurationBuilder} instance (never
+ * {@code null})
* @see TrackerConfiguration#builder()
* @see MatomoTrackerProperties
*/
- void customize(@NonNull TrackerConfiguration.TrackerConfigurationBuilder builder);
-
+ void customize(TrackerConfiguration.@NonNull TrackerConfigurationBuilder builder);
}
diff --git a/spring/src/main/java/org/matomo/java/tracking/spring/package-info.java b/spring/src/main/java/org/matomo/java/tracking/spring/package-info.java
index 784c9d72..b7db4c90 100644
--- a/spring/src/main/java/org/matomo/java/tracking/spring/package-info.java
+++ b/spring/src/main/java/org/matomo/java/tracking/spring/package-info.java
@@ -1,10 +1,10 @@
/**
* Provides Spring specific classes to integrate Matomo tracking into Spring applications.
*
- * See {@link org.matomo.java.tracking.spring.MatomoTrackerProperties} for the available configuration properties.
+ * See {@link org.matomo.java.tracking.spring.MatomoTrackerProperties} for the available
+ * configuration properties.
*
- * See {@link org.matomo.java.tracking.spring.MatomoTrackerAutoConfiguration} for the available configuration
- * options.
+ * See {@link org.matomo.java.tracking.spring.MatomoTrackerAutoConfiguration} for the available
+ * configuration options.
*/
-
-package org.matomo.java.tracking.spring;
\ No newline at end of file
+package org.matomo.java.tracking.spring;
diff --git a/spring/src/test/java/org/matomo/java/tracking/spring/MatomoTrackerAutoConfigurationIT.java b/spring/src/test/java/org/matomo/java/tracking/spring/MatomoTrackerAutoConfigurationIT.java
index c008dbc8..d185ea0c 100644
--- a/spring/src/test/java/org/matomo/java/tracking/spring/MatomoTrackerAutoConfigurationIT.java
+++ b/spring/src/test/java/org/matomo/java/tracking/spring/MatomoTrackerAutoConfigurationIT.java
@@ -15,14 +15,17 @@
class MatomoTrackerAutoConfigurationIT {
private final ApplicationContextRunner contextRunner =
- new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(MatomoTrackerAutoConfiguration.class));
-
+ new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(MatomoTrackerAutoConfiguration.class));
@Test
void matomoTrackerRegistration() {
- contextRunner.withPropertyValues("matomo.tracker.api-endpoint:https://test.com/matomo.php").run(context -> {
- assertThat(context).hasSingleBean(MatomoTracker.class).hasBean("matomoTracker");
- });
+ contextRunner
+ .withPropertyValues("matomo.tracker.api-endpoint:https://test.com/matomo.php")
+ .run(
+ context -> {
+ assertThat(context).hasSingleBean(MatomoTracker.class).hasBean("matomoTracker");
+ });
}
@Test
@@ -30,10 +33,13 @@ void additionalTrackerConfigurationBuilderCustomization() {
this.contextRunner
.withPropertyValues("matomo.tracker.api-endpoint:https://test.com/matomo.php")
.withUserConfiguration(TrackerConfigurationBuilderCustomizerConfig.class)
- .run(context -> {
- TrackerConfiguration trackerConfiguration = context.getBean(TrackerConfiguration.class);
- assertThat(trackerConfiguration.getConnectTimeout()).isEqualTo(Duration.ofMinutes(1L));
- });
+ .run(
+ context -> {
+ TrackerConfiguration trackerConfiguration =
+ context.getBean(TrackerConfiguration.class);
+ assertThat(trackerConfiguration.getConnectTimeout())
+ .isEqualTo(Duration.ofMinutes(1L));
+ });
}
@Test
@@ -41,10 +47,12 @@ void customTrackerConfigurationBuilder() {
this.contextRunner
.withPropertyValues("matomo.tracker.api-endpoint:https://test.com/matomo.php")
.withUserConfiguration(TrackerConfigurationBuilderConfig.class)
- .run(context -> {
- TrackerConfiguration trackerConfiguration = context.getBean(TrackerConfiguration.class);
- assertThat(trackerConfiguration.isDisableSslHostVerification()).isTrue();
- });
+ .run(
+ context -> {
+ TrackerConfiguration trackerConfiguration =
+ context.getBean(TrackerConfiguration.class);
+ assertThat(trackerConfiguration.isDisableSslHostVerification()).isTrue();
+ });
}
@Configuration
@@ -54,7 +62,6 @@ static class TrackerConfigurationBuilderCustomizerConfig {
TrackerConfigurationBuilderCustomizer customConnectTimeout() {
return configurationBuilder -> configurationBuilder.connectTimeout(Duration.ofMinutes(1L));
}
-
}
@Configuration
@@ -62,9 +69,9 @@ static class TrackerConfigurationBuilderConfig {
@Bean
TrackerConfiguration.TrackerConfigurationBuilder customTrackerConfigurationBuilder() {
- return TrackerConfiguration.builder().apiEndpoint(URI.create("https://test.com/matomo.php")).disableSslHostVerification(true);
+ return TrackerConfiguration.builder()
+ .apiEndpoint(URI.create("https://test.com/matomo.php"))
+ .disableSslHostVerification(true);
}
-
}
-
-}
\ No newline at end of file
+}
diff --git a/spring/src/test/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizerIT.java b/spring/src/test/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizerIT.java
index b62eafec..22052c8a 100644
--- a/spring/src/test/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizerIT.java
+++ b/spring/src/test/java/org/matomo/java/tracking/spring/StandardTrackerConfigurationBuilderCustomizerIT.java
@@ -44,12 +44,11 @@ void createsStandardTrackerConfigurationBuilderCustomizer() {
assertThat(configuration.getProxyPort()).isEqualTo(8080);
assertThat(configuration.getProxyUsername()).isEqualTo("user");
assertThat(configuration.getProxyPassword()).isEqualTo("password");
- assertThat(configuration.getUserAgent()).isEqualTo(
- "Mozilla/5.0 (compatible; AcmeInc/1.0; +https://example.com/bot.html)");
+ assertThat(configuration.getUserAgent())
+ .isEqualTo("Mozilla/5.0 (compatible; AcmeInc/1.0; +https://example.com/bot.html)");
assertThat(configuration.isLogFailedTracking()).isTrue();
assertThat(configuration.isDisableSslCertValidation()).isTrue();
assertThat(configuration.isDisableSslHostVerification()).isTrue();
assertThat(configuration.getThreadPoolSize()).isEqualTo(10);
}
-
-}
\ No newline at end of file
+}
diff --git a/test/pom.xml b/test/pom.xml
index 7a2eb183..d02fa589 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -1,10 +1,11 @@
+
Example: {@code {"brands":[{"brand":"Chromium","version":"110"}],"mobile":false}}
+ */
+ @TrackingParameter(name = "uadata")
+ private String clientHints;
+
/**
* An override value for the Accept-Language HTTP header field. This value is used to detect the
* visitor's country if GeoIP is not enabled.
@@ -407,6 +417,40 @@ public class MatomoRequest {
@TrackingParameter(name = "_ects")
private Instant ecommerceLastOrderTimestamp;
+ /**
+ * The SKU of the product being viewed. Used for ecommerce product page tracking.
+ *
+ * Requires {@code idgoal=0} and {@code _pks} to be set.
+ */
+ @TrackingParameter(name = "_pks")
+ private String ecommerceProductSku;
+
+ /**
+ * The name of the product being viewed. Used for ecommerce product page tracking.
+ *
+ * Requires {@code idgoal=0} and {@code _pks} to be set.
+ */
+ @TrackingParameter(name = "_pkn")
+ private String ecommerceProductName;
+
+ /**
+ * The category of the product being viewed. Used for ecommerce product page tracking.
+ *
+ * Can be a string or a JSON-encoded array of up to five category names.
+ *
+ * Requires {@code idgoal=0} and {@code _pks} to be set.
+ */
+ @TrackingParameter(name = "_pkc")
+ private String ecommerceProductCategory;
+
+ /**
+ * The price of the product being viewed. Used for ecommerce product page tracking.
+ *
+ * Requires {@code idgoal=0} and {@code _pks} to be set.
+ */
+ @TrackingParameter(name = "_pkp", min = 0)
+ private Double ecommerceProductPrice;
+
/**
* 32 character authorization key used to authenticate the API request. We recommend to create a
* user specifically for accessing the Tracking API, and give the user only write permission on
@@ -486,6 +530,34 @@ public class MatomoRequest {
@TrackingParameter(name = "bots")
private Boolean trackBotRequests;
+ /**
+ * When {@code bots=1} is set, this specifies the recording mode for bot requests.
+ *
+ * Set to {@code 1} to record bot requests without triggering any goals, events or actions.
+ */
+ @TrackingParameter(name = "recMode")
+ private Integer botRecordingMode;
+
+ /**
+ * The HTTP status code of the tracked request. Used with bot tracking.
+ *
+ * When tracking a bot visit, this can be set to the HTTP status code of the bot's request.
+ */
+ @TrackingParameter(name = "http_status")
+ private Integer httpStatusCode;
+
+ /** The bandwidth used for the tracked request in bytes. Used with bot tracking. */
+ @TrackingParameter(name = "bw_bytes", min = 0)
+ private Long bandwidthBytes;
+
+ /**
+ * Defines the source of the tracking request (e.g., {@code "backend"} or {@code "mobile-app"}).
+ *
+ * Used to classify where the tracking hit originated.
+ */
+ @TrackingParameter(name = "source")
+ private String sourceLabel;
+
/**
* Meant to hold a random value that is generated before each request. Using it helps avoid the
* tracking request being cached by the browser or a proxy.
@@ -501,6 +573,99 @@ public class MatomoRequest {
@TrackingParameter(name = "debug")
private Boolean debug;
+ /**
+ * A unique ID used to identify the media. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_id")
+ private String mediaId;
+
+ /**
+ * The title of the media resource. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_ti")
+ private String mediaTitle;
+
+ /**
+ * The URL of the media resource. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_re")
+ private String mediaResource;
+
+ /**
+ * The type of media, e.g. {@code "video"} or {@code "audio"}. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_mt")
+ private String mediaType;
+
+ /**
+ * The name of the media player used to play the media, e.g. {@code "html5"}. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_pn")
+ private String mediaPlayerName;
+
+ /**
+ * The number of seconds the visitor has spent playing/watching the media resource so far. Part of
+ * the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_st", min = 0)
+ private Integer mediaTimeSpent;
+
+ /**
+ * The total duration / length of the media resource in seconds. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_le", min = 0)
+ private Integer mediaLength;
+
+ /**
+ * The current progress of the media in percent (0–100). Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_ps", min = 0, max = 100)
+ private Integer mediaProgressPercent;
+
+ /**
+ * How many seconds it took before the media started playing. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_ttp", min = 0)
+ private Integer mediaTimeToPlay;
+
+ /**
+ * The width of the media player in pixels. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_w", min = 0)
+ private Integer mediaWidth;
+
+ /**
+ * The height of the media player in pixels. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_h", min = 0)
+ private Integer mediaHeight;
+
+ /**
+ * Whether the media is currently displayed in fullscreen. Part of the Media Analytics plugin.
+ */
+ @TrackingParameter(name = "ma_fs")
+ private Boolean mediaFullscreen;
+
+ /**
+ * A JSON-encoded array of which positions in the media were viewed by the visitor. Part of the Media Analytics plugin.
+ *
+ * Example: {@code [[0,15],[30,44]]} means the visitor watched segments 0–15s and 30–44s.
+ */
+ @TrackingParameter(name = "ma_se")
+ private String mediaSegmentsViewed;
+
/**
* Contains an error message describing the error that occurred during the last tracking request.
*
diff --git a/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java b/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
index 6201562c..0d5a18b5 100644
--- a/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
+++ b/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
@@ -618,4 +618,205 @@ void allowsZeroForEcommerceValues() {
+ "send_image=0&"
+ "rand=random-value");
}
+
+ @Test
+ void includesClientHints() {
+ matomoRequestBuilder.clientHints(
+ "{\"brands\":[{\"brand\":\"Chromium\",\"version\":\"110\"}],\"mobile\":false}");
+
+ whenCreatesQuery();
+
+ assertThat(query)
+ .contains(
+ "uadata=%7B%22brands%22%3A%5B%7B%22brand%22%3A%22Chromium%22%2C%22version%22%3A%22110%22%7D%5D%2C%22mobile%22%3Afalse%7D");
+ }
+
+ @Test
+ void includesEcommerceProductView() {
+ matomoRequestBuilder
+ .ecommerceProductSku("SKU-123")
+ .ecommerceProductName("Blue Widget")
+ .ecommerceProductCategory("Widgets")
+ .ecommerceProductPrice(9.99);
+
+ whenCreatesQuery();
+
+ assertThat(query)
+ .contains("_pks=SKU-123")
+ .contains("_pkn=Blue+Widget")
+ .contains("_pkc=Widgets")
+ .contains("_pkp=9.99");
+ }
+
+ @Test
+ void allowsZeroForEcommerceProductPrice() {
+ matomoRequestBuilder.ecommerceProductSku("SKU-FREE").ecommerceProductPrice(0.0);
+
+ whenCreatesQuery();
+
+ assertThat(query).contains("_pks=SKU-FREE").contains("_pkp=0.0");
+ }
+
+ @Test
+ void failsIfEcommerceProductPriceIsNegative() {
+ matomoRequestBuilder.ecommerceProductPrice(-1.0);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for _pkp. Must be greater or equal than 0");
+ }
+
+ @Test
+ void includesBotTrackingParameters() {
+ matomoRequestBuilder
+ .trackBotRequests(true)
+ .botRecordingMode(1)
+ .httpStatusCode(200)
+ .bandwidthBytes(1024L)
+ .sourceLabel("backend");
+
+ whenCreatesQuery();
+
+ assertThat(query)
+ .contains("bots=1")
+ .contains("recMode=1")
+ .contains("http_status=200")
+ .contains("bw_bytes=1024")
+ .contains("source=backend");
+ }
+
+ @Test
+ void allowsZeroForBandwidthBytes() {
+ matomoRequestBuilder.bandwidthBytes(0L);
+
+ whenCreatesQuery();
+
+ assertThat(query).contains("bw_bytes=0");
+ }
+
+ @Test
+ void failsIfBandwidthBytesIsNegative() {
+ matomoRequestBuilder.bandwidthBytes(-1L);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for bw_bytes. Must be greater or equal than 0");
+ }
+
+ @Test
+ void includesMediaAnalyticsParameters() {
+ matomoRequestBuilder
+ .mediaId("media-abc123")
+ .mediaTitle("My Video")
+ .mediaResource("https://example.com/video.mp4")
+ .mediaType("video")
+ .mediaPlayerName("html5")
+ .mediaTimeSpent(42)
+ .mediaLength(120)
+ .mediaProgressPercent(35)
+ .mediaTimeToPlay(3)
+ .mediaWidth(1280)
+ .mediaHeight(720)
+ .mediaFullscreen(false)
+ .mediaSegmentsViewed("[[0,42]]");
+
+ whenCreatesQuery();
+
+ assertThat(query)
+ .contains("ma_id=media-abc123")
+ .contains("ma_ti=My+Video")
+ .contains("ma_re=https%3A%2F%2Fexample.com%2Fvideo.mp4")
+ .contains("ma_mt=video")
+ .contains("ma_pn=html5")
+ .contains("ma_st=42")
+ .contains("ma_le=120")
+ .contains("ma_ps=35")
+ .contains("ma_ttp=3")
+ .contains("ma_w=1280")
+ .contains("ma_h=720")
+ .contains("ma_fs=0")
+ .contains("ma_se=%5B%5B0%2C42%5D%5D");
+ }
+
+ @Test
+ void allowsZeroForMediaTimeValues() {
+ matomoRequestBuilder.mediaTimeSpent(0).mediaLength(0).mediaTimeToPlay(0);
+
+ whenCreatesQuery();
+
+ assertThat(query).contains("ma_st=0").contains("ma_le=0").contains("ma_ttp=0");
+ }
+
+ @Test
+ void failsIfMediaTimeSpentIsNegative() {
+ matomoRequestBuilder.mediaTimeSpent(-1);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_st. Must be greater or equal than 0");
+ }
+
+ @Test
+ void failsIfMediaLengthIsNegative() {
+ matomoRequestBuilder.mediaLength(-1);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_le. Must be greater or equal than 0");
+ }
+
+ @Test
+ void failsIfMediaProgressPercentIsNegative() {
+ matomoRequestBuilder.mediaProgressPercent(-1);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_ps. Must be greater or equal than 0");
+ }
+
+ @Test
+ void failsIfMediaProgressPercentExceeds100() {
+ matomoRequestBuilder.mediaProgressPercent(101);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_ps. Must be less or equal than 100");
+ }
+
+ @Test
+ void allowsZeroAndMaxForMediaProgressPercent() {
+ matomoRequestBuilder.mediaProgressPercent(0);
+ whenCreatesQuery();
+ assertThat(query).contains("ma_ps=0");
+
+ matomoRequestBuilder.mediaProgressPercent(100);
+ whenCreatesQuery();
+ assertThat(query).contains("ma_ps=100");
+ }
+
+ @Test
+ void failsIfMediaWidthIsNegative() {
+ matomoRequestBuilder.mediaWidth(-1);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_w. Must be greater or equal than 0");
+ }
+
+ @Test
+ void failsIfMediaHeightIsNegative() {
+ matomoRequestBuilder.mediaHeight(-1);
+
+ assertThatThrownBy(this::whenCreatesQuery)
+ .isInstanceOf(MatomoException.class)
+ .hasMessage("Could not append parameter")
+ .hasRootCauseMessage("Invalid value for ma_h. Must be greater or equal than 0");
+ }
}
From 0a969da2025e81d185313df3fc26fe93c8192098 Mon Sep 17 00:00:00 2001
From: Daniel Heid
* matomo.tracker.api-endpoint=https://your-matomo-domain.example/matomo.php
* matomo.tracker.default-site-id=1
@@ -44,70 +45,62 @@
public class MatomoTrackerProperties {
/**
- * The Matomo Tracking HTTP API endpoint, for example https://your-matomo-domain.example/matomo.php
+ * The Matomo Tracking HTTP API endpoint. Example: https://your-matomo-domain.example/matomo.php
*/
private String apiEndpoint;
- /**
- * The default ID of the website that will be used if not specified explicitly.
- */
+ /** The default ID of the website that will be used if not specified explicitly. */
private Integer defaultSiteId;
- /**
- * The authorization token (parameter token_auth) to use if not specified explicitly.
- */
+ /** The authorization token (parameter token_auth) to use if not specified explicitly. */
private String defaultAuthToken;
- /**
- * Allows to stop the tracker to send requests to the Matomo endpoint.
- */
+ /** Allows to stop the tracker to send requests to the Matomo endpoint. */
private Boolean enabled = true;
/**
* The timeout until a connection is established.
*
- *
{@code Required = true Visior Id = random 16 character hex string Random Value = random 20 - * character hex string API version = 1 Response as Image = false } - * - *
Overwrite these values yourself as desired. - * - * @param siteId the id of the website we're tracking a visit/action for - * @param actionUrl the full URL for the current action - * @deprecated Please use {@link MatomoRequest#request()} - */ - @Deprecated - public MatomoRequest(int siteId, String actionUrl) { - this.siteId = siteId; - this.actionUrl = actionUrl; - required = true; - visitorId = VisitorId.random(); - randomValue = RandomValue.random(); - apiVersion = "1"; - responseAsImage = false; - } - - /** - * Gets the list of objects currently stored at the specified custom tracking parameter. An empty - * list will be returned if there are no objects set at that key. - * - * @param key the key of the parameter whose list of objects to get. Cannot be null - * @return the parameter at the specified key, null if nothing at this key - */ - @Nullable - public Object getCustomTrackingParameter(@NonNull String key) { - if (additionalParameters == null || additionalParameters.isEmpty()) { - return null; - } - return additionalParameters.get(key); - } - - /** - * Set a custom tracking parameter whose toString() value will be sent to the Matomo server. These - * parameters are stored separately from named Matomo parameters, meaning it is not possible to - * overwrite or clear named Matomo parameters with this method. A custom parameter that has the - * same name as a named Matomo parameter will be sent in addition to that named parameter. - * - * @param key the parameter's key. Cannot be null - * @param value the parameter's value. Removes the parameter if null - * @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead. - */ - @Deprecated - public void setCustomTrackingParameter(@NonNull String key, @Nullable Object value) { - - if (value == null) { - if (additionalParameters != null) { - additionalParameters.remove(key); - } - } else { - if (additionalParameters == null) { - additionalParameters = new LinkedHashMap<>(); - } - additionalParameters.put(key, value); - } - } - - /** - * Add a custom tracking parameter to the specified key. If there is already a parameter at this - * key, the new value replaces the old value. - * - * @param key the parameter's key. Cannot be null - * @param value the parameter's value. May be null - * @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead. - */ - @Deprecated - public void addCustomTrackingParameter(@NonNull String key, @Nullable Object value) { - if (additionalParameters == null) { - additionalParameters = new LinkedHashMap<>(); - } - additionalParameters.put(key, value); - } - - /** - * Removes all custom tracking parameters. - * - * @deprecated Please use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} - * instead so that you can manage the map yourself. - */ - @Deprecated - public void clearCustomTrackingParameter() { - additionalParameters.clear(); - } - - /** - * Sets idgoal=0 in the request to track an ecommerce interaction: cart update or an - * ecommerce order. - * - * @deprecated Please use {@link MatomoRequest#setGoalId(Integer)} instead - */ - @Deprecated - public void enableEcommerce() { - setGoalId(0); - } - - /** - * Get the {@link EcommerceItem} at the specified index. - * - * @param index the index of the {@link EcommerceItem} to return - * @return the {@link EcommerceItem} at the specified index - * @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)} - * instead - */ - @Nullable - @Deprecated - public EcommerceItem getEcommerceItem(int index) { - if (ecommerceItems == null || ecommerceItems.isEmpty()) { - return null; - } - return ecommerceItems.get(index); - } - - /** - * Add an {@link EcommerceItem} to this order. Ecommerce must be enabled, and EcommerceId and - * EcommerceRevenue must first be set. - * - * @param item the {@link EcommerceItem} to add. Cannot be null - * @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)} - * instead - */ - @Deprecated - public void addEcommerceItem(@NonNull EcommerceItem item) { - if (ecommerceItems == null) { - ecommerceItems = new EcommerceItems(); - } - ecommerceItems.add(item); - } - - /** - * Clears all {@link EcommerceItem} from this order. - * - * @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)} - * instead - */ - @Deprecated - public void clearEcommerceItems() { - ecommerceItems.clear(); - } - - /** - * Get the page custom variable at the specified key. - * - * @param key the key of the variable to get - * @return the variable at the specified key, null if key is not present - * @deprecated Use the {@link #getPageCustomVariables()} method instead. - */ - @Nullable - @Deprecated - public String getPageCustomVariable(String key) { - if (pageCustomVariables == null) { - return null; - } - return pageCustomVariables.get(key); - } - - /** - * Get the page custom variable at the specified index. - * - * @param index the index of the variable to get. Must be greater than 0 - * @return the variable at the specified key, null if nothing at this index - * @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead - */ - @Deprecated - @Nullable - public CustomVariable getPageCustomVariable(int index) { - return getCustomVariable(pageCustomVariables, index); - } - - @Nullable - @Deprecated - private static CustomVariable getCustomVariable(CustomVariables customVariables, int index) { - if (customVariables == null) { - return null; - } - return customVariables.get(index); - } - - /** - * Set a page custom variable with the specified key and value at the first available index. All - * page custom variables with this key will be overwritten or deleted - * - * @param key the key of the variable to set - * @param value the value of the variable to set at the specified key. A null value will remove - * this custom variable - * @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead - */ - @Deprecated - public void setPageCustomVariable(@NonNull String key, @Nullable String value) { - if (value == null) { - if (pageCustomVariables == null) { - return; - } - pageCustomVariables.remove(key); - } else { - CustomVariable variable = new CustomVariable(key, value); - if (pageCustomVariables == null) { - pageCustomVariables = new CustomVariables(); - } - pageCustomVariables.add(variable); - } - } - - /** - * Set a page custom variable at the specified index. - * - * @param customVariable the CustomVariable to set. A null value will remove the CustomVariable at - * the specified index - * @param index the index of he CustomVariable to set - * @deprecated Use {@link #getPageCustomVariables()} instead - */ - @Deprecated - public void setPageCustomVariable(@Nullable CustomVariable customVariable, int index) { - if (pageCustomVariables == null) { - if (customVariable == null) { - return; - } - pageCustomVariables = new CustomVariables(); - } - setCustomVariable(pageCustomVariables, customVariable, index); - } - - @Deprecated - private static void setCustomVariable( - CustomVariables customVariables, @Nullable CustomVariable customVariable, int index) { - if (customVariable == null) { - customVariables.remove(index); - } else { - customVariables.add(customVariable, index); - } - } - - /** - * Get the datetime of the request. - * - * @return the datetime of the request - * @deprecated Use {@link #getRequestTimestamp()} instead - */ - @Deprecated - @Nullable - public MatomoDate getRequestDatetime() { - return requestTimestamp == null ? null : new MatomoDate(requestTimestamp.toEpochMilli()); - } - - /** - * Set the datetime of the request (normally the current time is used). This can be used to record - * visits and page views in the past. The datetime must be sent in UTC timezone. Note: if you - * record data in the past, you will need to force - * Matomo to re-process reports for the past dates. If you set the Request - * Datetime to a datetime older than four hours then Auth Token must be set. If you - * set Request Datetime with a datetime in the last four hours then you don't need to - * pass Auth Token. - * - * @param matomoDate the datetime of the request to set. A null value will remove this parameter - * @deprecated Use {@link #setRequestTimestamp(Instant)} instead - */ - @Deprecated - public void setRequestDatetime(MatomoDate matomoDate) { - if (matomoDate == null) { - requestTimestamp = null; - } else { - setRequestTimestamp(matomoDate.getZonedDateTime().toInstant()); - } - } - - /** - * Get the visit custom variable at the specified key. - * - * @param key the key of the variable to get - * @return the variable at the specified key, null if key is not present - * @deprecated Use the {@link #getVisitCustomVariables()} method instead. - */ - @Nullable - @Deprecated - public String getUserCustomVariable(String key) { - if (visitCustomVariables == null) { - return null; - } - return visitCustomVariables.get(key); - } - - /** - * Get the visit custom variable at the specified index. - * - * @param index the index of the variable to get - * @return the variable at the specified index, null if nothing at this index - * @deprecated Use {@link #getVisitCustomVariables()} instead - */ - @Nullable - @Deprecated - public CustomVariable getVisitCustomVariable(int index) { - return getCustomVariable(visitCustomVariables, index); - } - - /** - * Set a visit custom variable with the specified key and value at the first available index. All - * visit custom variables with this key will be overwritten or deleted - * - * @param key the key of the variable to set - * @param value the value of the variable to set at the specified key. A null value will remove - * this parameter - * @deprecated Use {@link #setVisitCustomVariables(CustomVariables)} instead - */ - @Deprecated - public void setUserCustomVariable(@NonNull String key, @Nullable String value) { - if (value == null) { - if (visitCustomVariables == null) { - return; - } - visitCustomVariables.remove(key); - } else { - CustomVariable variable = new CustomVariable(key, value); - if (visitCustomVariables == null) { - visitCustomVariables = new CustomVariables(); - } - visitCustomVariables.add(variable); - } - } - - /** - * Set a user custom variable at the specified key. - * - * @param customVariable the CustomVariable to set. A null value will remove the custom variable - * at the specified index - * @param index the index to set the customVariable at. - * @deprecated Use {@link #setVisitCustomVariables(CustomVariables)} instead - */ - @Deprecated - public void setVisitCustomVariable(@Nullable CustomVariable customVariable, int index) { - if (visitCustomVariables == null) { - if (customVariable == null) { - return; - } - visitCustomVariables = new CustomVariables(); - } - setCustomVariable(visitCustomVariables, customVariable, index); - } - - /** - * Sets a custom parameter to append to the Matomo tracking parameters. - * - *
Attention: If a parameter with the same name already exists, it will be appended twice! - * - * @param parameterName The name of the query parameter to append. Must not be null or empty. - * @param value The value of the query parameter to append. To remove the parameter, pass null. - * @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} - * instead - */ - @Deprecated - public void setParameter(@NonNull String parameterName, Object value) { - if (parameterName.trim().isEmpty()) { - throw new IllegalArgumentException("Parameter name must not be empty"); - } - if (additionalParameters == null) { - if (value == null) { - return; - } - additionalParameters = new LinkedHashMap<>(); - } - if (value == null) { - additionalParameters.remove(parameterName); - } else { - additionalParameters.put(parameterName, value); - } - } - - /** - * Creates a new {@link MatomoRequestBuilder} instance. Only here for backwards compatibility. - * - * @deprecated Use {@link MatomoRequest#request()} instead. - */ - @Deprecated - public static org.matomo.java.tracking.MatomoRequestBuilder builder() { - return new org.matomo.java.tracking.MatomoRequestBuilder(); - } - - /** - * Parses the given device resolution string and sets the {@link #deviceResolution} field. - * - * @param deviceResolution the device resolution string to parse. Format: "WIDTHxHEIGHT" - * @deprecated Use {@link #setDeviceResolution(DeviceResolution)} instead. - */ - @Tolerate - @Deprecated - public void setDeviceResolution(@Nullable String deviceResolution) { - if (deviceResolution == null || deviceResolution.trim().isEmpty()) { - this.deviceResolution = null; - } else { - this.deviceResolution = DeviceResolution.fromString(deviceResolution); - } - } } diff --git a/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java b/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java deleted file mode 100644 index 963e6916..00000000 --- a/core/src/main/java/org/matomo/java/tracking/MatomoRequestBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.matomo.java.tracking; - -import edu.umd.cs.findbugs.annotations.Nullable; -import java.util.Map; -import org.matomo.java.tracking.parameters.AcceptLanguage; - -/** - * The former MatomoRequestBuilder class has been moved to MatomoRequest.MatomoRequestBuilder. This - * class is only here for backwards compatibility. - * - * @deprecated Use {@link MatomoRequest.MatomoRequestBuilder} instead. - */ -@Deprecated -public class MatomoRequestBuilder extends MatomoRequest.MatomoRequestBuilder { - - /** - * Sets the tracking parameter for the accept languages of a user. Only here for backwards - * compatibility. - * - * @param headerAcceptLanguage The accept language header of a user. Must be in the format - * specified in RFC 2616. - * @return This builder - * @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#headerAcceptLanguage(AcceptLanguage)} - * in combination with {@link AcceptLanguage#fromHeader(String)} instead. - */ - @Deprecated - public MatomoRequestBuilder headerAcceptLanguage(@Nullable String headerAcceptLanguage) { - headerAcceptLanguage(AcceptLanguage.fromHeader(headerAcceptLanguage)); - return this; - } - - /** - * Sets the custom tracking parameters to the given parameters. - * - *
This converts the given map to a map of collections. Only included for backwards
- * compatibility.
- *
- * @param parameters The custom tracking parameters to set
- * @return This builder
- * @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)}}
- */
- @Deprecated
- public MatomoRequestBuilder customTrackingParameters(@Nullable Map Use this method if you want to send a single request. If you want to send multiple requests
- * at once, use {@link #sendBulkRequestAsync(Collection, Consumer)} instead. If you want to send
- * multiple requests synchronously, use {@link #sendRequest(MatomoRequest)} or {@link
- * #sendBulkRequest(Iterable)} instead.
- *
- * @param request request to send
- * @param callback callback that gets executed when response arrives, must not be null
- * @return a completable future to let you know when the request is done. The future contains the
- * callback result.
- * @deprecated Please use {@link MatomoTracker#sendRequestAsync(MatomoRequest)} in combination
- * with {@link CompletableFuture#thenAccept(Consumer)} instead
- */
- @Deprecated
- public Specify the AuthToken if parameters that require an auth token is used. If you want to send
- * a single request, use {@link #sendRequest(MatomoRequest)} instead. If you want to send multiple
- * requests asynchronously, use {@link #sendBulkRequestAsync(Collection)} instead.
- *
- * @param requests the requests to send
- * @param authToken specify if any of the parameters use require AuthToken, if null the default
- * auth token from the request or the tracker configuration is used.
- * @deprecated use {@link #sendBulkRequest(Iterable)} instead and set the auth token in the
- * tracker configuration or the requests directly.
- */
- @Deprecated
- public void sendBulkRequest(
- @NonNull Iterable extends MatomoRequest> requests, @Nullable String authToken) {
if (trackerConfiguration.isEnabled()) {
for (MatomoRequest request : requests) {
applyGoalIdAndCheckSiteId(request);
}
log.debug("Sending requests via POST: {}", requests);
initializeSender();
- sender.sendBulk(requests, authToken);
+ sender.sendBulk(requests);
} else {
log.warn("Not sending request, because tracker is disabled");
}
@@ -276,7 +161,7 @@ public void sendBulkRequest(
* @return completable future to let you know when the request is done
*/
public CompletableFuture Renamed to {@link org.matomo.java.tracking.parameters.CustomVariable} in 3.0.0.
- *
- * @author brettcsorba
- * @deprecated Use {@link org.matomo.java.tracking.parameters.CustomVariable} instead.
- */
-@Deprecated
-public class CustomVariable extends org.matomo.java.tracking.parameters.CustomVariable {
-
- /**
- * Instantiates a new custom variable.
- *
- * @param key the key of the custom variable (required)
- * @param value the value of the custom variable (required)
- * @deprecated Use {@link org.matomo.java.tracking.parameters.CustomVariable} instead.
- */
- @Deprecated
- public CustomVariable(String key, String value) {
- super(key, value);
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/EcommerceItem.java b/core/src/main/java/org/piwik/java/tracking/EcommerceItem.java
deleted file mode 100644
index e9b4ce6c..00000000
--- a/core/src/main/java/org/piwik/java/tracking/EcommerceItem.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Matomo Java Tracker
- *
- * @link https://github.com/matomo/matomo-java-tracker
- * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-
-package org.piwik.java.tracking;
-
-/**
- * Describes an item in an ecommerce transaction.
- *
- * @author brettcsorba
- * @deprecated Use {@link org.matomo.java.tracking.parameters.EcommerceItem} instead.
- */
-@Deprecated
-public class EcommerceItem extends org.matomo.java.tracking.parameters.EcommerceItem {
-
- /**
- * Creates a new ecommerce item.
- *
- * @param sku the sku (Stock Keeping Unit) of the item.
- * @param name the name of the item.
- * @param category the category of the item.
- * @param price the price of the item.
- * @param quantity the quantity of the item.
- * @deprecated Use {@link org.matomo.java.tracking.parameters.EcommerceItem} instead.
- */
- @Deprecated
- public EcommerceItem(String sku, String name, String category, Double price, Integer quantity) {
- super(sku, name, category, price, quantity);
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/PiwikDate.java b/core/src/main/java/org/piwik/java/tracking/PiwikDate.java
deleted file mode 100644
index 501ea8ac..00000000
--- a/core/src/main/java/org/piwik/java/tracking/PiwikDate.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Matomo Java Tracker
- *
- * @link https://github.com/matomo/matomo-java-tracker
- * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-
-package org.piwik.java.tracking;
-
-import java.time.Instant;
-import java.time.ZonedDateTime;
-import java.util.TimeZone;
-import org.matomo.java.tracking.MatomoDate;
-
-/**
- * A date object that can be used to send dates to Matomo. This class is deprecated and will be
- * removed in a future.
- *
- * @author brettcsorba
- * @deprecated Please use {@link Instant}
- */
-@Deprecated
-public class PiwikDate extends MatomoDate {
-
- /**
- * Creates a new date object with the current time.
- *
- * @deprecated Use {@link Instant} instead.
- */
- @Deprecated
- public PiwikDate() {}
-
- /**
- * Creates a new date object with the specified time. The time is specified in milliseconds since
- * the epoch.
- *
- * @param epochMilli The time in milliseconds since the epoch
- * @deprecated Use {@link Instant} instead.
- */
- @Deprecated
- public PiwikDate(long epochMilli) {
- super(epochMilli);
- }
-
- /**
- * Sets the time zone for this date object. This is used to convert the date to UTC before sending
- * it to Matomo.
- *
- * @param zone the time zone to use
- * @deprecated Use {@link ZonedDateTime#toInstant()} instead.
- */
- @Deprecated
- public void setTimeZone(TimeZone zone) {
- setTimeZone(zone.toZoneId());
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/PiwikLocale.java b/core/src/main/java/org/piwik/java/tracking/PiwikLocale.java
deleted file mode 100644
index 21f31cf7..00000000
--- a/core/src/main/java/org/piwik/java/tracking/PiwikLocale.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Matomo Java Tracker
- *
- * @link https://github.com/matomo/matomo-java-tracker
- * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-
-package org.piwik.java.tracking;
-
-import java.util.Locale;
-import org.matomo.java.tracking.parameters.Country;
-
-/**
- * A locale object that can be used to send visitor country to Matomo. This class is deprecated and
- * will be removed in the future.
- *
- * @author brettcsorba
- * @deprecated Use {@link Country} instead.
- */
-@Deprecated
-public class PiwikLocale extends Country {
-
- /**
- * Creates a new Piwik locale object with the specified locale.
- *
- * @param locale the locale to use
- * @deprecated Use {@link Country} instead.
- */
- @Deprecated
- public PiwikLocale(Locale locale) {
- super(locale);
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/PiwikRequest.java b/core/src/main/java/org/piwik/java/tracking/PiwikRequest.java
deleted file mode 100644
index 341cf1aa..00000000
--- a/core/src/main/java/org/piwik/java/tracking/PiwikRequest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Matomo Java Tracker
- *
- * @link https://github.com/matomo/matomo-java-tracker
- * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-
-package org.piwik.java.tracking;
-
-import static java.util.Objects.requireNonNull;
-
-import java.net.URL;
-import org.matomo.java.tracking.MatomoRequest;
-
-/**
- * A request object that can be used to send requests to Matomo. This class is deprecated and will
- * be removed in the future.
- *
- * @author brettcsorba
- * @deprecated Use {@link MatomoRequest} instead.
- */
-@Deprecated
-public class PiwikRequest extends MatomoRequest {
-
- /**
- * Creates a new request object with the specified site ID and action URL.
- *
- * @param siteId the site ID
- * @param actionUrl the action URL. Must not be null.
- * @deprecated Use {@link MatomoRequest} instead.
- */
- @Deprecated
- public PiwikRequest(int siteId, URL actionUrl) {
- super(siteId, requireNonNull(actionUrl, "Action URL must not be null").toString());
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/PiwikTracker.java b/core/src/main/java/org/piwik/java/tracking/PiwikTracker.java
deleted file mode 100644
index 89caf0d3..00000000
--- a/core/src/main/java/org/piwik/java/tracking/PiwikTracker.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Matomo Java Tracker
- *
- * @link https://github.com/matomo/matomo-java-tracker
- * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-
-package org.piwik.java.tracking;
-
-import edu.umd.cs.findbugs.annotations.NonNull;
-import edu.umd.cs.findbugs.annotations.Nullable;
-import org.matomo.java.tracking.MatomoTracker;
-
-/**
- * Creates a new PiwikTracker instance. This class is deprecated and will be removed in the future.
- *
- * @author brettcsorba
- * @deprecated Use {@link MatomoTracker} instead.
- */
-@Deprecated
-public class PiwikTracker extends MatomoTracker {
-
- /**
- * Creates a new PiwikTracker instance with the given host URL.
- *
- * @param hostUrl the host URL of the Matomo server
- * @deprecated Use {@link MatomoTracker} instead.
- */
- @Deprecated
- public PiwikTracker(@NonNull String hostUrl) {
- super(hostUrl);
- }
-
- /**
- * Creates a new PiwikTracker instance with the given host URL and timeout in milliseconds. Use -1
- * for no timeout.
- *
- * @param hostUrl the host URL of the Matomo server
- * @param timeout the timeout in milliseconds or -1 for no timeout
- * @deprecated Use {@link MatomoTracker} instead.
- */
- @Deprecated
- public PiwikTracker(@NonNull String hostUrl, int timeout) {
- super(hostUrl, timeout);
- }
-
- /**
- * Creates a new PiwikTracker instance with the given host URL and proxy settings.
- *
- * @param hostUrl the host URL of the Matomo server
- * @param proxyHost the proxy host
- * @param proxyPort the proxy port
- * @deprecated Use {@link MatomoTracker} instead.
- */
- @Deprecated
- public PiwikTracker(@NonNull String hostUrl, @Nullable String proxyHost, int proxyPort) {
- super(hostUrl, proxyHost, proxyPort);
- }
-
- /**
- * Creates a new PiwikTracker instance with the given host URL, proxy settings and timeout in
- * milliseconds. Use -1 for no timeout.
- *
- * @param hostUrl the host URL of the Matomo server
- * @param proxyHost the proxy host
- * @param proxyPort the proxy port
- * @param timeout the timeout in milliseconds or -1 for no timeout
- * @deprecated Use {@link MatomoTracker} instead.
- */
- @Deprecated
- public PiwikTracker(
- @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort, int timeout) {
- super(hostUrl, proxyHost, proxyPort, timeout);
- }
-}
diff --git a/core/src/main/java/org/piwik/java/tracking/package-info.java b/core/src/main/java/org/piwik/java/tracking/package-info.java
deleted file mode 100644
index 39f46a23..00000000
--- a/core/src/main/java/org/piwik/java/tracking/package-info.java
+++ /dev/null
@@ -1,2 +0,0 @@
-/** Piwik Java Tracking API. Renamed to {@link org.matomo.java.tracking} in 3.0.0. */
-package org.piwik.java.tracking;
diff --git a/core/src/test/java/org/matomo/java/tracking/AuthTokenTest.java b/core/src/test/java/org/matomo/java/tracking/AuthTokenTest.java
index cac2ba1e..bdafba71 100644
--- a/core/src/test/java/org/matomo/java/tracking/AuthTokenTest.java
+++ b/core/src/test/java/org/matomo/java/tracking/AuthTokenTest.java
@@ -16,7 +16,7 @@ void determineAuthTokenReturnsAuthTokenFromRequest() {
.authToken("bdeca231a312ab12cde124131bedfa23")
.build();
- String authToken = AuthToken.determineAuthToken(null, singleton(request), null);
+ String authToken = AuthToken.determineAuthToken(singleton(request), null);
assertThat(authToken).isEqualTo("bdeca231a312ab12cde124131bedfa23");
}
@@ -30,7 +30,7 @@ void determineAuthTokenReturnsAuthTokenFromTrackerConfiguration() {
.defaultAuthToken("bdeca231a312ab12cde124131bedfa23")
.build();
- String authToken = AuthToken.determineAuthToken(null, null, trackerConfiguration);
+ String authToken = AuthToken.determineAuthToken(null, trackerConfiguration);
assertThat(authToken).isEqualTo("bdeca231a312ab12cde124131bedfa23");
}
@@ -46,7 +46,7 @@ void determineAuthTokenFromTrackerConfigurationIfRequestTokenIsEmpty() {
.defaultAuthToken("bdeca231a312ab12cde124131bedfa23")
.build();
- String authToken = AuthToken.determineAuthToken(null, singleton(request), trackerConfiguration);
+ String authToken = AuthToken.determineAuthToken(singleton(request), trackerConfiguration);
assertThat(authToken).isEqualTo("bdeca231a312ab12cde124131bedfa23");
}
@@ -62,7 +62,7 @@ void determineAuthTokenFromTrackerConfigurationIfRequestTokenIsBlank() {
.defaultAuthToken("bdeca231a312ab12cde124131bedfa23")
.build();
- String authToken = AuthToken.determineAuthToken(null, singleton(request), trackerConfiguration);
+ String authToken = AuthToken.determineAuthToken(singleton(request), trackerConfiguration);
assertThat(authToken).isEqualTo("bdeca231a312ab12cde124131bedfa23");
}
diff --git a/core/src/test/java/org/matomo/java/tracking/BulkRequestTest.java b/core/src/test/java/org/matomo/java/tracking/BulkRequestTest.java
index a78aac9b..87a6c382 100644
--- a/core/src/test/java/org/matomo/java/tracking/BulkRequestTest.java
+++ b/core/src/test/java/org/matomo/java/tracking/BulkRequestTest.java
@@ -5,12 +5,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.util.Arrays;
import org.junit.jupiter.api.Test;
class BulkRequestTest {
@Test
- void formatsQueriesAsJson() {
+ void formatsQueryAsJson() {
BulkRequest bulkRequest =
BulkRequest.builder()
.queries(singleton("idsite=1&rec=1&action_name=TestBulkRequest"))
@@ -24,6 +25,24 @@ void formatsQueriesAsJson() {
"{\"requests\":[\"?idsite=1&rec=1&action_name=TestBulkRequest\"],\"token_auth\":\"token\"}");
}
+ @Test
+ void formatsQueriesAsJson() {
+ BulkRequest bulkRequest =
+ BulkRequest.builder()
+ .queries(
+ Arrays.asList(
+ "idsite=1&rec=1&action_name=TestBulkRequest1",
+ "idsite=1&rec=1" + "&action_name=TestBulkRequest2"))
+ .authToken("token")
+ .build();
+
+ byte[] bytes = bulkRequest.toBytes();
+
+ assertThat(new String(bytes))
+ .isEqualTo(
+ "{\"requests\":[\"?idsite=1&rec=1&action_name=TestBulkRequest1\",\"?idsite=1&rec=1&action_name=TestBulkRequest2\"],\"token_auth\":\"token\"}");
+ }
+
@Test
void failsIfQueriesAreEmpty() {
diff --git a/core/src/test/java/org/matomo/java/tracking/CustomVariableTest.java b/core/src/test/java/org/matomo/java/tracking/CustomVariableTest.java
deleted file mode 100644
index 8f1cb0bd..00000000
--- a/core/src/test/java/org/matomo/java/tracking/CustomVariableTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.matomo.java.tracking;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import org.junit.jupiter.api.Test;
-
-class CustomVariableTest {
-
- @Test
- void createsCustomVariable() {
- CustomVariable customVariable = new CustomVariable("key", "value");
-
- assertThat(customVariable.getKey()).isEqualTo("key");
- assertThat(customVariable.getValue()).isEqualTo("value");
- }
-
- @Test
- void failsOnNullKey() {
- assertThatThrownBy(() -> new CustomVariable(null, "value"))
- .isInstanceOf(NullPointerException.class);
- }
-
- @Test
- void failsOnNullValue() {
- assertThatThrownBy(() -> new CustomVariable("key", null))
- .isInstanceOf(NullPointerException.class);
- }
-
- @Test
- void failsOnNullKeyAndValue() {
- assertThatThrownBy(() -> new CustomVariable(null, null))
- .isInstanceOf(NullPointerException.class);
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/MatomoLocaleTest.java b/core/src/test/java/org/matomo/java/tracking/MatomoLocaleTest.java
deleted file mode 100644
index c4d1f5ba..00000000
--- a/core/src/test/java/org/matomo/java/tracking/MatomoLocaleTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.matomo.java.tracking;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.Locale;
-import org.junit.jupiter.api.Test;
-
-class MatomoLocaleTest {
-
- @Test
- void createsMatomoLocaleFromLocale() {
- MatomoLocale locale = new MatomoLocale(Locale.US);
- assertThat(locale.toString()).isEqualTo("us");
- }
-
- @Test
- void failsIfLocaleIsNull() {
- assertThatThrownBy(() -> new MatomoLocale(null))
- .isInstanceOf(NullPointerException.class)
- .hasMessage("Locale must not be null");
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java b/core/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java
deleted file mode 100644
index d46403d2..00000000
--- a/core/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.matomo.java.tracking;
-
-import static java.util.Collections.singletonMap;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.Test;
-import org.matomo.java.tracking.parameters.CustomVariables;
-
-class MatomoRequestBuilderTest {
-
- @Test
- void buildsRequest() {
- CustomVariable pageCustomVariable =
- new CustomVariable("pageCustomVariableName", "pageCustomVariableValue");
- CustomVariable visitCustomVariable =
- new CustomVariable("visitCustomVariableName", "visitCustomVariableValue");
-
- MatomoRequest matomoRequest =
- new MatomoRequestBuilder()
- .siteId(42)
- .actionName("ACTION_NAME")
- .actionUrl("https://www.your-domain.tld/some/page?query=foo")
- .referrerUrl("https://referrer.com")
- .additionalParameters(singletonMap("trackingParameterName", "trackingParameterValue"))
- .pageCustomVariables(new CustomVariables().add(pageCustomVariable, 2))
- .visitCustomVariables(new CustomVariables().add(visitCustomVariable, 3))
- .customAction(true)
- .build();
-
- assertThat(matomoRequest.getSiteId()).isEqualTo(42);
- assertThat(matomoRequest.getActionName()).isEqualTo("ACTION_NAME");
- assertThat(matomoRequest.getApiVersion()).isEqualTo("1");
- assertThat(matomoRequest.getActionUrl())
- .isEqualTo("https://www.your-domain.tld/some/page?query=foo");
- assertThat(matomoRequest.getVisitorId().toString()).hasSize(16).isHexadecimal();
- assertThat(matomoRequest.getRandomValue().toString()).hasSize(20).isHexadecimal();
- assertThat(matomoRequest.getResponseAsImage()).isFalse();
- assertThat(matomoRequest.getRequired()).isTrue();
- assertThat(matomoRequest.getReferrerUrl()).isEqualTo("https://referrer.com");
- assertThat(matomoRequest.getCustomTrackingParameter("trackingParameterName"))
- .isEqualTo("trackingParameterValue");
- assertThat(matomoRequest.getPageCustomVariables())
- .hasToString("{\"2\":[\"pageCustomVariableName\",\"pageCustomVariableValue\"]}");
- assertThat(matomoRequest.getVisitCustomVariables())
- .hasToString("{\"3\":[\"visitCustomVariableName\",\"visitCustomVariableValue\"]}");
- assertThat(matomoRequest.getCustomAction()).isTrue();
- }
-
- @Test
- void setCustomTrackingParameters() {
- MatomoRequest matomoRequest =
- new MatomoRequestBuilder()
- .customTrackingParameters(singletonMap("foo", "bar"))
- .siteId(42)
- .actionName("ACTION_NAME")
- .actionUrl("https://www.your-domain.tld/some/page?query=foo")
- .referrerUrl("https://referrer.com")
- .build();
-
- assertThat(matomoRequest.getCustomTrackingParameter("foo")).isEqualTo("bar");
- }
-
- @Test
- void setCustomTrackingParametersWithCollectopm() {
- MatomoRequest matomoRequest =
- new MatomoRequestBuilder()
- .customTrackingParameters(singletonMap("foo", "bar"))
- .siteId(42)
- .actionName("ACTION_NAME")
- .actionUrl("https://www.your-domain.tld/some/page?query=foo")
- .referrerUrl("https://referrer.com")
- .build();
-
- assertThat(matomoRequest.getCustomTrackingParameter("foo")).isEqualTo("bar");
- }
-
- @Test
- void acceptsNullAsHeaderAcceptLanguage() {
- MatomoRequest matomoRequest =
- new MatomoRequestBuilder().headerAcceptLanguage((String) null).build();
-
- assertThat(matomoRequest.getHeaderAcceptLanguage()).isNull();
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/MatomoRequestTest.java b/core/src/test/java/org/matomo/java/tracking/MatomoRequestTest.java
deleted file mode 100644
index 20d2c2f5..00000000
--- a/core/src/test/java/org/matomo/java/tracking/MatomoRequestTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package org.matomo.java.tracking;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
-
-import org.junit.jupiter.api.Test;
-
-class MatomoRequestTest {
-
- private MatomoRequest request = new MatomoRequest();
-
- @Test
- void returnsEmptyListWhenCustomTrackingParametersDoesNotContainKey() {
-
- request.setCustomTrackingParameter("foo", "bar");
-
- assertThat(request.getCustomTrackingParameter("baz")).isNull();
- assertThat(request.getAdditionalParameters()).isNotEmpty();
- assertThat(request.getCustomTrackingParameter("foo")).isEqualTo("bar");
- }
-
- @Test
- void getPageCustomVariableReturnsNullIfPageCustomVariablesIsNull() {
- assertThat(request.getPageCustomVariable("foo")).isNull();
- }
-
- @Test
- void getPageCustomVariableReturnsValueIfPageCustomVariablesIsNotNull() {
- request.setPageCustomVariable("foo", "bar");
- assertThat(request.getPageCustomVariable("foo")).isEqualTo("bar");
- }
-
- @Test
- void setPageCustomVariableRequiresNonNullKey() {
- assertThatThrownBy(() -> request.setPageCustomVariable(null, "bar"))
- .isInstanceOf(NullPointerException.class);
- }
-
- @Test
- void setPageCustomVariableDoesNothingIfValueIsNull() {
- request.setPageCustomVariable("foo", null);
- assertThat(request.getPageCustomVariable("foo")).isNull();
- }
-
- @Test
- void setPageCustomVariableRemovesValueIfValueIsNull() {
- request.setPageCustomVariable("foo", "bar");
- request.setPageCustomVariable("foo", null);
- assertThat(request.getPageCustomVariable("foo")).isNull();
- }
-
- @Test
- void setPageCustomVariableAddsCustomVariableIfValueIsNotNull() {
- request.setPageCustomVariable("foo", "bar");
- assertThat(request.getPageCustomVariable("foo")).isEqualTo("bar");
- }
-
- @Test
- void setPageCustomVariableDoesNothingIfCustomVariableParameterIsNullAndIndexIsPositive() {
- request.setPageCustomVariable(null, 1);
- assertThat(request.getPageCustomVariable(1)).isNull();
- }
-
- @Test
- void
- setPageCustomVariableInitializesPageCustomVariablesIfCustomVariableParameterIsNullAndIndexIsPositive() {
- request.setPageCustomVariable(new CustomVariable("key", "value"), 1);
- assertThat(request.getPageCustomVariables()).isNotNull();
- }
-
- @Test
- void setUserCustomVariableDoesNothingIfValueIsNull() {
- request.setUserCustomVariable("foo", null);
- assertThat(request.getUserCustomVariable("foo")).isNull();
- }
-
- @Test
- void setUserCustomVariableRemovesValueIfValueIsNull() {
- request.setUserCustomVariable("foo", "bar");
- request.setUserCustomVariable("foo", null);
- assertThat(request.getUserCustomVariable("foo")).isNull();
- }
-
- @Test
- void setVisitCustomVariableDoesNothingIfCustomVariableParameterIsNullAndIndexIsPositive() {
- request.setVisitCustomVariable(null, 1);
- assertThat(request.getVisitCustomVariable(1)).isNull();
- }
-
- @Test
- void
- setVisitCustomVariableInitializesVisitCustomVariablesIfCustomVariableParameterIsNullAndIndexIsPositive() {
- request.setVisitCustomVariable(new CustomVariable("key", "value"), 1);
- assertThat(request.getVisitCustomVariables()).isNotNull();
- }
-
- @Test
- void setsCustomParameter() {
- request.setParameter("foo", 1);
- assertThat(request.getCustomTrackingParameter("foo")).isEqualTo(1);
- }
-
- @Test
- void failsToSetCustomParameterIfKeyIsNull() {
- assertThatThrownBy(() -> request.setParameter(null, 1))
- .isInstanceOf(NullPointerException.class);
- }
-
- @Test
- void doesNothingWhenSettingCustomParameterIfValueIsNull() {
- request.setParameter("foo", null);
- assertThat(request.getAdditionalParameters()).isNull();
- }
-
- @Test
- void removesCustomParameter() {
- request.setParameter("foo", 1);
- request.setParameter("foo", null);
- assertThat(request.getAdditionalParameters()).isEmpty();
- }
-
- @Test
- void setsDeviceResolutionString() {
- request.setDeviceResolution("1920x1080");
- assertThat(request.getDeviceResolution().toString()).isEqualTo("1920x1080");
- }
-
- @Test
- void failsIfSetParameterParameterNameIsBlank() {
- assertThatThrownBy(() -> request.setParameter(" ", "bar"))
- .isInstanceOf(IllegalArgumentException.class);
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/MatomoTrackerIT.java b/core/src/test/java/org/matomo/java/tracking/MatomoTrackerIT.java
index efbdb067..6171bd52 100644
--- a/core/src/test/java/org/matomo/java/tracking/MatomoTrackerIT.java
+++ b/core/src/test/java/org/matomo/java/tracking/MatomoTrackerIT.java
@@ -5,6 +5,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.net.URI;
+import java.time.Duration;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
import org.matomo.java.tracking.parameters.RandomValue;
@@ -28,7 +29,8 @@ class MatomoTrackerIT {
@Test
void sendsRequest() {
- matomoTracker = new MatomoTracker(HOST_URL);
+ matomoTracker =
+ new MatomoTracker(TrackerConfiguration.builder().apiEndpoint(URI.create(HOST_URL)).build());
matomoTracker.setSenderFactory(senderFactory);
matomoTracker.sendRequest(request);
@@ -41,7 +43,8 @@ void sendsRequest() {
@Test
void validatesRequest() {
- matomoTracker = new MatomoTracker(HOST_URL);
+ matomoTracker =
+ new MatomoTracker(TrackerConfiguration.builder().apiEndpoint(URI.create(HOST_URL)).build());
matomoTracker.setSenderFactory(senderFactory);
request.setSiteId(null);
@@ -71,7 +74,13 @@ void doesNotSendRequestIfNotEnabled() {
@Test
void sendsRequestUsingProxy() {
- matomoTracker = new MatomoTracker(HOST_URL, "localhost", 8081);
+ matomoTracker =
+ new MatomoTracker(
+ TrackerConfiguration.builder()
+ .apiEndpoint(URI.create(HOST_URL))
+ .proxyHost("localhost")
+ .proxyPort(8081)
+ .build());
matomoTracker.setSenderFactory(senderFactory);
matomoTracker.sendRequest(request);
@@ -86,7 +95,13 @@ void sendsRequestUsingProxy() {
@Test
void sendsRequestAsync() {
- matomoTracker = new MatomoTracker(HOST_URL, 1000);
+ matomoTracker =
+ new MatomoTracker(
+ TrackerConfiguration.builder()
+ .apiEndpoint(URI.create(HOST_URL))
+ .connectTimeout(Duration.ofSeconds(1L))
+ .socketTimeout(Duration.ofSeconds(1L))
+ .build());
matomoTracker.setSenderFactory(senderFactory);
matomoTracker.sendRequestAsync(request);
@@ -99,16 +114,22 @@ void sendsRequestAsync() {
@Test
void sendsRequestAsyncWithCallback() {
- matomoTracker = new MatomoTracker(HOST_URL, 1000);
+ matomoTracker =
+ new MatomoTracker(
+ TrackerConfiguration.builder()
+ .apiEndpoint(URI.create(HOST_URL))
+ .connectTimeout(Duration.ofSeconds(1L))
+ .socketTimeout(Duration.ofSeconds(1L))
+ .build());
matomoTracker.setSenderFactory(senderFactory);
AtomicBoolean callbackCalled = new AtomicBoolean();
- matomoTracker.sendRequestAsync(
- request,
- request -> {
- assertThat(request).isEqualTo(request);
- callbackCalled.set(true);
- return null;
- });
+ matomoTracker
+ .sendRequestAsync(request)
+ .thenAccept(
+ request -> {
+ assertThat(request).isEqualTo(this.request);
+ callbackCalled.set(true);
+ });
TestSender testSender = senderFactory.getTestSender();
thenContainsRequest(testSender, QUERY);
@@ -135,7 +156,8 @@ void doesNotSendRequestAsyncIfNotEnabled() {
@Test
void sendsBulkRequests() {
- matomoTracker = new MatomoTracker(HOST_URL);
+ matomoTracker =
+ new MatomoTracker(TrackerConfiguration.builder().apiEndpoint(URI.create(HOST_URL)).build());
matomoTracker.setSenderFactory(senderFactory);
matomoTracker.sendBulkRequest(request);
@@ -164,7 +186,13 @@ void doesNotSendBulkRequestsIfNotEnabled() {
@Test
void sendsBulkRequestsAsync() {
- matomoTracker = new MatomoTracker(HOST_URL, 1000);
+ matomoTracker =
+ new MatomoTracker(
+ TrackerConfiguration.builder()
+ .apiEndpoint(URI.create(HOST_URL))
+ .connectTimeout(Duration.ofSeconds(1L))
+ .socketTimeout(Duration.ofSeconds(1L))
+ .build());
matomoTracker.setSenderFactory(senderFactory);
matomoTracker.sendBulkRequestAsync(request);
@@ -193,10 +221,18 @@ void doesNotSendBulkRequestsAsyncIfNotEnabled() {
@Test
void sendsBulkRequestAsyncWithCallback() {
- matomoTracker = new MatomoTracker(HOST_URL, 1000);
+ matomoTracker =
+ new MatomoTracker(
+ TrackerConfiguration.builder()
+ .apiEndpoint(URI.create(HOST_URL))
+ .connectTimeout(Duration.ofSeconds(1L))
+ .socketTimeout(Duration.ofSeconds(1L))
+ .build());
matomoTracker.setSenderFactory(senderFactory);
AtomicBoolean callbackCalled = new AtomicBoolean();
- matomoTracker.sendBulkRequestAsync(singleton(request), v -> callbackCalled.set(true));
+ matomoTracker
+ .sendBulkRequestAsync(singleton(request))
+ .thenAccept(request -> callbackCalled.set(true));
TestSender testSender = senderFactory.getTestSender();
thenContainsRequest(testSender, QUERY);
@@ -204,24 +240,11 @@ void sendsBulkRequestAsyncWithCallback() {
assertThat(callbackCalled).isTrue();
}
- @Test
- void sendsBulkRequestAsyncWithAuthToken() {
-
- matomoTracker = new MatomoTracker(HOST_URL, 1000);
- matomoTracker.setSenderFactory(senderFactory);
- matomoTracker.sendBulkRequestAsync(singleton(request), "abc123def456abc123def456abc123de");
-
- TestSender testSender = senderFactory.getTestSender();
- thenContainsRequest(
- testSender,
- "token_auth=abc123def456abc123def456abc123de&rec=1&idsite=1&action_name=test&apiv=1&_id=00000000343efaf5&send_image=0&rand=test-random");
- assertThat(testSender.getTrackerConfiguration().getApiEndpoint()).hasToString(HOST_URL);
- }
-
@Test
void appliesGoalId() {
- matomoTracker = new MatomoTracker(HOST_URL);
+ matomoTracker =
+ new MatomoTracker(TrackerConfiguration.builder().apiEndpoint(URI.create(HOST_URL)).build());
matomoTracker.setSenderFactory(senderFactory);
request.setEcommerceId("some-id");
diff --git a/core/src/test/java/org/matomo/java/tracking/PiwikDateTest.java b/core/src/test/java/org/matomo/java/tracking/PiwikDateTest.java
deleted file mode 100644
index c5d99795..00000000
--- a/core/src/test/java/org/matomo/java/tracking/PiwikDateTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.matomo.java.tracking;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.TimeZone;
-import org.junit.jupiter.api.Test;
-import org.piwik.java.tracking.PiwikDate;
-
-class PiwikDateTest {
-
- /** Test of constructor, of class PiwikDate. */
- @Test
- void testConstructor0() {
- PiwikDate date = new PiwikDate();
- assertThat(date).isNotNull();
- }
-
- @Test
- void testConstructor1() {
- PiwikDate date = new PiwikDate(1433186085092L);
- assertThat(date).isNotNull();
- assertThat(date.getTime()).isEqualTo(1433186085092L);
- }
-
- @Test
- void testConstructor2() {
- PiwikDate date = new PiwikDate(1467437553000L);
- assertThat(date.getTime()).isEqualTo(1467437553000L);
- }
-
- /** Test of setTimeZone method, of class PiwikDate. */
- @Test
- void testSetTimeZone() {
- PiwikDate date = new PiwikDate(1433186085092L);
- date.setTimeZone(TimeZone.getTimeZone("America/New_York"));
- assertThat(date.getTime()).isEqualTo(1433186085092L);
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java b/core/src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java
deleted file mode 100644
index a03b97c9..00000000
--- a/core/src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.matomo.java.tracking;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Locale;
-import org.junit.jupiter.api.Test;
-import org.piwik.java.tracking.PiwikLocale;
-
-class PiwikLocaleTest {
-
- private final PiwikLocale locale = new PiwikLocale(Locale.US);
-
- /** Test of setLocale method, of class PiwikLocale. */
- @Test
- void testLocale() {
- locale.setLocale(Locale.GERMANY);
- assertThat(locale.getLocale()).isEqualTo(Locale.GERMAN);
- }
-
- /** Test of toString method, of class PiwikLocale. */
- @Test
- void testToString() {
- assertThat(locale).hasToString("us");
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/PiwikRequestTest.java b/core/src/test/java/org/matomo/java/tracking/PiwikRequestTest.java
deleted file mode 100644
index 6f11c1e7..00000000
--- a/core/src/test/java/org/matomo/java/tracking/PiwikRequestTest.java
+++ /dev/null
@@ -1,809 +0,0 @@
-package org.matomo.java.tracking;
-
-import static java.time.temporal.ChronoUnit.MINUTES;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.Assertions.fail;
-import static org.assertj.core.api.Assertions.within;
-
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.time.Instant;
-import java.time.ZonedDateTime;
-import java.util.Locale;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.matomo.java.tracking.parameters.AcceptLanguage;
-import org.matomo.java.tracking.parameters.DeviceResolution;
-import org.matomo.java.tracking.parameters.RandomValue;
-import org.matomo.java.tracking.parameters.VisitorId;
-import org.piwik.java.tracking.PiwikDate;
-import org.piwik.java.tracking.PiwikLocale;
-import org.piwik.java.tracking.PiwikRequest;
-
-class PiwikRequestTest {
-
- private PiwikRequest request;
-
- @BeforeEach
- void setUp() throws Exception {
- request = new PiwikRequest(3, new URL("https://test.com"));
- }
-
- @Test
- void testConstructor() throws Exception {
- request = new PiwikRequest(3, new URL("https://test.com"));
- assertThat(request.getSiteId()).isEqualTo(Integer.valueOf(3));
- assertThat(request.getRequired()).isTrue();
- assertThat(request.getActionUrl()).isEqualTo("https://test.com");
- assertThat(request.getVisitorId()).isNotNull();
- assertThat(request.getRandomValue()).isNotNull();
- assertThat(request.getApiVersion()).isEqualTo("1");
- assertThat(request.getResponseAsImage()).isFalse();
- }
-
- /** Test of getActionName method, of class PiwikRequest. */
- @Test
- void testActionName() {
- request.setActionName("action");
- assertThat(request.getActionName()).isEqualTo("action");
- request.setActionName(null);
- assertThat(request.getActionName()).isNull();
- }
-
- /** Test of getActionUrl method, of class PiwikRequest. */
- @Test
- void testActionUrl() {
- request.setActionUrl(null);
- assertThat(request.getActionUrl()).isNull();
- request.setActionUrl("https://action.com");
- assertThat(request.getActionUrl()).isEqualTo("https://action.com");
- }
-
- /** Test of getApiVersion method, of class PiwikRequest. */
- @Test
- void testApiVersion() {
- request.setApiVersion("2");
- assertThat(request.getApiVersion()).isEqualTo("2");
- }
-
- @Test
- void testAuthTokenTF() {
- request.setAuthToken("12345678901234567890123456789012");
- assertThat(request.getAuthToken()).isEqualTo("12345678901234567890123456789012");
- }
-
- @Test
- void testAuthTokenF() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setAuthToken(null);
- assertThat(request.getAuthToken()).isNull();
- }
-
- /** Test of getCampaignKeyword method, of class PiwikRequest. */
- @Test
- void testCampaignKeyword() {
- request.setCampaignKeyword("keyword");
- assertThat(request.getCampaignKeyword()).isEqualTo("keyword");
- }
-
- /** Test of getCampaignName method, of class PiwikRequest. */
- @Test
- void testCampaignName() {
- request.setCampaignName("name");
- assertThat(request.getCampaignName()).isEqualTo("name");
- }
-
- /** Test of getCharacterSet method, of class PiwikRequest. */
- @Test
- void testCharacterSet() {
- Charset charset = Charset.defaultCharset();
- request.setCharacterSet(charset);
- assertThat(request.getCharacterSet()).isEqualTo(charset);
- }
-
- /** Test of getContentInteraction method, of class PiwikRequest. */
- @Test
- void testContentInteraction() {
- request.setContentInteraction("interaction");
- assertThat(request.getContentInteraction()).isEqualTo("interaction");
- }
-
- /** Test of getContentName method, of class PiwikRequest. */
- @Test
- void testContentName() {
- request.setContentName("name");
- assertThat(request.getContentName()).isEqualTo("name");
- }
-
- /** Test of getContentPiece method, of class PiwikRequest. */
- @Test
- void testContentPiece() {
- request.setContentPiece("piece");
- assertThat(request.getContentPiece()).isEqualTo("piece");
- }
-
- /** Test of getContentTarget method, of class PiwikRequest. */
- @Test
- void testContentTarget() {
- request.setContentTarget("https://target.com");
- assertThat(request.getContentTarget()).isEqualTo("https://target.com");
- }
-
- /** Test of getCurrentHour method, of class PiwikRequest. */
- @Test
- void testCurrentHour() {
- request.setCurrentHour(1);
- assertThat(request.getCurrentHour()).isEqualTo(Integer.valueOf(1));
- }
-
- /** Test of getCurrentMinute method, of class PiwikRequest. */
- @Test
- void testCurrentMinute() {
- request.setCurrentMinute(2);
- assertThat(request.getCurrentMinute()).isEqualTo(Integer.valueOf(2));
- }
-
- /** Test of getCurrentSecond method, of class PiwikRequest. */
- @Test
- void testCurrentSecond() {
- request.setCurrentSecond(3);
- assertThat(request.getCurrentSecond()).isEqualTo(Integer.valueOf(3));
- }
-
- /** Test of getCustomTrackingParameter method, of class PiwikRequest. */
- @Test
- void testGetCustomTrackingParameter_T() {
- try {
- request.getCustomTrackingParameter(null);
- fail("Exception should have been thrown.");
- } catch (NullPointerException e) {
- assertThat(e.getLocalizedMessage()).isEqualTo("key is marked non-null but is null");
- }
- }
-
- @Test
- void testGetCustomTrackingParameter_FT() {
- assertThat(request.getCustomTrackingParameter("key")).isNull();
- }
-
- @Test
- void testSetCustomTrackingParameter_T() {
- try {
- request.setCustomTrackingParameter(null, null);
- fail("Exception should have been thrown.");
- } catch (NullPointerException e) {
- assertThat(e.getLocalizedMessage()).isEqualTo("key is marked non-null but is null");
- }
- }
-
- @Test
- void testSetCustomTrackingParameter1() {
- request.setCustomTrackingParameter("key", "value");
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isEqualTo("value");
- request.setCustomTrackingParameter("key", "value2");
- }
-
- @Test
- void testSetCustomTrackingParameter2() {
- request.setCustomTrackingParameter("key", "value2");
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isEqualTo("value2");
- request.setCustomTrackingParameter("key", null);
- l = request.getCustomTrackingParameter("key");
- assertThat(l).isNull();
- }
-
- @Test
- void testSetCustomTrackingParameter3() {
- request.setCustomTrackingParameter("key", null);
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isNull();
- }
-
- @Test
- void testAddCustomTrackingParameter_T() {
- try {
- request.addCustomTrackingParameter(null, null);
- fail("Exception should have been thrown.");
- } catch (NullPointerException e) {
- assertThat(e.getLocalizedMessage()).isEqualTo("key is marked non-null but is null");
- }
- }
-
- @Test
- void testAddCustomTrackingParameter1() {
- request.addCustomTrackingParameter("key", "value");
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isEqualTo("value");
- }
-
- @Test
- void testAddCustomTrackingParameter2() {
- request.addCustomTrackingParameter("key", "value");
- request.addCustomTrackingParameter("key", "value2");
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isEqualTo("value2");
- }
-
- @Test
- void testClearCustomTrackingParameter() {
- request.setCustomTrackingParameter("key", "value");
- request.clearCustomTrackingParameter();
- Object l = request.getCustomTrackingParameter("key");
- assertThat(l).isNull();
- }
-
- /** Test of getDeviceResolution method, of class PiwikRequest. */
- @Test
- void testDeviceResolution() {
- request.setDeviceResolution(DeviceResolution.fromString("100x200"));
- assertThat(request.getDeviceResolution()).hasToString("100x200");
- }
-
- /** Test of getDownloadUrl method, of class PiwikRequest. */
- @Test
- void testDownloadUrl() {
-
- request.setDownloadUrl("https://download.com");
- assertThat(request.getDownloadUrl()).isEqualTo("https://download.com");
- }
-
- /** Test of enableEcommerce method, of class PiwikRequest. */
- @Test
- void testEnableEcommerce() {
- request.enableEcommerce();
- assertThat(request.getGoalId()).isEqualTo(Integer.valueOf(0));
- }
-
- /** Test of getEcommerceDiscount method, of class PiwikRequest. */
- @Test
- void testEcommerceDiscountT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.setEcommerceDiscount(1.0);
- assertThat(request.getEcommerceDiscount()).isEqualTo(Double.valueOf(1.0));
- }
-
- @Test
- void testEcommerceDiscountF() {
- request.setEcommerceDiscount(null);
- assertThat(request.getEcommerceDiscount()).isNull();
- }
-
- /** Test of getEcommerceId method, of class PiwikRequest. */
- @Test
- void testEcommerceIdT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- assertThat(request.getEcommerceId()).isEqualTo("1");
- }
-
- @Test
- void testEcommerceIdF() {
- request.setEcommerceId(null);
- assertThat(request.getEcommerceId()).isNull();
- }
-
- @Test
- void testEcommerceItemE2() {
- try {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.addEcommerceItem(null);
- fail("Exception should have been thrown.");
- } catch (NullPointerException e) {
- assertThat(e.getLocalizedMessage()).isEqualTo("item is marked non-null but is null");
- }
- }
-
- @Test
- void testEcommerceItem() {
- assertThat(request.getEcommerceItem(0)).isNull();
- EcommerceItem item = new EcommerceItem("sku", "name", "category", 1.0, 2);
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.addEcommerceItem(item);
- assertThat(request.getEcommerceItem(0)).isEqualTo(item);
- request.clearEcommerceItems();
- assertThat(request.getEcommerceItem(0)).isNull();
- }
-
- /** Test of getEcommerceLastOrderTimestamp method, of class PiwikRequest. */
- @Test
- void testEcommerceLastOrderTimestampT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.setEcommerceLastOrderTimestamp(Instant.ofEpochSecond(1000L));
- assertThat(request.getEcommerceLastOrderTimestamp()).isEqualTo("1970-01-01T00:16:40Z");
- }
-
- @Test
- void testEcommerceLastOrderTimestampF() {
- request.setEcommerceLastOrderTimestamp(null);
- assertThat(request.getEcommerceLastOrderTimestamp()).isNull();
- }
-
- /** Test of getEcommerceRevenue method, of class PiwikRequest. */
- @Test
- void testEcommerceRevenueT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(20.0);
- assertThat(request.getEcommerceRevenue()).isEqualTo(Double.valueOf(20.0));
- }
-
- @Test
- void testEcommerceRevenueF() {
- request.setEcommerceRevenue(null);
- assertThat(request.getEcommerceRevenue()).isNull();
- }
-
- /** Test of getEcommerceShippingCost method, of class PiwikRequest. */
- @Test
- void testEcommerceShippingCostT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.setEcommerceShippingCost(20.0);
- assertThat(request.getEcommerceShippingCost()).isEqualTo(Double.valueOf(20.0));
- }
-
- @Test
- void testEcommerceShippingCostF() {
- request.setEcommerceShippingCost(null);
- assertThat(request.getEcommerceShippingCost()).isNull();
- }
-
- /** Test of getEcommerceSubtotal method, of class PiwikRequest. */
- @Test
- void testEcommerceSubtotalT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.setEcommerceSubtotal(20.0);
- assertThat(request.getEcommerceSubtotal()).isEqualTo(Double.valueOf(20.0));
- }
-
- @Test
- void testEcommerceSubtotalF() {
- request.setEcommerceSubtotal(null);
- assertThat(request.getEcommerceSubtotal()).isNull();
- }
-
- /** Test of getEcommerceTax method, of class PiwikRequest. */
- @Test
- void testEcommerceTaxT() {
- request.enableEcommerce();
- request.setEcommerceId("1");
- request.setEcommerceRevenue(2.0);
- request.setEcommerceTax(20.0);
- assertThat(request.getEcommerceTax()).isEqualTo(Double.valueOf(20.0));
- }
-
- @Test
- void testEcommerceTaxF() {
- request.setEcommerceTax(null);
- assertThat(request.getEcommerceTax()).isNull();
- }
-
- /** Test of getEventAction method, of class PiwikRequest. */
- @Test
- void testEventAction() {
- request.setEventAction("action");
- assertThat(request.getEventAction()).isEqualTo("action");
- request.setEventAction(null);
- assertThat(request.getEventAction()).isNull();
- }
-
- /** Test of getEventCategory method, of class PiwikRequest. */
- @Test
- void testEventCategory() {
- request.setEventCategory("category");
- assertThat(request.getEventCategory()).isEqualTo("category");
- }
-
- /** Test of getEventName method, of class PiwikRequest. */
- @Test
- void testEventName() {
- request.setEventName("name");
- assertThat(request.getEventName()).isEqualTo("name");
- }
-
- /** Test of getEventValue method, of class PiwikRequest. */
- @Test
- void testEventValue() {
- request.setEventValue(1.0);
- assertThat(request.getEventValue()).isOne();
- }
-
- /** Test of getGoalId method, of class PiwikRequest. */
- @Test
- void testGoalId() {
- request.setGoalId(1);
- assertThat(request.getGoalId()).isEqualTo(Integer.valueOf(1));
- }
-
- /** Test of getHeaderAcceptLanguage method, of class PiwikRequest. */
- @Test
- void testHeaderAcceptLanguage() {
- request.setHeaderAcceptLanguage(AcceptLanguage.fromHeader("en"));
- assertThat(request.getHeaderAcceptLanguage()).hasToString("en");
- }
-
- /** Test of getHeaderUserAgent method, of class PiwikRequest. */
- @Test
- void testHeaderUserAgent() {
- request.setHeaderUserAgent("agent");
- assertThat(request.getHeaderUserAgent()).isEqualTo("agent");
- }
-
- /** Test of getNewVisit method, of class PiwikRequest. */
- @Test
- void testNewVisit() {
- request.setNewVisit(true);
- assertThat(request.getNewVisit()).isTrue();
- request.setNewVisit(null);
- assertThat(request.getNewVisit()).isNull();
- }
-
- /** Test of getOutlinkUrl method, of class PiwikRequest. */
- @Test
- void testOutlinkUrl() {
- request.setOutlinkUrl("https://outlink.com");
- assertThat(request.getOutlinkUrl()).isEqualTo("https://outlink.com");
- }
-
- /** Test of getPageCustomVariable method, of class PiwikRequest. */
- @Test
- void testPageCustomVariableStringStringE() {
- assertThatThrownBy(() -> request.setPageCustomVariable(null, null));
- }
-
- @Test
- void testPageCustomVariableStringStringE2() {
- assertThatThrownBy(() -> request.setPageCustomVariable(null, "pageVal"));
- }
-
- @Test
- void testPageCustomVariableCustomVariable() {
- assertThat(request.getPageCustomVariable(1)).isNull();
- CustomVariable cv = new CustomVariable("pageKey", "pageVal");
- request.setPageCustomVariable(cv, 1);
- assertThat(request.getPageCustomVariable(1)).isEqualTo(cv);
- request.setPageCustomVariable(null, 1);
- assertThat(request.getPageCustomVariable(1)).isNull();
- request.setPageCustomVariable(cv, 2);
- assertThat(request.getPageCustomVariable(2)).isEqualTo(cv);
- }
-
- /** Test of getPluginDirector method, of class PiwikRequest. */
- @Test
- void testPluginDirector() {
- request.setPluginDirector(true);
- assertThat(request.getPluginDirector()).isTrue();
- }
-
- /** Test of getPluginFlash method, of class PiwikRequest. */
- @Test
- void testPluginFlash() {
- request.setPluginFlash(true);
- assertThat(request.getPluginFlash()).isTrue();
- }
-
- /** Test of getPluginGears method, of class PiwikRequest. */
- @Test
- void testPluginGears() {
- request.setPluginGears(true);
- assertThat(request.getPluginGears()).isTrue();
- }
-
- /** Test of getPluginJava method, of class PiwikRequest. */
- @Test
- void testPluginJava() {
- request.setPluginJava(true);
- assertThat(request.getPluginJava()).isTrue();
- }
-
- /** Test of getPluginPDF method, of class PiwikRequest. */
- @Test
- void testPluginPDF() {
- request.setPluginPDF(true);
- assertThat(request.getPluginPDF()).isTrue();
- }
-
- /** Test of getPluginQuicktime method, of class PiwikRequest. */
- @Test
- void testPluginQuicktime() {
- request.setPluginQuicktime(true);
- assertThat(request.getPluginQuicktime()).isTrue();
- }
-
- /** Test of getPluginRealPlayer method, of class PiwikRequest. */
- @Test
- void testPluginRealPlayer() {
- request.setPluginRealPlayer(true);
- assertThat(request.getPluginRealPlayer()).isTrue();
- }
-
- /** Test of getPluginSilverlight method, of class PiwikRequest. */
- @Test
- void testPluginSilverlight() {
- request.setPluginSilverlight(true);
- assertThat(request.getPluginSilverlight()).isTrue();
- }
-
- /** Test of getPluginWindowsMedia method, of class PiwikRequest. */
- @Test
- void testPluginWindowsMedia() {
- request.setPluginWindowsMedia(true);
- assertThat(request.getPluginWindowsMedia()).isTrue();
- }
-
- /** Test of getRandomValue method, of class PiwikRequest. */
- @Test
- void testRandomValue() {
- request.setRandomValue(RandomValue.fromString("value"));
- assertThat(request.getRandomValue()).hasToString("value");
- }
-
- /** Test of setReferrerUrl method, of class PiwikRequest. */
- @Test
- void testReferrerUrl() {
- request.setReferrerUrl("https://referrer.com");
- assertThat(request.getReferrerUrl()).isEqualTo("https://referrer.com");
- }
-
- /** Test of getRequestDatetime method, of class PiwikRequest. */
- @Test
- void testRequestDatetimeTTT() {
- request.setAuthToken("12345678901234567890123456789012");
- PiwikDate date = new PiwikDate(1000L);
- request.setRequestDatetime(date);
- assertThat(request.getRequestDatetime().getTime()).isEqualTo(1000L);
- }
-
- @Test
- void testRequestDatetimeTF() {
- request.setRequestDatetime(new PiwikDate());
- assertThat(request.getRequestDatetime().getZonedDateTime())
- .isCloseTo(ZonedDateTime.now(), within(2, MINUTES));
- }
-
- @Test
- void testRequestDatetimeF() {
- PiwikDate date = new PiwikDate();
- request.setRequestDatetime(date);
- request.setRequestDatetime(null);
- assertThat(request.getRequestDatetime()).isNull();
- }
-
- /** Test of getRequired method, of class PiwikRequest. */
- @Test
- void testRequired() {
- request.setRequired(false);
- assertThat(request.getRequired()).isFalse();
- }
-
- /** Test of getResponseAsImage method, of class PiwikRequest. */
- @Test
- void testResponseAsImage() {
- request.setResponseAsImage(true);
- assertThat(request.getResponseAsImage()).isTrue();
- }
-
- @Test
- void testSearchCategoryTF() {
- request.setSearchQuery("query");
- request.setSearchCategory("category");
- assertThat(request.getSearchCategory()).isEqualTo("category");
- }
-
- @Test
- void testSearchCategoryF() {
- request.setSearchCategory(null);
- assertThat(request.getSearchCategory()).isNull();
- }
-
- /** Test of getSearchQuery method, of class PiwikRequest. */
- @Test
- void testSearchQuery() {
- request.setSearchQuery("query");
- assertThat(request.getSearchQuery()).isEqualTo("query");
- }
-
- @Test
- void testSearchResultsCountTF() {
- request.setSearchQuery("query");
- request.setSearchResultsCount(100L);
- assertThat(request.getSearchResultsCount()).isEqualTo(Long.valueOf(100L));
- }
-
- @Test
- void testSearchResultsCountF() {
- request.setSearchResultsCount(null);
- assertThat(request.getSearchResultsCount()).isNull();
- }
-
- /** Test of getSiteId method, of class PiwikRequest. */
- @Test
- void testSiteId() {
- request.setSiteId(2);
- assertThat(request.getSiteId()).isEqualTo(Integer.valueOf(2));
- }
-
- /** Test of setTrackBotRequest method, of class PiwikRequest. */
- @Test
- void testTrackBotRequests() {
- request.setTrackBotRequests(true);
- assertThat(request.getTrackBotRequests()).isTrue();
- }
-
- /** Test of getUserCustomVariable method, of class PiwikRequest. */
- @Test
- void testUserCustomVariableStringString() {
- request.setUserCustomVariable("userKey", "userValue");
- assertThat(request.getUserCustomVariable("userKey")).isEqualTo("userValue");
- }
-
- /** Test of getUserId method, of class PiwikRequest. */
- @Test
- void testUserId() {
- request.setUserId("id");
- assertThat(request.getUserId()).isEqualTo("id");
- }
-
- /** Test of getVisitorCity method, of class PiwikRequest. */
- @Test
- void testVisitorCityT() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorCity("city");
- assertThat(request.getVisitorCity()).isEqualTo("city");
- }
-
- @Test
- void testVisitorCityF() {
- request.setVisitorCity(null);
- assertThat(request.getVisitorCity()).isNull();
- }
-
- /** Test of getVisitorCountry method, of class PiwikRequest. */
- @Test
- void testVisitorCountryT() {
- PiwikLocale country = new PiwikLocale(Locale.US);
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorCountry(country);
- assertThat(request.getVisitorCountry()).isEqualTo(country);
- }
-
- @Test
- void testVisitorCountryF() {
- request.setVisitorCountry(null);
- assertThat(request.getVisitorCountry()).isNull();
- }
-
- @Test
- void testVisitorCustomTF() {
- request.setVisitorCustomId(VisitorId.fromHex("1234567890abcdef"));
- assertThat(request.getVisitorCustomId()).hasToString("1234567890abcdef");
- }
-
- @Test
- void testVisitorCustomIdF() {
- request.setVisitorCustomId(VisitorId.fromHex("1234567890abcdef"));
- request.setVisitorCustomId(null);
- assertThat(request.getVisitorCustomId()).isNull();
- }
-
- /** Test of getVisitorFirstVisitTimestamp method, of class PiwikRequest. */
- @Test
- void testVisitorFirstVisitTimestamp() {
- request.setVisitorFirstVisitTimestamp(Instant.parse("2021-03-10T10:22:22.123Z"));
- assertThat(request.getVisitorFirstVisitTimestamp()).isEqualTo("2021-03-10T10:22:22.123Z");
- }
-
- @Test
- void testVisitorIdTFT() {
- try {
- request.setVisitorId(VisitorId.fromHex("1234567890abcdeg"));
- fail("Exception should have been thrown.");
- } catch (IllegalArgumentException e) {
- assertThat(e.getLocalizedMessage()).isEqualTo("Input must be a valid hex string");
- }
- }
-
- @Test
- void testVisitorIdTFF() {
- request.setVisitorId(VisitorId.fromHex("1234567890abcdef"));
- assertThat(request.getVisitorId()).hasToString("1234567890abcdef");
- }
-
- @Test
- void testVisitorIdF() {
- request.setVisitorId(VisitorId.fromHex("1234567890abcdef"));
- request.setVisitorId(null);
- assertThat(request.getVisitorId()).isNull();
- }
-
- /** Test of getVisitorIp method, of class PiwikRequest. */
- @Test
- void testVisitorIpT() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorIp("ip");
- assertThat(request.getVisitorIp()).isEqualTo("ip");
- }
-
- @Test
- void testVisitorIpF() {
- request.setVisitorIp(null);
- assertThat(request.getVisitorIp()).isNull();
- }
-
- /** Test of getVisitorLatitude method, of class PiwikRequest. */
- @Test
- void testVisitorLatitudeT() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorLatitude(10.5);
- assertThat(request.getVisitorLatitude()).isEqualTo(Double.valueOf(10.5));
- }
-
- @Test
- void testVisitorLatitudeF() {
- request.setVisitorLatitude(null);
- assertThat(request.getVisitorLatitude()).isNull();
- }
-
- /** Test of getVisitorLongitude method, of class PiwikRequest. */
- @Test
- void testVisitorLongitudeT() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorLongitude(20.5);
- assertThat(request.getVisitorLongitude()).isEqualTo(Double.valueOf(20.5));
- }
-
- @Test
- void testVisitorLongitudeF() {
- request.setVisitorLongitude(null);
- assertThat(request.getVisitorLongitude()).isNull();
- }
-
- /** Test of getVisitorPreviousVisitTimestamp method, of class PiwikRequest. */
- @Test
- void testVisitorPreviousVisitTimestamp() {
- request.setVisitorPreviousVisitTimestamp(Instant.ofEpochSecond(1000L));
- assertThat(request.getVisitorPreviousVisitTimestamp()).isEqualTo("1970-01-01T00:16:40Z");
- }
-
- /** Test of getVisitorRegion method, of class PiwikRequest. */
- @Test
- void testVisitorRegionT() {
- request.setAuthToken("12345678901234567890123456789012");
- request.setVisitorRegion("region");
- assertThat(request.getVisitorRegion()).isEqualTo("region");
- }
-
- @Test
- void testVisitorRegionF() {
- request.setVisitorRegion(null);
- assertThat(request.getVisitorRegion()).isNull();
- }
-
- /** Test of getVisitorVisitCount method, of class PiwikRequest. */
- @Test
- void testVisitorVisitCount() {
- request.setVisitorVisitCount(100);
- assertThat(request.getVisitorVisitCount()).isEqualTo(Integer.valueOf(100));
- }
-
- @Test
- void failsIfActionUrlIsNull() {
- assertThatThrownBy(() -> new PiwikRequest(3, null))
- .isInstanceOf(NullPointerException.class)
- .hasMessage("Action URL must not be null");
- }
-}
diff --git a/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java b/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
index 0d5a18b5..1bcac9eb 100644
--- a/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
+++ b/core/src/test/java/org/matomo/java/tracking/QueryCreatorTest.java
@@ -56,7 +56,7 @@ private void whenCreatesQuery() {
.defaultSiteId(42)
.defaultAuthToken(defaultAuthToken)
.build();
- String authToken = AuthToken.determineAuthToken(null, singleton(request), trackerConfiguration);
+ String authToken = AuthToken.determineAuthToken(singleton(request), trackerConfiguration);
query = new QueryCreator(trackerConfiguration).createQuery(request, authToken);
}
@@ -362,14 +362,12 @@ void testVisitCustomVariableCustomVariable() {
.randomValue(RandomValue.fromString("random"))
.visitorId(VisitorId.fromHex("1234567890123456"))
.siteId(3);
- org.matomo.java.tracking.CustomVariable cv =
- new org.matomo.java.tracking.CustomVariable("visitKey", "visitVal");
+ CustomVariable cv = new CustomVariable("visitKey", "visitVal");
matomoRequestBuilder.visitCustomVariables(new CustomVariables().add(cv, 8));
defaultAuthToken = null;
whenCreatesQuery();
- assertThat(request.getVisitCustomVariable(1)).isNull();
assertThat(query)
.isEqualTo(
"rec=1&idsite=3&apiv=1&_id=1234567890123456&_cvar=%7B%228%22%3A%5B%22visitKey%22%2C%22visitVal%22%5D%7D&send_image=0&rand=random");
diff --git a/core/src/test/java/org/matomo/java/tracking/RequestValidatorTest.java b/core/src/test/java/org/matomo/java/tracking/RequestValidatorTest.java
index d223f688..e5b09177 100644
--- a/core/src/test/java/org/matomo/java/tracking/RequestValidatorTest.java
+++ b/core/src/test/java/org/matomo/java/tracking/RequestValidatorTest.java
@@ -1,11 +1,12 @@
package org.matomo.java.tracking;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import java.util.Locale;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import org.junit.jupiter.api.Test;
-import org.piwik.java.tracking.PiwikDate;
-import org.piwik.java.tracking.PiwikLocale;
+import org.matomo.java.tracking.parameters.Country;
class RequestValidatorTest {
@@ -66,9 +67,8 @@ void testVisitorRegion() {
}
@Test
- void testVisitorCountryTE() {
- PiwikLocale country = new PiwikLocale(Locale.US);
- request.setVisitorCountry(country);
+ void testVisitorCountry() {
+ request.setVisitorCountry(Country.fromCode("us"));
assertThatThrownBy(() -> RequestValidator.validate(request, null))
.isInstanceOf(MatomoException.class)
@@ -78,16 +78,38 @@ void testVisitorCountryTE() {
}
@Test
- void testRequestDatetime() {
+ void testVisitorIp() {
+ request.setVisitorIp("192.168.0.1");
- PiwikDate date = new PiwikDate(1000L);
- request.setRequestDatetime(date);
+ assertThatThrownBy(() -> RequestValidator.validate(request, null))
+ .isInstanceOf(MatomoException.class)
+ .hasMessage(
+ "Auth token must be present if visitor longitude, latitude, region, city, country or IP"
+ + " are set");
+ }
+
+ @Test
+ void testRequestTimestampOlderThanFourHours() {
+ request.setRequestTimestamp(Instant.now().minus(5, ChronoUnit.HOURS));
assertThatThrownBy(() -> RequestValidator.validate(request, null))
.isInstanceOf(MatomoException.class)
.hasMessage("Auth token must be present if request timestamp is more than four hours ago");
}
+ @Test
+ void doesNotFailIfRequestTimestampIsWithinFourHours() {
+ request.setRequestTimestamp(Instant.now().minus(1, ChronoUnit.HOURS));
+
+ assertThatCode(() -> RequestValidator.validate(request, null)).doesNotThrowAnyException();
+ }
+
+ @Test
+ void doesNotFailWithValid32CharAuthToken() {
+ assertThatCode(() -> RequestValidator.validate(request, "12345678901234567890123456789012"))
+ .doesNotThrowAnyException();
+ }
+
@Test
void failsIfAuthTokenIsNot32CharactersLong() {
assertThatThrownBy(() -> RequestValidator.validate(request, "123456789012345678901234567890"))
diff --git a/core/src/test/java/org/matomo/java/tracking/TestSender.java b/core/src/test/java/org/matomo/java/tracking/TestSender.java
index 30f0395c..0cbc0729 100644
--- a/core/src/test/java/org/matomo/java/tracking/TestSender.java
+++ b/core/src/test/java/org/matomo/java/tracking/TestSender.java
@@ -3,7 +3,6 @@
import static java.util.Collections.singleton;
import edu.umd.cs.findbugs.annotations.NonNull;
-import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
@@ -32,37 +31,34 @@ class TestSender implements Sender {
@NonNull
@Override
public CompletableFuture