JAVA 电子邮件跟踪像素跟踪阅读时间
JAVA email tracking pixel keep track of reading time
我正在从事电子邮件跟踪像素项目,我想确保用户在考虑“已读”之前至少花 30 秒阅读电子邮件
我正在使用 Java Springboot 作为后端服务器,HTML 创建电子邮件模板
在我的模板中,我将此像素用于跟踪:
<img id="tr_pixel" src="https://localhost:8080/api/v1/images/1"/>
图像加载后,它将请求我的服务器:
@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
}
}
有什么方法可以检查客户端是否断开连接,或者客户端是否收到http响应?
也许 302 重定向会对您有所帮助。
您定义两个入口点就足够了。
- 第一个点
@GetMapping("/wait30second/{emailID}")
,收到请求后休眠30秒,发送302重定向到第二个点...your-site.../images/{emailID}
,例如这样:https://www.baeldung.com/spring-redirect-and-forward
- 第二点
@GetMapping("/images/{emailID}")
只是修复了对一个像素的重复访问
service.saveTracking(emailID)
没有 30 秒的停顿。 302 重定向由客户端执行。所以,如果没有重复申诉,就说明这封信没有被阅读。
但是,请记住,随着此类监控的大量使用,您的电子邮件被标记为垃圾邮件的风险很高。
我正在从事电子邮件跟踪像素项目,我想确保用户在考虑“已读”之前至少花 30 秒阅读电子邮件
我正在使用 Java Springboot 作为后端服务器,HTML 创建电子邮件模板
在我的模板中,我将此像素用于跟踪:
<img id="tr_pixel" src="https://localhost:8080/api/v1/images/1"/>
图像加载后,它将请求我的服务器:
@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
}
}
有什么方法可以检查客户端是否断开连接,或者客户端是否收到http响应?
也许 302 重定向会对您有所帮助。 您定义两个入口点就足够了。
- 第一个点
@GetMapping("/wait30second/{emailID}")
,收到请求后休眠30秒,发送302重定向到第二个点...your-site.../images/{emailID}
,例如这样:https://www.baeldung.com/spring-redirect-and-forward - 第二点
@GetMapping("/images/{emailID}")
只是修复了对一个像素的重复访问service.saveTracking(emailID)
没有 30 秒的停顿。 302 重定向由客户端执行。所以,如果没有重复申诉,就说明这封信没有被阅读。
但是,请记住,随着此类监控的大量使用,您的电子邮件被标记为垃圾邮件的风险很高。