ahoy_email 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +6 -0
- data/Rakefile +0 -1
- data/ahoy_email.gemspec +4 -4
- data/app/controllers/ahoy/messages_controller.rb +3 -4
- data/lib/ahoy_email.rb +7 -7
- data/lib/ahoy_email/engine.rb +1 -3
- data/lib/ahoy_email/interceptor.rb +0 -2
- data/lib/ahoy_email/mailer.rb +0 -2
- data/lib/ahoy_email/processor.rb +16 -8
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/generators/ahoy_email/install_generator.rb +0 -1
- data/lib/generators/ahoy_email/templates/install.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6c59b97a0029bef3d6070fc62b01b4c6f79b476
|
4
|
+
data.tar.gz: 6cbc7dec76e337280204d5cb420e71a0b20b6a19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346a685b5fc9f4a3e743b845eb1d74faf69993e7a04c01ab01a971d4d7045f621c0699f311603f8b0f7d9704ca834cd6d20ecb249d71b55c93079886a96d7e9e
|
7
|
+
data.tar.gz: 4261c2b50159e022b7ec6875b27cfc37006702385771329446664be6cf17c5ba4ae1c9c7e2869b33b5127b76c81957a069c411b9207fd21072efd2a2123ce0ca
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/ahoy_email.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "ahoy_email/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ahoy_email"
|
8
8
|
spec.version = AhoyEmail::VERSION
|
9
9
|
spec.authors = ["Andrew Kane"]
|
10
10
|
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Simple, powerful email tracking for Rails"
|
12
|
+
spec.description = "Simple, powerful email tracking for Rails"
|
13
13
|
spec.homepage = "https://github.com/ankane/ahoy_email"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -3,7 +3,7 @@ module Ahoy
|
|
3
3
|
before_filter :set_message
|
4
4
|
|
5
5
|
def open
|
6
|
-
if @message
|
6
|
+
if @message && !@message.opened_at
|
7
7
|
@message.opened_at = Time.now
|
8
8
|
@message.save!
|
9
9
|
end
|
@@ -12,12 +12,12 @@ module Ahoy
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def click
|
15
|
-
if @message
|
15
|
+
if @message && !@message.clicked_at
|
16
16
|
@message.clicked_at = Time.now
|
17
17
|
@message.opened_at ||= @message.clicked_at
|
18
18
|
@message.save!
|
19
19
|
end
|
20
|
-
url = params[:url]
|
20
|
+
url = params[:url].to_s
|
21
21
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), AhoyEmail.secret_token, url)
|
22
22
|
publish :click, url: params[:url]
|
23
23
|
if secure_compare(params[:signature], signature)
|
@@ -54,6 +54,5 @@ module Ahoy
|
|
54
54
|
b.each_byte { |byte| res |= byte ^ l.shift }
|
55
55
|
res == 0
|
56
56
|
end
|
57
|
-
|
58
57
|
end
|
59
58
|
end
|
data/lib/ahoy_email.rb
CHANGED
@@ -16,13 +16,14 @@ module AhoyEmail
|
|
16
16
|
open: true,
|
17
17
|
click: true,
|
18
18
|
utm_params: true,
|
19
|
-
utm_source: proc {|message, mailer| mailer.mailer_name },
|
19
|
+
utm_source: proc { |message, mailer| mailer.mailer_name },
|
20
20
|
utm_medium: "email",
|
21
21
|
utm_term: nil,
|
22
22
|
utm_content: nil,
|
23
|
-
utm_campaign: proc {|message, mailer| mailer.action_name },
|
24
|
-
user: proc{|message, mailer| (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
|
25
|
-
mailer: proc{|message, mailer| "#{mailer.class.name}##{mailer.action_name}" }
|
23
|
+
utm_campaign: proc { |message, mailer| mailer.action_name },
|
24
|
+
user: proc { |message, mailer| (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
|
25
|
+
mailer: proc { |message, mailer| "#{mailer.class.name}##{mailer.action_name}" },
|
26
|
+
url_options: {}
|
26
27
|
}
|
27
28
|
|
28
29
|
self.subscribers = []
|
@@ -31,14 +32,13 @@ module AhoyEmail
|
|
31
32
|
self.options = self.options.merge(options)
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
class << self
|
36
|
+
attr_writer :message_model
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.message_model
|
39
40
|
@message_model || Ahoy::Message
|
40
41
|
end
|
41
|
-
|
42
42
|
end
|
43
43
|
|
44
44
|
ActionMailer::Base.send :include, AhoyEmail::Mailer
|
data/lib/ahoy_email/engine.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module AhoyEmail
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
|
4
3
|
initializer "ahoy_email" do |app|
|
5
4
|
secrets = app.respond_to?(:secrets) ? app.secrets : app.config
|
6
|
-
AhoyEmail.secret_token
|
5
|
+
AhoyEmail.secret_token ||= secrets.respond_to?(:secret_key_base) ? secrets.secret_key_base : secrets.secret_token
|
7
6
|
end
|
8
|
-
|
9
7
|
end
|
10
8
|
end
|
data/lib/ahoy_email/mailer.rb
CHANGED
data/lib/ahoy_email/processor.rb
CHANGED
@@ -9,15 +9,18 @@ module AhoyEmail
|
|
9
9
|
|
10
10
|
def process
|
11
11
|
action_name = mailer.action_name.to_sym
|
12
|
-
if options[:message]
|
12
|
+
if options[:message] && (!options[:only] || options[:only].include?(action_name)) && !options[:except].to_a.include?(action_name)
|
13
13
|
@ahoy_message = AhoyEmail.message_model.new
|
14
14
|
ahoy_message.token = generate_token
|
15
15
|
ahoy_message.to = message.to.join(", ") if ahoy_message.respond_to?(:to=)
|
16
16
|
ahoy_message.user = options[:user]
|
17
17
|
|
18
18
|
track_open if options[:open]
|
19
|
-
track_links if options[:utm_params]
|
19
|
+
track_links if options[:utm_params] || options[:click]
|
20
20
|
|
21
|
+
ahoy_message.utm_source = options[:utm_source] if ahoy_message.respond_to?(:utm_source=)
|
22
|
+
ahoy_message.utm_medium = options[:utm_medium] if ahoy_message.respond_to?(:utm_medium=)
|
23
|
+
ahoy_message.utm_campaign = options[:utm_campaign] if ahoy_message.respond_to?(:utm_campaign=)
|
21
24
|
ahoy_message.mailer = options[:mailer] if ahoy_message.respond_to?(:mailer=)
|
22
25
|
ahoy_message.subject = message.subject if ahoy_message.respond_to?(:subject=)
|
23
26
|
ahoy_message.content = message.to_s if ahoy_message.respond_to?(:content=)
|
@@ -92,17 +95,17 @@ module AhoyEmail
|
|
92
95
|
doc = Nokogiri::HTML(body.raw_source)
|
93
96
|
doc.css("a[href]").each do |link|
|
94
97
|
# utm params first
|
95
|
-
if options[:utm_params]
|
98
|
+
if options[:utm_params] && !skip_attribute?(link, "utm-params")
|
96
99
|
uri = Addressable::URI.parse(link["href"])
|
97
100
|
params = uri.query_values || {}
|
98
|
-
%w
|
101
|
+
%w(utm_source utm_medium utm_term utm_content utm_campaign).each do |key|
|
99
102
|
params[key] ||= options[key.to_sym] if options[key.to_sym]
|
100
103
|
end
|
101
104
|
uri.query_values = params
|
102
105
|
link["href"] = uri.to_s
|
103
106
|
end
|
104
107
|
|
105
|
-
if options[:click]
|
108
|
+
if options[:click] && !skip_attribute?(link, "click")
|
106
109
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), AhoyEmail.secret_token, link["href"])
|
107
110
|
link["href"] =
|
108
111
|
url_for(
|
@@ -133,13 +136,19 @@ module AhoyEmail
|
|
133
136
|
elsif link["href"].to_s =~ /unsubscribe/i
|
134
137
|
# try to avoid unsubscribe links
|
135
138
|
true
|
139
|
+
elsif link["href"].to_s.start_with?("mailto:")
|
140
|
+
# mailto's shouldn't go through a redirect
|
141
|
+
true
|
136
142
|
else
|
137
143
|
false
|
138
144
|
end
|
139
145
|
end
|
140
146
|
|
141
|
-
def url_for(
|
142
|
-
|
147
|
+
def url_for(opt)
|
148
|
+
opt = (ActionMailer::Base.default_url_options || {})
|
149
|
+
.merge(options[:url_options])
|
150
|
+
.merge(opt)
|
151
|
+
AhoyEmail::Engine.routes.url_helpers.url_for(opt)
|
143
152
|
end
|
144
153
|
|
145
154
|
# not a fan of quiet errors
|
@@ -152,6 +161,5 @@ module AhoyEmail
|
|
152
161
|
raise e
|
153
162
|
end
|
154
163
|
end
|
155
|
-
|
156
164
|
end
|
157
165
|
end
|
data/lib/ahoy_email/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahoy_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.4.5
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Simple, powerful email tracking for Rails
|