ankane / ahoy_email

First-party email analytics for Rails
MIT License
1.11k stars 137 forks source link

User model is available but not set in Ahoy::Message #135

Closed mike1011 closed 5 years ago

mike1011 commented 5 years ago

I am re-posting this issue, after I didn't got any help from stackoverflow here

I have successfully setup Ahoy Email and works just great and tracks my visits, opens and clicks easily.

The only place where I am having a trouble is to set the user data in my Ahoy::Message model. I debugged and can also see my attributes user_id and user_type are easily set but not inserted in the db.

I debugged in initializers/ahoy_email.rb

 AhoyEmail.track_method = lambda do |data|
   Rails.logger.info " =======TRACK AHOY EMAILS=============== "
   Rails.logger.info data
 end

=====debug value=====with user_id and user_type along with user object and devise attributes
==== other data is removed for more clarity
{:mailer=>"BusinessMailer#notify_about_new_message", :extra=>{}, :user=>#<User id: 145, email: "user_1542307802tbzyjlbl@gmail.com",xxxxxxxxx all devise specific attributes..>, :user_type=>"User", :user_id=>145, :token=>"cccxxxxxxxxxxxtokenxxxxxxxxx", :message=>#<Mail::XXXXXXXXXXX}

As you can see from the above, i am getting the user but its not set in the actual insert query shown below.

 ##where is the user data?####
 SQL (3.3ms)  INSERT INTO "ahoy_messages" ("to", "mailer", "subject", "token", "sent_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["to", "USER_1542307802TBZYJLBL@gmail.com"], ["mailer", "BusinessMailer#notify_about_new_message"], ["subject", "New Messagexxxxx"], ["token", "CEls3LuSU5ohnmzoXQTkTbqbWPt3IlJF"], ["sent_at", "2019-04-11 00:40:55.846351"]]

I also tried adding @user in my mailer.rb file, but still the same

 track user: -> { @user }

  def send_email_testing user_id
  @user = User.find user_id
  ####send email ......removed for clarity

Will appreciate if someone can put some light here :)

Thanks in advance.

ankane commented 5 years ago

Hey @mike1011, unfortunately, I have limited bandwidth for app-specific issues, so Stack Overflow is still your best bet.

mike1011 commented 5 years ago

Thanks @ankane for your reply. However, Is there anything helpful that you can guide me or share your opinion, as the above issue is self-descriptive.

Thanks in advance.

ankane commented 5 years ago

@mike1011 My general advice is to fork the gem and add log statements to get a better understanding of what's going on.

mike1011 commented 5 years ago

Thanks for getting in touch again. I will update this issue, in case I fix it.