{"id":13542439,"url":"https://github.com/ankane/ahoy_email","last_synced_at":"2025-11-17T14:03:22.976Z","repository":{"id":16479477,"uuid":"19231848","full_name":"ankane/ahoy_email","owner":"ankane","description":"First-party email analytics for Rails","archived":false,"fork":false,"pushed_at":"2025-10-24T02:35:17.000Z","size":361,"stargazers_count":1170,"open_issues_count":1,"forks_count":141,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-11-13T21:08:08.348Z","etag":null,"topics":["analytics","first-party-analytics","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":"Unmaintained","scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-04-28T08:25:42.000Z","updated_at":"2025-11-10T05:52:13.000Z","dependencies_parsed_at":"2023-02-13T20:17:12.494Z","dependency_job_id":"40d45cc2-0d4c-4f2b-b9eb-76bc26a60e54","html_url":"https://github.com/ankane/ahoy_email","commit_stats":{"total_commits":467,"total_committers":32,"mean_commits":14.59375,"dds":"0.10064239828693788","last_synced_commit":"3c3379b9be9ce7871a8b401068d1c225bb55b206"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/ahoy_email","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fahoy_email","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fahoy_email/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fahoy_email/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fahoy_email/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/ahoy_email/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fahoy_email/sbom","scorecard":{"id":197138,"data":{"date":"2025-08-11","repo":{"name":"github.com/ankane/ahoy_email","commit":"1871bc866d46c7369e4d24ab28e55b8aa767609f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"12 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/ahoy_email/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/ahoy_email/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/ahoy_email/build.yml/master?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T22:00:59.402Z","repository_id":16479477,"created_at":"2025-08-16T22:00:59.402Z","updated_at":"2025-08-16T22:00:59.402Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284507668,"owners_count":27017332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-15T02:00:06.050Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","first-party-analytics","rails"],"created_at":"2024-08-01T10:01:07.728Z","updated_at":"2025-11-17T14:03:22.971Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby","Analytics","rails","Email","Gems"],"sub_categories":["Articles"],"readme":"# Ahoy Email\n\nFirst-party email analytics for Rails\n\n**Ahoy Email 3.0 was recently released** - see [how to upgrade](#upgrading)\n\n:fire: For web and native app analytics, check out [Ahoy](https://github.com/ankane/ahoy)\n\n:bullettrain_side: To manage email subscriptions, check out [Mailkick](https://github.com/ankane/mailkick)\n\n[![Build Status](https://github.com/ankane/ahoy_email/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/ahoy_email/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"ahoy_email\"\n```\n\n## Getting Started\n\nThere are three main features, which can be used independently:\n\n- [Message history](#message-history)\n- [UTM tagging](#utm-tagging)\n- [Click analytics](#click-analytics)\n\n## Message History\n\nTo encrypt email addresses with Lockbox, install [Lockbox](https://github.com/ankane/lockbox) and [Blind Index](https://github.com/ankane/blind_index) and run:\n\n```sh\nrails generate ahoy:messages --encryption=lockbox\nrails db:migrate\n```\n\nTo use Active Record encryption, run:\n\n```sh\nrails generate ahoy:messages --encryption=activerecord\nrails db:migrate\n```\n\nIf you prefer not to encrypt data, run:\n\n```sh\nrails generate ahoy:messages --encryption=none\nrails db:migrate\n```\n\nThen, add to mailers:\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  has_history\nend\n```\n\nUse the `Ahoy::Message` model to query messages:\n\n```ruby\nAhoy::Message.last\n```\n\nUse only and except to limit actions\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  has_history only: [:welcome]\nend\n```\n\nTo store history for all mailers, create `config/initializers/ahoy_email.rb` with:\n\n```ruby\nAhoyEmail.default_options[:message] = true\n```\n\n### Users\n\nBy default, Ahoy Email tries `@user` then `params[:user]` then `User.find_by(email: message.to)` to find the user. You can pass a specific user with:\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  has_history user: -\u003e { params[:some_user] }\nend\n```\n\nThe user association is [polymorphic](https://railscasts.com/episodes/154-polymorphic-association), so use it with any model.\n\nTo get all messages sent to a user, add an association:\n\n```ruby\nclass User \u003c ApplicationRecord\n  has_many :messages, class_name: \"Ahoy::Message\", as: :user\nend\n```\n\nAnd run:\n\n```ruby\nuser.messages\n```\n\n### Extra Data\n\nAdd extra data to messages. Create a migration like:\n\n```ruby\nclass AddCouponIdToAhoyMessages \u003c ActiveRecord::Migration[8.1]\n  def change\n    add_column :ahoy_messages, :coupon_id, :integer\n  end\nend\n```\n\nAnd use:\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  has_history extra: {coupon_id: 1}\nend\n```\n\nYou can use a proc as well.\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  has_history extra: -\u003e { {coupon_id: params[:coupon].id} }\nend\n```\n\n### Options\n\nSet global options\n\n```ruby\nAhoyEmail.default_options[:user] = -\u003e { params[:admin] }\n```\n\nUse a different model\n\n```ruby\nAhoyEmail.message_model = -\u003e { UserMessage }\n```\n\nOr fully customize how messages are tracked\n\n```ruby\nAhoyEmail.track_method = lambda do |data|\n  # your code\nend\n```\n\n### Data Retention\n\nDelete older data with:\n\n```ruby\nAhoy::Message.where(\"sent_at \u003c ?\", 1.year.ago).in_batches.delete_all\n```\n\nDelete data for a specific user with:\n\n```ruby\nAhoy::Message.where(user_id: 1, user_type: \"User\").in_batches.delete_all\n```\n\n## UTM Tagging\n\nUse UTM tagging to attribute visits or conversions to an email campaign. Add UTM parameters to links with:\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  utm_params\nend\n```\n\nThe defaults are:\n\n- `utm_medium` - `email`\n- `utm_source` - the mailer name like `coupon_mailer`\n- `utm_campaign` - the mailer action like `offer`\n\nYou can customize them with:\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  utm_params utm_campaign: -\u003e { \"coupon#{params[:coupon].id}\" }\nend\n```\n\nUse only and except to limit actions\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  utm_params only: [:welcome]\nend\n```\n\nSkip specific links with:\n\n```erb\n\u003c%= link_to \"Go\", some_url, data: {skip_utm_params: true} %\u003e\n```\n\n## Click Analytics\n\nYou 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.\n\n#### Database\n\nRun:\n\n```sh\nrails generate ahoy:clicks\nrails db:migrate\n```\n\nAnd create `config/initializers/ahoy_email.rb` with:\n\n```ruby\nAhoyEmail.subscribers \u003c\u003c AhoyEmail::DatabaseSubscriber\nAhoyEmail.api = true\n```\n\n#### Redis\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"redis\"\n```\n\nAnd create `config/initializers/ahoy_email.rb` with:\n\n```ruby\n# pass your Redis client if you already have one\nAhoyEmail.subscribers \u003c\u003c AhoyEmail::RedisSubscriber.new(redis: Redis.new)\nAhoyEmail.api = true\n```\n\n#### Other\n\nCreate `config/initializers/ahoy_email.rb` with:\n\n```ruby\nclass EmailSubscriber\n  def track_send(data)\n    # your code\n  end\n\n  def track_click(data)\n    # your code\n  end\n\n  def stats(campaign)\n    # optional, for AhoyEmail.stats\n  end\nend\n\nAhoyEmail.subscribers \u003c\u003c EmailSubscriber\nAhoyEmail.api = true\n````\n\n### Usage\n\nAdd to mailers you want to track\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  track_clicks campaign: \"my-campaign\"\nend\n```\n\nIf storing stats in the database, the mailer should also use `has_history`\n\nUse only and except to limit actions\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  track_clicks campaign: \"my-campaign\", only: [:welcome]\nend\n```\n\nOr make it conditional\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  track_clicks campaign: \"my-campaign\", if: -\u003e { params[:user].opted_in? }\nend\n```\n\nYou can also use a proc\n\n```ruby\nclass CouponMailer \u003c ApplicationMailer\n  track_clicks campaign: -\u003e { \"coupon-#{action_name}\" }\nend\n```\n\nSkip specific links with:\n\n```erb\n\u003c%= link_to \"Go\", some_url, data: {skip_click: true} %\u003e\n```\n\nBy default, unsubscribe links are excluded. To change this, use:\n\n```ruby\nAhoyEmail.default_options[:unsubscribe_links] = true\n```\n\nYou can specify the domain to use with:\n\n```ruby\nAhoyEmail.default_options[:url_options] = {host: \"mydomain.com\"}\n```\n\n### Stats\n\nGet stats for a campaign\n\n```ruby\nAhoyEmail.stats(\"my-campaign\")\n```\n\n## Upgrading\n\n### 3.0\n\nLinks that use click analytics created before version 2.3.0 (released June 2024) will no longer work by default. To restore support, [determine the previous secret token](https://github.com/ankane/ahoy_email/blob/v2.5.0/lib/ahoy_email/engine.rb#L11-L21) and create an initializer with:\n\n```ruby\nAhoyEmail.secret_token = [AhoyEmail.secret_token, previous_secret_token]\n```\n\nAlso, Nokogiri’s HTML5 parser is now used to rewrite links for UTM tagging and click analytics when available. To use HTML4 parsing, create an initializer with:\n\n```ruby\nAhoyEmail.default_options[:html5] = false\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/ahoy_email/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/ahoy_email/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/ahoy_email/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/ahoy_email.git\ncd ahoy_email\nbundle install\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fahoy_email","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fahoy_email","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fahoy_email/lists"}