2

I got a web site with a lot of links on it and I want to know which links user chose

I tried to write a small script using JS which send some kind of logs to backend

I want to know is there any method to do this mush easier

Yorn
  • 37
  • 4
  • What kind of logging do you want?It's only user navigation behavior?And what are you using in your view (ex.: thymeleaf, jsp with spring mvc, rest services,etc)? – Juliano Pacheco Nov 02 '19 at 12:52
  • In my view I use thymeleaf. I would like that logs contain following data: links of the current page and what links the user clicked on. for example: links[] and user clicked on links[1], links[5], links[7] – Yorn Nov 02 '19 at 12:59

1 Answers1

0

I guess if you want to work with spring to get this data, you have two possibilities (probably there are others):

Spring Interceptors

In this case you will create an spring interceptor that will monitor the requests made on your page, in this case user clicks. So, to do this you need to create a class that will contain your rule and extend HandleInterceptor or HandlerInterceptorAdapter and choose which method is best suited to capture the information that is useful to you. The methods provided by the interface are preHandle, postHandle, and afterCompletion. After you create your Interceptor you need to register it with a WebMvcConfigurerAdapter. Here two examples:

User activity logging: Spring

Intercepting incoming requests using Spring’s Interceptor

Spring Events

In this case you need to use Spring 5 and Spring-boot 2. With spring events you could get and monitoring many kinds of events, include clicks. In this case you need to create a custom event to contain data related to what you want to monitor, publish it, create a listener and configure a AsynchronousSpringEventsConfig. There are already some pre-created events provided by the framework like RequestHandledEvent and you can test them to see if they fit your case. Here a good link with a good explanation: Spring Events

Using Javascript

And with you wish you also use JS and overwrite onclick event like the guy did in this question on stackoverflow.

Juliano Pacheco
  • 521
  • 1
  • 5
  • 13