Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ahoy_email

> 后端框架
Open source

First-party email analytics for Rails

1.2K stars0 likes2 views
WebsiteGitHub

About

First-party email analytics for Rails

Ahoy Email

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

Installation

Add this line to your application’s Gemfile:

ruby
gem "ahoy_email"

Getting Started

There are three main features, which can be used independently:

  • Message history
  • UTM tagging
  • Click analytics

Message History

To encrypt email addresses with Lockbox, install Lockbox and Blind Index and run:

bash
rails generate ahoy:messages --encryption=lockbox
rails db:migrate

To use Active Record encryption, run:

bash
rails generate ahoy:messages --encryption=activerecord
rails db:migrate

If you prefer not to encrypt data, run:

bash
rails generate ahoy:messages --encryption=none
rails db:migrate

Then, add to mailers:

ruby
class CouponMailer  { params[:some_user] }
end

The user association is polymorphic, so use it with any model.

To get all messages sent to a user, add an association:

ruby
class User  { {coupon_id: params[:coupon].id} }
end

Options

Set global options

ruby
AhoyEmail.default_options[:user] = -> { params[:admin] }

Use a different model

ruby
AhoyEmail.message_model = -> { UserMessage }

Or fully customize how messages are tracked

ruby
AhoyEmail.track_method = lambda do |data|
  # your code
end

Data Retention

Delete older data with:

ruby
Ahoy::Message.where("sent_at  { "coupon#{params[:coupon].id}" }
end

Use only and except to limit actions

ruby
class CouponMailer 

Click Analytics

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.

Database

Run:

bash
rails generate ahoy:clicks
rails db:migrate

And create config/initializers/ahoy_email.rb with:

ruby
AhoyEmail.subscribers  { params[:user].opted_in? }
end

You can also use a proc

ruby
class CouponMailer  { "coupon-#{action_name}" }
end

Skip specific links with:

erb

By default, unsubscribe links are excluded. To change this, use:

ruby
AhoyEmail.default_options[:unsubscribe_links] = true

You can specify the domain to use with:

ruby
AhoyEmail.default_options[:url_options] = {host: "mydomain.com"}

Stats

Get stats for a campaign

ruby
AhoyEmail.stats("my-campaign")

Upgrading

4.0

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:

ruby
config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

bash
git clone https://github.com/ankane/ahoy_email.git
cd ahoy_email
bundle install
bundle exec rake test

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyanalyticsfirst-party-analyticsrails

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架