First-party email analytics for Rails
First-party email analytics for Rails
Ahoy Email 4.0 was recently released - see how to upgrade
:fire: For web and native app analytics, check out Ahoy
:bullettrain_side: To manage email subscriptions, check out Mailkick
Add this line to your application’s Gemfile:
gem "ahoy_email"There are three main features, which can be used independently:
To encrypt email addresses with Lockbox, install Lockbox and Blind Index and run:
rails generate ahoy:messages --encryption=lockbox
rails db:migrateTo use Active Record encryption, run:
rails generate ahoy:messages --encryption=activerecord
rails db:migrateIf you prefer not to encrypt data, run:
rails generate ahoy:messages --encryption=none
rails db:migrateThen, add to mailers:
class CouponMailer { params[:some_user] }
endThe user association is polymorphic, so use it with any model.
To get all messages sent to a user, add an association:
class User { {coupon_id: params[:coupon].id} }
endSet global options
AhoyEmail.default_options[:user] = -> { params[:admin] }Use a different model
AhoyEmail.message_model = -> { UserMessage }Or fully customize how messages are tracked
AhoyEmail.track_method = lambda do |data|
# your code
endDelete older data with:
Ahoy::Message.where("sent_at { "coupon#{params[:coupon].id}" }
endUse only and except to limit actions
class CouponMailer You can track click-through rate to see how well campaigns are performing. Stats can be stored in your database, Redis, or any other data store.
Run:
rails generate ahoy:clicks
rails db:migrateAnd create config/initializers/ahoy_email.rb with:
AhoyEmail.subscribers { params[:user].opted_in? }
endYou can also use a proc
class CouponMailer { "coupon-#{action_name}" }
endSkip specific links with:
By default, unsubscribe links are excluded. To change this, use:
AhoyEmail.default_options[:unsubscribe_links] = trueYou can specify the domain to use with:
AhoyEmail.default_options[:url_options] = {host: "mydomain.com"}Get stats for a campaign
AhoyEmail.stats("my-campaign")Versions 2.3.0-3.0.0 cause applications to use SHA1 for the key generator hash digest class (due to this behavior in Rails). To avoid breakage when upgrading, add to config/application.rb:
config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
To get started with development:
git clone https://github.com/ankane/ahoy_email.git
cd ahoy_email
bundle install
bundle exec rake testNo open issues yet, or sync has not completed.