I am working on email tracking pixel project, and I want to make sure that users spend at least 30 seconds reading an email before considering it "read"
I am using Java Springboot for backend server and HTML to create email templates
in my template I put this pixel for tracking:
<img id="tr_pixel" src="https://localhost:8080/api/v1/images/1"/>
once the image is loaded it will request my server:
@GetMapping("/images/{emailID}")
public ResponseEntity<byte[]> getImagePixel (@Pathvariable String emailID) {
try{
// wait 30seconds before saving the event
Thread.sleep(30000);
// If the connection with the client is lost, throw an exception and ignore the next line
//save tracking only if user spend > 30s
service.saveTracking(emailID);
return ok().contentType(IMAGE_PNG).body(pixel);
} catch (ConnectionLostException){
// catch connection lost error if the client close the email before 30s or if did not receive the response
}
}
is there any way to check if the connection with the client is lost, or if the client receives the http response?