Search code examples
ruby-on-railsrubyemailrubygemsahoy

Rails ahoy_email gem url broken sometimes


For my work, I was using ahoy_email gem to help analysis email status. It works fine and very helpful.

But sometime the url link were not successful redirect to correct url address.

For example:

Suppose my email has a link, google homepage url:

https://www.google.com

When I sent the mail, it packaged the link which in the email template by ahoy message gem, it looks like:

https://mail-center.mycompany.com/ahoy/messages/4Kwe4f3xsie1u70ybsYYUc8l3klW1v10/click?signature=5047051b3f2730e64af700b6acecee42ad4cc086&url=https://www.google.com

mail-center.mycompany.com is my server site, and this link suppose to go through to my mail server and redirect to google homepage when user clicked the link.

But very very rare, the link was broken. It did not redirect to the google homepage but to the https://mail-center.mycompany.com homepage.

It is hard to reproduced the situation, others email looks fine..

How could I fix or check the problem?

My rails project:

  • Ruby 2.5.1
  • rails 5.2.1
  • ahoy_email gem 1.0.2

Solution

  • I am facing the exact same problem and honestly now fed up. The only thing i can point you to is: This probably happens when -

    • The url you send, ex: google.com had some url encoding needed. Like: https://www.google.com?click=true&dummy_param=true

    • Ahoy expects the exact url to be returned in url part of the link

      ...&url=https%3A%2F%2Fwww.google.com%3Fclick%3Dtrue%26dummy_param%3Dtrue

    • But when the acutal url is clicked from mail, it is not EXACTLY same as what you sent earlier

      ...&url=https%3A%2F%2Fwww.google.com%3Fclick%3Dtrue&dummy_param=true

    • On decoding the whole call, url becomes different.

    On checking multiple times, correct url is being generated by Ahoy but for some reason (randomly/rarely), this is happening

    I hope it makes sense about what may be causing the issue.