ponch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +7 -0
- data/TODO.md +3 -0
- data/app/controllers/ponch/tracking_controller.rb +12 -0
- data/app/models/ponch/delivery.rb +40 -0
- data/config/routes.rb +6 -0
- data/images/blank.gif +0 -0
- data/lib/generators/ponch/deliveries_generator.rb +29 -0
- data/lib/generators/ponch/templates/create_deliveries.rb +25 -0
- data/lib/ponch.rb +15 -0
- data/lib/ponch/config.rb +11 -0
- data/lib/ponch/engine.rb +20 -0
- data/lib/ponch/interceptor.rb +25 -0
- data/lib/ponch/version.rb +3 -0
- data/ponch.gemspec +20 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Ponch
|
2
|
+
|
3
|
+
Simple email analytics for your Rails app
|
4
|
+
|
5
|
+
## Information
|
6
|
+
|
7
|
+
**Ponch** lets you track opened emails if you're using your own sendmail server or Amazon SES.
|
8
|
+
|
9
|
+
Only works on Rails 3.x
|
10
|
+
|
11
|
+
It works by inserting an 1x1 tracking gif on your html emails and adding a controller that handles the request to that image.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Simply add in your Gemfile
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
gem 'ponch'
|
19
|
+
```
|
20
|
+
|
21
|
+
and then set in your config/environment.rb (or in each environment file) the details for
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
config.ponch.url_options = {host: "localhost", port: 3000}
|
25
|
+
```
|
26
|
+
|
27
|
+
And then Ponch takes care of the rest for you!
|
28
|
+
|
29
|
+
## Patches/Pull Requests
|
30
|
+
|
31
|
+
* Fork the project.
|
32
|
+
* Make your feature addition or bug fix.
|
33
|
+
* Add tests for it. This is important so I don't break it in a
|
34
|
+
future version unintentionally.
|
35
|
+
* Commit, do not mess with Rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but
|
37
|
+
bump version in a commit by itself I can ignore when I pull)
|
38
|
+
* Send me a pull request. Bonus points for topic branches.
|
39
|
+
|
40
|
+
## Licence
|
41
|
+
|
42
|
+
Ponch is released under the MIT license.
|
data/Rakefile
ADDED
data/TODO.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class Ponch::TrackingController < ActionController::Base
|
2
|
+
|
3
|
+
def pixel
|
4
|
+
ponch_delivery = Ponch::Delivery.find_by_code params[:code]
|
5
|
+
|
6
|
+
ponch_delivery.open!(request.remote_ip) if ponch_delivery
|
7
|
+
|
8
|
+
send_file File.expand_path('../../../../images/blank.gif', __FILE__),
|
9
|
+
type: "image/gif", disposition: 'inline', stream: false
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ponch
|
2
|
+
class Delivery < ActiveRecord::Base
|
3
|
+
set_table_name :ponch_deliveries
|
4
|
+
|
5
|
+
validates_presence_of :to, :from, :sent_at
|
6
|
+
|
7
|
+
scope :opened, where("opened_at is not null")
|
8
|
+
|
9
|
+
before_create :generate_code
|
10
|
+
|
11
|
+
def opened?
|
12
|
+
!opened_at.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def open!(ip_address = nil)
|
16
|
+
unless opened?
|
17
|
+
self.opened_at = Time.now
|
18
|
+
self.opened_ip = ip_address
|
19
|
+
self.save!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#class methods
|
24
|
+
def self.create_from_mail(mail)
|
25
|
+
self.create! to: mail.to.first,
|
26
|
+
from: mail.from.first,
|
27
|
+
subject: mail.subject,
|
28
|
+
sent_at: Time.now
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def generate_code
|
33
|
+
self.code = loop do
|
34
|
+
code_attempt = SecureRandom.hex(20)
|
35
|
+
break code_attempt unless self.class.find_by_code(code_attempt)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/config/routes.rb
ADDED
data/images/blank.gif
ADDED
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require "rails/generators/migration"
|
3
|
+
|
4
|
+
module Ponch
|
5
|
+
module Generators
|
6
|
+
|
7
|
+
class DeliveriesGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
desc "Creates a base migration for Ponch::Delivery model"
|
11
|
+
|
12
|
+
source_root File.expand_path('../templates', __FILE__)
|
13
|
+
|
14
|
+
def copy_files
|
15
|
+
migration_template('create_deliveries.rb', 'db/migrate/create_ponch_deliveries.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.next_migration_number(dirname) #:nodoc:
|
19
|
+
if ActiveRecord::Base.timestamped_migrations
|
20
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
21
|
+
else
|
22
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class CreatePonchDeliveries < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :ponch_deliveries do |t|
|
5
|
+
t.string :to, :null => false
|
6
|
+
t.string :from, :null => false
|
7
|
+
t.string :subject
|
8
|
+
|
9
|
+
t.string :code, :null => false
|
10
|
+
t.datetime :sent_at, :null => false
|
11
|
+
|
12
|
+
t.datetime :opened_at
|
13
|
+
t.string :opened_ip
|
14
|
+
|
15
|
+
t.datetime :clicked_at
|
16
|
+
t.string :clicked_ip
|
17
|
+
end
|
18
|
+
add_index :ponch_deliveries, :code, unique: true
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.down
|
22
|
+
drop_table :ponch_deliveries
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/ponch.rb
ADDED
data/lib/ponch/config.rb
ADDED
data/lib/ponch/engine.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ponch/interceptor'
|
2
|
+
|
3
|
+
module Ponch
|
4
|
+
class Engine < ::Rails::Engine#:nodoc:
|
5
|
+
|
6
|
+
config.ponch = ActiveSupport::OrderedOptions.new
|
7
|
+
|
8
|
+
config.to_prepare do
|
9
|
+
Ponch::Engine.config.ponch.each do |key, value|
|
10
|
+
Ponch.config.send "#{key}=".to_sym, value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#action mailer register_interceptor
|
15
|
+
ActiveSupport.on_load(:action_mailer) do
|
16
|
+
ActionMailer::Base.register_interceptor(Interceptor)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Ponch
|
4
|
+
class Interceptor
|
5
|
+
|
6
|
+
def self.delivering_email(message)
|
7
|
+
if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message))
|
8
|
+
delivery = Ponch::Delivery.create_from_mail message
|
9
|
+
|
10
|
+
message_body = html_part.body.to_s
|
11
|
+
|
12
|
+
html_doc = Nokogiri::HTML(message_body)
|
13
|
+
|
14
|
+
pixel_url = Rails.application.routes.url_helpers.ponch_pixel_url(delivery.code, Ponch.config.url_options)
|
15
|
+
tracking_pixel = "<img src=\"#{pixel_url}\" />"
|
16
|
+
html_doc.at("body").add_child(tracking_pixel)
|
17
|
+
|
18
|
+
#set the HTML part with tracking pixel at the end
|
19
|
+
html_part.body = html_doc.to_s
|
20
|
+
end
|
21
|
+
message
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/ponch.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ponch/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Esteban Pastorino"]
|
6
|
+
gem.email = ["ejpastorino@gmail.com"]
|
7
|
+
gem.description = "Ponch lets you track opened emails if you're using your own sendmail server or Amazon SES. Only works on Rails 3.x. It works by inserting an 1x1 tracking gif on your html emails and adding a controller that handles the request to that image."
|
8
|
+
gem.summary = "Simple email analytics for your Rails app"
|
9
|
+
gem.homepage = "https://github.com/kitop/ponch"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "ponch"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Ponch::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'railties', ['>= 3.0.0']
|
19
|
+
gem.add_dependency 'nokogiri', ['>= 1.4.7']
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ponch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Esteban Pastorino
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &19667820 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *19667820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
requirement: &19683660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.7
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *19683660
|
36
|
+
description: Ponch lets you track opened emails if you're using your own sendmail
|
37
|
+
server or Amazon SES. Only works on Rails 3.x. It works by inserting an 1x1 tracking
|
38
|
+
gif on your html emails and adding a controller that handles the request to that
|
39
|
+
image.
|
40
|
+
email:
|
41
|
+
- ejpastorino@gmail.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- TODO.md
|
52
|
+
- app/controllers/ponch/tracking_controller.rb
|
53
|
+
- app/models/ponch/delivery.rb
|
54
|
+
- config/routes.rb
|
55
|
+
- images/blank.gif
|
56
|
+
- lib/generators/ponch/deliveries_generator.rb
|
57
|
+
- lib/generators/ponch/templates/create_deliveries.rb
|
58
|
+
- lib/ponch.rb
|
59
|
+
- lib/ponch/config.rb
|
60
|
+
- lib/ponch/engine.rb
|
61
|
+
- lib/ponch/interceptor.rb
|
62
|
+
- lib/ponch/version.rb
|
63
|
+
- ponch.gemspec
|
64
|
+
homepage: https://github.com/kitop/ponch
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.10
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Simple email analytics for your Rails app
|
88
|
+
test_files: []
|