Ogni destinatario mostra se la mail è partita e se è stata aperta, con conteggi in dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
726 B
Ruby
25 lines
726 B
Ruby
require "base64"
|
|
|
|
class MailOpensController < ActionController::Base
|
|
PIXEL = Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==").freeze
|
|
|
|
def show
|
|
record_open
|
|
expires_now
|
|
response.set_header("Cache-Control", "no-store, no-cache, must-revalidate, private, max-age=0")
|
|
response.set_header("Pragma", "no-cache")
|
|
send_data PIXEL, type: "image/gif", disposition: "inline", filename: "o.gif"
|
|
end
|
|
|
|
private
|
|
|
|
def record_open
|
|
token = params[:token].to_s
|
|
recipient = MailingRecipient.find_by(tracking_token: token)
|
|
recipient&.record_open!
|
|
rescue StandardError => e
|
|
Rails.logger.warn("[mail_open] #{e.class}: #{e.message}")
|
|
raise if Rails.env.test?
|
|
end
|
|
end
|