Aggiunge il rilevamento di invio e apertura delle email di campagna.
CI / scan_ruby (push) Failing after 12m56s
CI / scan_js (push) Successful in 12m23s
CI / lint (push) Failing after 12m15s

Ogni destinatario mostra se la mail è partita e se è stata aperta, con conteggi in dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-20 12:26:14 +02:00
co-authored by Cursor
parent ab57309f5c
commit 2db7504629
18 changed files with 332 additions and 5 deletions
+36
View File
@@ -0,0 +1,36 @@
module Mailings
class OpenPixel
def self.call(html, recipient)
new(html, recipient).call
end
def initialize(html, recipient)
@html = html.to_s
@recipient = recipient
end
def call
return @html unless trackable?
url = tracking_url
return @html if url.blank?
tag = %(<img src="#{ERB::Util.html_escape(url)}" width="1" height="1" alt="" style="display:block;border:0;width:1px;height:1px;opacity:0;" />)
if @html.match?(/<\/body>/i)
@html.sub(/<\/body>/i, "#{tag}</body>")
else
"#{@html}#{tag}"
end
end
private
def trackable?
@recipient.respond_to?(:tracking_token) && @recipient.tracking_token.present?
end
def tracking_url
Rails.application.routes.url_helpers.mail_open_url(@recipient.tracking_token, **PublicUrl.options)
end
end
end
+24
View File
@@ -0,0 +1,24 @@
module Mailings
module PublicUrl
module_function
def options
opts = Rails.application.config.action_mailer.default_url_options.to_h.symbolize_keys
opts[:protocol] ||= protocol
port = opts[:port].to_i
opts.delete(:port) if port.zero? || default_port?(port)
opts
end
def protocol
return "https" if Rails.application.config.force_ssl
return "https" if ENV["ASSUME_SSL"] == "true"
"http"
end
def default_port?(port)
(protocol == "https" && port == 443) || (protocol == "http" && port == 80)
end
end
end