Class MatomoTracker

java.lang.Object
org.matomo.java.tracking.MatomoTracker
Direct Known Subclasses:
PiwikTracker

public class MatomoTracker extends Object
A class that sends MatomoRequests to a specified Matomo server.
Author:
brettcsorba
  • Constructor Details

    • MatomoTracker

      public MatomoTracker(@NonNull @NonNull String hostUrl)
      Creates a tracker that will send MatomoRequests to the specified Tracking HTTP API endpoint.
      Parameters:
      hostUrl - url endpoint to send requests to. Usually in the format http://your-matomo-domain.tld/matomo.php. Must not be null
    • MatomoTracker

      public MatomoTracker(@NonNull @NonNull String hostUrl, int timeout)
      Creates a tracker that will send MatomoRequests to the specified Tracking HTTP API endpoint.
      Parameters:
      hostUrl - url endpoint to send requests to. Usually in the format http://your-matomo-domain.tld/matomo.php.
      timeout - the timeout of the sent request in milliseconds
    • MatomoTracker

      public MatomoTracker(@NonNull @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort, int timeout)
    • MatomoTracker

      public MatomoTracker(@NonNull @NonNull String hostUrl, @Nullable String proxyHost, int proxyPort)
      Creates a tracker that will send MatomoRequests to the specified Tracking HTTP API endpoint via the provided proxy
      Parameters:
      hostUrl - url endpoint to send requests to. Usually in the format http://your-matomo-domain.tld/matomo.php.
      proxyHost - url endpoint for the proxy
      proxyPort - proxy server port number
  • Method Details

    • sendRequest

      @Deprecated public org.apache.http.HttpResponse sendRequest(@NonNull @NonNull MatomoRequest request)
      Deprecated.
      use sendRequestAsync instead
      Sends a tracking request to Matomo
      Parameters:
      request - request to send. must not be null
      Returns:
      the response from this request
    • getHttpClient

      protected org.apache.http.client.HttpClient getHttpClient()
      Get a HTTP client. With proxy if a proxy is provided in the constructor.
      Returns:
      a HTTP client
    • sendRequestAsync

      public Future<org.apache.http.HttpResponse> sendRequestAsync(@NonNull @NonNull MatomoRequest request)
      Send a request.
      Parameters:
      request - request to send
      Returns:
      future with response from this request
    • sendRequestAsync

      public Future<org.apache.http.HttpResponse> sendRequestAsync(@NonNull @NonNull MatomoRequest request, @Nullable org.apache.http.concurrent.FutureCallback<org.apache.http.HttpResponse> callback)
      Send a request.
      Parameters:
      request - request to send
      callback - callback that gets executed when response arrives
      Returns:
      future with response from this request
    • getHttpAsyncClient

      protected org.apache.http.impl.nio.client.CloseableHttpAsyncClient getHttpAsyncClient()
      Get an async HTTP client. With proxy if a proxy is provided in the constructor.
      Returns:
      an async HTTP client
    • sendBulkRequest

      @Deprecated public org.apache.http.HttpResponse sendBulkRequest(@NonNull @NonNull Iterable<? extends MatomoRequest> requests)
      Deprecated.
      use sendBulkRequestAsync instead
      Send multiple requests in a single HTTP call. More efficient than sending several individual requests.
      Parameters:
      requests - the requests to send
      Returns:
      the response from these requests
    • sendBulkRequest

      @Deprecated public org.apache.http.HttpResponse sendBulkRequest(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken)
      Deprecated.
      use sendBulkRequestAsync 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 send
      authToken - specify if any of the parameters use require AuthToken
      Returns:
      the response from these requests
    • sendBulkRequestAsync

      public Future<org.apache.http.HttpResponse> 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:
      future with response from these requests
    • sendBulkRequestAsync

      public Future<org.apache.http.HttpResponse> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken, @Nullable org.apache.http.concurrent.FutureCallback<org.apache.http.HttpResponse> 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 send
      authToken - specify if any of the parameters use require AuthToken
      callback - callback that gets executed when response arrives
      Returns:
      the response from these requests
    • sendBulkRequestAsync

      public Future<org.apache.http.HttpResponse> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable org.apache.http.concurrent.FutureCallback<org.apache.http.HttpResponse> callback)
      Send multiple requests in a single HTTP call. More efficient than sending several individual requests.
      Parameters:
      requests - the requests to send
      callback - callback that gets executed when response arrives
      Returns:
      future with response from these requests
    • sendBulkRequestAsync

      public Future<org.apache.http.HttpResponse> sendBulkRequestAsync(@NonNull @NonNull Iterable<? extends MatomoRequest> requests, @Nullable String authToken)
      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 send
      authToken - specify if any of the parameters use require AuthToken
      Returns:
      the response from these requests