Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UFAL/Matomo statistics with dimension #813

Merged
merged 13 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a custom dimension with item's handle URL
  • Loading branch information
milanmajchrak committed Nov 20, 2024
commit 97d3c1ef1213effe6ff807a1456ab1a4db83de52
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.matomo.java.tracking.CustomVariable;
import org.matomo.java.tracking.MatomoException;
import org.matomo.java.tracking.MatomoRequest;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -80,9 +81,11 @@ protected void preTrack(Context context, MatomoRequest matomoRequest, Item item,
matomoRequest.setActionUrl(itemIdentifier);
}
try {
LinkedHashMap<Long, Object> handle = new LinkedHashMap<>();
handle.put(1L, "bitstream");
matomoRequest.setDimensions(handle);
matomoRequest.setPageCustomVariable(new CustomVariable("source", "bitstream"), 1);
// Add the Item handle into the request as a custom dimension
LinkedHashMap<Long, Object> handleDimension = new LinkedHashMap<>();
handleDimension.put(10L, item.getHandle());
matomoRequest.setDimensions(handleDimension);
} catch (MatomoException e) {
log.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import java.util.Calendar;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.CompletableFuture;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Item;
import org.dspace.content.factory.ClarinServiceFactory;
Expand Down Expand Up @@ -134,18 +132,13 @@ protected void preTrack(Context context, MatomoRequest matomoRequest, Item item,
* @param matomoRequest prepared MatomoRequest for sending
*/
public void sendTrackingRequest(MatomoRequest matomoRequest) {
try {
Future<HttpResponse> response = tracker.sendRequestAsync(matomoRequest);
// usually not needed:
HttpResponse httpResponse = response.get();
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode > 399) {
// problem
log.error("Matomo tracker error the response has status code: " + statusCode);
CompletableFuture<MatomoRequest> completableFuture = tracker.sendRequestAsync(matomoRequest);

completableFuture.whenComplete((result, exception) -> {
if (exception != null) {
log.error("Matomo tracker error - the response exception message: {}", exception.getMessage());
}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}

protected String getFullURL(HttpServletRequest request) {
Expand Down
Loading