Class MatomoTracker
- All Implemented Interfaces:
AutoCloseable
MatomoRequests 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 TrackerConfiguration trackerConfiguration) Creates a new Matomo Tracker instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidsendBulkRequest(@NonNull Iterable<? extends MatomoRequest> requests) Send multiple requests in a single HTTP POST call.voidsendBulkRequest(MatomoRequest... requests) Send multiple requests in a single HTTP POST call.sendBulkRequestAsync(@NonNull Collection<? extends MatomoRequest> requests) Send multiple requests in a single HTTP call.sendBulkRequestAsync(MatomoRequest... requests) Send multiple requests in a single HTTP call.voidsendRequest(@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.protected voidsetSenderFactory(SenderFactory senderFactory)
-
Constructor Details
-
MatomoTracker
Creates a new Matomo Tracker instance.- Parameters:
trackerConfiguration- Configurations parameters (you can use a builder)
-
-
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(Collection)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(Collection)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.
-
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(Collection)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(Collection)instead.- Parameters:
requests- the requests to send
-
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 Collection<? 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
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
setSenderFactory
-