Class MatomoTracker
- Direct Known Subclasses:
PiwikTracker
MatomoRequest
s to a specified Matomo server.
Contains several methods to send requests synchronously and asynchronously. The asynchronous methods return a
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 TrackerConfiguration
class. You can use the
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.
- Author:
- brettcsorba
-
Constructor Summary
ConstructorsConstructorDescriptionMatomoTracker
(@NonNull String hostUrl) Deprecated.MatomoTracker
(@NonNull String hostUrl, int timeout) Deprecated.Please useMatomoTracker(TrackerConfiguration)
MatomoTracker
(@NonNull String hostUrl, String proxyHost, int proxyPort) Deprecated.Please useMatomoTracker(TrackerConfiguration)
MatomoTracker
(@NonNull String hostUrl, String proxyHost, int proxyPort, int timeout) Deprecated.Please useMatomoTracker(TrackerConfiguration)
MatomoTracker
(@NonNull TrackerConfiguration trackerConfiguration) Creates a new Matomo Tracker instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
sendBulkRequest
(@NonNull Iterable<? extends MatomoRequest> requests) Send multiple requests in a single HTTP POST call.void
sendBulkRequest
(@NonNull Iterable<? extends MatomoRequest> requests, String authToken) Deprecated.usesendBulkRequest(Iterable)
instead and set the auth token in the tracker configuration or the requests directly.void
sendBulkRequest
(MatomoRequest... requests) Send multiple requests in a single HTTP POST call.sendBulkRequestAsync
(@NonNull Iterable<? extends MatomoRequest> requests) Send multiple requests in a single HTTP call.sendBulkRequestAsync
(@NonNull Iterable<? extends MatomoRequest> requests, String authToken) Deprecated.Please set the auth token in the tracker configuration or the requests directly and usesendBulkRequestAsync(Iterable)
instead.sendBulkRequestAsync
(@NonNull Iterable<? extends MatomoRequest> requests, String authToken, Consumer<Void> callback) Deprecated.Please set the auth token in the tracker configuration or the requests directly and useCompletableFuture.thenAccept(Consumer)
instead for the callback.sendBulkRequestAsync
(@NonNull Iterable<? extends MatomoRequest> requests, Consumer<Void> callback) Send multiple requests in a single HTTP call.sendBulkRequestAsync
(MatomoRequest... requests) Send multiple requests in a single HTTP call.void
sendRequest
(@NonNull MatomoRequest request) Sends a tracking request to Matomo using the HTTP GET method.sendRequestAsync
(@NonNull MatomoRequest request) Send a request asynchronously via HTTP GET.<T> CompletableFuture<T>
sendRequestAsync
(@NonNull MatomoRequest request, @NonNull Function<MatomoRequest, T> callback) Deprecated.Please usesendRequestAsync(MatomoRequest)
in combination withCompletableFuture.thenAccept(Consumer)
insteadprotected void
setSenderFactory
(SenderFactory senderFactory)
-
Constructor Details
-
MatomoTracker
Deprecated.Please useMatomoTracker(TrackerConfiguration)
Creates a tracker that will sendMatomoRequest
s to the specified Tracking HTTP API endpoint.- Parameters:
hostUrl
- url endpoint to send requests to. Usually in the format https://your-matomo-domain.tld/matomo.php. Must not be null
-
MatomoTracker
Deprecated.Please useMatomoTracker(TrackerConfiguration)
Creates a tracker that will sendMatomoRequest
s to the specified Tracking HTTP API endpoint.- Parameters:
hostUrl
- url endpoint to send requests to. Usually in the format https://your-matomo-domain.tld/matomo.php.timeout
- the timeout of the sent request in milliseconds or -1 if not set
-
MatomoTracker
@Deprecated public MatomoTracker(@NonNull @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort, int timeout) Deprecated.Please useMatomoTracker(TrackerConfiguration)
Creates a tracker that will sendMatomoRequest
s to the specified Tracking HTTP API endpoint.- Parameters:
hostUrl
- url endpoint to send requests to. Usually in the format https://your-matomo-domain.tld/matomo.php.proxyHost
- The hostname or IP address of an optional HTTP proxy, null allowedproxyPort
- The port of an HTTP proxy or -1 if not settimeout
- the timeout of the request in milliseconds or -1 if not set
-
MatomoTracker
Creates a new Matomo Tracker instance.- Parameters:
trackerConfiguration
- Configurations parameters (you can use a builder)
-
MatomoTracker
@Deprecated public MatomoTracker(@NonNull @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort) Deprecated.Please useMatomoTracker(TrackerConfiguration)
Creates a tracker that will sendMatomoRequest
s to the specified Tracking HTTP API endpoint via the provided proxy.- Parameters:
hostUrl
- url endpoint to send requests to. Usually in the format https://your-matomo-domain.tld/matomo.php.proxyHost
- url endpoint for the proxy, null allowedproxyPort
- proxy server port number or -1 if not set
-
-
Method Details
-
sendRequest
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
sendBulkRequest(Iterable)
instead. If you want to send multiple requests asynchronously, usesendRequestAsync(MatomoRequest)
orsendBulkRequestAsync(Iterable)
instead.- Parameters:
request
- request to send. must not be null
-
sendRequestAsync
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
sendBulkRequestAsync(Iterable)
instead. If you want to send multiple requests synchronously, usesendRequest(MatomoRequest)
orsendBulkRequest(Iterable)
instead.- Parameters:
request
- request to send- Returns:
- completable future to let you know when the request is done. Contains the request.
-
sendRequestAsync
@Deprecated public <T> CompletableFuture<T> sendRequestAsync(@NonNull @NonNull MatomoRequest request, @NonNull @NonNull Function<MatomoRequest, T> callback) Deprecated.Please usesendRequestAsync(MatomoRequest)
in combination withCompletableFuture.thenAccept(Consumer)
insteadSend a request asynchronously via HTTP GET and specify a callback that gets executed when the response arrives.Use this method if you want to send a single request. If you want to send multiple requests at once, use
sendBulkRequestAsync(Iterable, Consumer)
instead. If you want to send multiple requests synchronously, usesendRequest(MatomoRequest)
orsendBulkRequest(Iterable)
instead.- Parameters:
request
- request to sendcallback
- callback that gets executed when response arrives, must not be null- Returns:
- a completable future to let you know when the request is done. The future contains the callback result.
-
sendBulkRequest
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
sendRequest(MatomoRequest)
instead. If you want to send multiple requests asynchronously, usesendBulkRequestAsync(Iterable)
instead.- Parameters:
requests
- the requests to send
-
sendBulkRequest
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
sendRequest(MatomoRequest)
instead. If you want to send multiple requests asynchronously, usesendBulkRequestAsync(Iterable)
instead.- Parameters:
requests
- the requests to send
-
sendBulkRequest
@Deprecated public void sendBulkRequest(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken) Deprecated.usesendBulkRequest(Iterable)
instead and set the auth token in the tracker configuration or the requests directly.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
sendRequest(MatomoRequest)
instead. If you want to send multiple requests asynchronously, usesendBulkRequestAsync(Iterable)
instead.- Parameters:
requests
- the requests to sendauthToken
- specify if any of the parameters use require AuthToken, if null the default auth token from the request or the tracker configuration is used.
-
sendBulkRequestAsync
Send multiple requests in a single HTTP call. More efficient than sending several individual requests.- Parameters:
requests
- the requests to send- Returns:
- completable future to let you know when the request is done
-
sendBulkRequestAsync
public CompletableFuture<Void> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests) Send multiple requests in a single HTTP call. More efficient than sending several individual requests.- Parameters:
requests
- the requests to send- Returns:
- completable future to let you know when the request is done
-
sendBulkRequestAsync
@Deprecated public CompletableFuture<Void> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken, @Nullable Consumer<Void> callback) Deprecated.Please set the auth token in the tracker configuration or the requests directly and useCompletableFuture.thenAccept(Consumer)
instead for the callback.Send multiple requests in a single HTTP call. More efficient than sending several individual requests. Specify the AuthToken if parameters that require an auth token is used.- Parameters:
requests
- the requests to sendauthToken
- specify if any of the parameters use require AuthToken, if null the default auth token from the request or the tracker configuration is usedcallback
- callback that gets executed when response arrives, null allowed- Returns:
- a completable future to let you know when the request is done
-
sendBulkRequestAsync
public CompletableFuture<Void> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable Consumer<Void> callback) Send multiple requests in a single HTTP call. More efficient than sending several individual requests.- Parameters:
requests
- the requests to sendcallback
- callback that gets executed when response arrives, null allowed- Returns:
- completable future to let you know when the request is done
-
sendBulkRequestAsync
public CompletableFuture<Void> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken) Deprecated.Please set the auth token in the tracker configuration or the requests directly and usesendBulkRequestAsync(Iterable)
instead.Send multiple requests in a single HTTP call. More efficient than sending several individual requests. Specify the AuthToken if parameters that require an auth token is used.- Parameters:
requests
- the requests to sendauthToken
- specify if any of the parameters use require AuthToken, null allowed- Returns:
- completable future to let you know when the request is done
-
setSenderFactory
-
MatomoTracker(TrackerConfiguration)