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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 578ee3a9017fb411299f65ca92e63d99f62ba5c9
4
- data.tar.gz: 4ac755f40d9b70edd52996057b0b090bb0187e16
3
+ metadata.gz: d6c59b97a0029bef3d6070fc62b01b4c6f79b476
4
+ data.tar.gz: 6cbc7dec76e337280204d5cb420e71a0b20b6a19
5
5
  SHA512:
6
- metadata.gz: 12e9c5ff140a53e27945b82dff0f8175b452332b03d1fdf3745dc5039dc183c234f74463a5ec05f52ad50373f989b852eb640346ad57205fd75d966f9299854f
7
- data.tar.gz: 2294b76fdd392c8fdd5472682db14aa7bc8bed7ad8bf017ab688ef5752b8fd22830daf185f2fb642253eb8f3763f892314ca88a99badd9381bad0cca69cac8a5
6
+ metadata.gz: 346a685b5fc9f4a3e743b845eb1d74faf69993e7a04c01ab01a971d4d7045f621c0699f311603f8b0f7d9704ca834cd6d20ecb249d71b55c93079886a96d7e9e
7
+ data.tar.gz: 4261c2b50159e022b7ec6875b27cfc37006702385771329446664be6cf17c5ba4ae1c9c7e2869b33b5127b76c81957a069c411b9207fd21072efd2a2123ce0ca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.2.3
2
+
3
+ - Save utm parameters
4
+ - Added `url_options`
5
+ - Skip tracking for `mailto` links
6
+ - Only set secret token if not already set
7
+
1
8
  ## 0.2.2
2
9
 
3
10
  - Fixed secret token for Rails 4.1
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ahoy_email.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -206,6 +206,12 @@ Or by default
206
206
  AhoyEmail.track message: false
207
207
  ```
208
208
 
209
+ Customize domain
210
+
211
+ ```ruby
212
+ track url_options: {host: "mydomain.com"}
213
+ ```
214
+
209
215
  Use a different model
210
216
 
211
217
  ```ruby
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
1
  require "bundler/gem_tasks"
2
-
data/ahoy_email.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ahoy_email/version'
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 = %q{Simple, powerful email tracking for Rails}
12
- spec.description = %q{Simple, powerful email tracking for Rails}
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 and !@message.opened_at
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 and !@message.clicked_at
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
- def self.message_model=(message_model)
35
- @message_model = message_model
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
@@ -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 = secrets.respond_to?(:secret_key_base) ? secrets.secret_key_base : secrets.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
@@ -1,11 +1,9 @@
1
1
  module AhoyEmail
2
2
  class Interceptor
3
3
  class << self
4
-
5
4
  def delivering_email(message)
6
5
  AhoyEmail::Processor.new(message).track_send
7
6
  end
8
-
9
7
  end
10
8
  end
11
9
  end
@@ -1,6 +1,5 @@
1
1
  module AhoyEmail
2
2
  module Mailer
3
-
4
3
  def self.included(base)
5
4
  base.extend ClassMethods
6
5
  base.class_eval do
@@ -26,6 +25,5 @@ module AhoyEmail
26
25
  AhoyEmail::Processor.new(message, self).process
27
26
  message
28
27
  end
29
-
30
28
  end
31
29
  end
@@ -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] and (!options[:only] or options[:only].include?(action_name)) and !options[:except].to_a.include?(action_name)
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] or options[:click]
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] and !skip_attribute?(link, "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[utm_source utm_medium utm_term utm_content utm_campaign].each do |key|
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] and !skip_attribute?(link, "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(options)
142
- AhoyEmail::Engine.routes.url_helpers.url_for((ActionMailer::Base.default_url_options || {}).merge(options))
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
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -24,7 +24,6 @@ module AhoyEmail
24
24
  def copy_migration
25
25
  migration_template "install.rb", "db/migrate/create_ahoy_messages.rb"
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
  end
@@ -13,6 +13,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration
13
13
  t.string :mailer
14
14
  t.text :subject
15
15
  t.text :content
16
+ t.string :utm_source
17
+ t.string :utm_medium
18
+ t.string :utm_campaign
16
19
 
17
20
  # timestamps
18
21
  t.timestamp :sent_at
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.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: 2014-08-31 00:00:00.000000000 Z
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.2.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