开发者

Email open notification - ruby on rails

If I will send 100 email to the registered user and I want to know if users open email o开发者_运维技巧r not

How can I do this using Ruby on Rails?


The only way to do this, is to use html email with a tracker image. You need to include a user specific image into the code.

class TrackingController < ApplicationController
  def image
    # do something with params[:id]
    send_file "/path/to/an/image"
  end
end

add the following route:

# Rails 2
map.tracking_image "tracking_image/:id.gif", :controller => 'tracking', :action => image

# Rails 3
match 'products/:id', :to => 'tracking#image', :as => "tracking_image"

# Rails 4 (match without verb is deprecated)
get 'producsts/:id' => 'tracking#image', as: 'tracking_image'
# or
match 'producsts/:id' => 'tracking#image', as: 'tracking_image', via: :get

in your email template something like this:

<%= image_tag tracking_image_url(@user.id) %>

But be aware, that this it's not guaranteed that the user reads the email and loads the image, some email clients don't load images, until the user wants to. And If he doesn't you can't do anything about this. Also if the user uses text mail only this won't work neither.


Short answer, You can't. Slightly longer answer You can't reliably.

Using something like VERP you can automate the the bounce processing, to get a fairly good idea if the far end mail server accepted the email. But after that all bets are off. You can't really tell what the email server did with it, (route it to junk/spam folder, put in inbox, silently drop it on the floor/bit bucket, etc..). You could enable read-receipt headers in your email, but that is client specific (and people like me eat/deny them). You can look into using a web bug, for example customize each email with an HTML file, that pulls a remote image, that has a unique id associated with it, but again client specific, most will not load remote images. So unless the email bounces there is no 100% reliable way to tell what happens to the email after it leaves your server.


I am not very familiar with ruby but have written multiple mass mailer apps. You can use a webbug image to get an approximate open rate. Basically it is just a one pixel or transparent image with some tracking information:

<img src="http://mysite/trackingimage.gif?email=x&customer=y">

What I do is make a directory called trackingimage.gif with an index in it that reads and stores the url params and then relocates to the real image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜