ahoy_email 2.3.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 238e4d5f6eb74588ea6d9d628cce5b7c69fa584741280c9d766fa13c5ef8164a
4
- data.tar.gz: 3dedf13c78c400d139bb9450fc01ceb1a56c844b463ff0cafdf12fc7f6553573
3
+ metadata.gz: aa1850e7d07ec2fe43003f8e6c2046a10bd8229c6e5e8d12849cc8a2d819f670
4
+ data.tar.gz: 4eefd3654e671eb6c65b064025d9ea5c7dd7810d73f12bbc8b34cafb2e5e00f4
5
5
  SHA512:
6
- metadata.gz: 4cc75f90c29e23f1c4dc5e87cfa626cbff9a6a0f3c23850f5813bb3890f1afbc72912e94bc8fb5f15f87c0f32794c7031f5559d0255d52065412e73dba793985
7
- data.tar.gz: 559b2bec029c2d659c10799ff38453b939ff615f84a7a4041670badf3b96c8faa91d9f6037f9147d0003422197bdc430ddd2e075f391391c01905cb522abc2f6
6
+ metadata.gz: 0e021685e661cbb627a5d95fde8dfccbc0630398a391eea319d64ce268f3219918a6442a23f1ed9a2a06b69761a97f09aa8cb2a633e282affc200e4ac45b7d7b
7
+ data.tar.gz: 104b6dfebf8f9d3bb3381e09b972708f539122ff2ca062cfc0aaf5a5af529661e06c196dfa35e862a8709b2ede56af3dcf13af9ee1bb15552ce036323ced9f39
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 2.5.0 (2025-05-04)
2
+
3
+ - Removed support for Ruby < 3.2 and Rails < 7.1
4
+
5
+ ## 2.4.0 (2024-11-11)
6
+
7
+ - Added `html5` option
8
+ - Improved generator for Active Record encryption and MySQL
9
+ - Removed support for Ruby < 3.1 and Rails < 7
10
+ - Removed support for Mongoid < 8
11
+
1
12
  ## 2.3.1 (2024-09-09)
2
13
 
3
14
  - Fixed deprecation warning with Rails 7.1
@@ -180,4 +191,14 @@ Breaking changes
180
191
 
181
192
  ## 0.1.0 (2014-04-29)
182
193
 
183
- - First major release
194
+ - Changed option names
195
+
196
+ ## 0.0.2 (2014-04-29)
197
+
198
+ - Added open and click tracking
199
+ - Added UTM parameters
200
+ - Rescue errors
201
+
202
+ ## 0.0.1 (2014-04-28)
203
+
204
+ - First release
data/README.md CHANGED
@@ -33,7 +33,7 @@ rails generate ahoy:messages --encryption=lockbox
33
33
  rails db:migrate
34
34
  ```
35
35
 
36
- To use Active Record encryption (Rails 7+, experimental), run:
36
+ To use Active Record encryption, run:
37
37
 
38
38
  ```sh
39
39
  rails generate ahoy:messages --encryption=activerecord
@@ -106,7 +106,7 @@ user.messages
106
106
  Add extra data to messages. Create a migration like:
107
107
 
108
108
  ```ruby
109
- class AddCouponIdToAhoyMessages < ActiveRecord::Migration[7.2]
109
+ class AddCouponIdToAhoyMessages < ActiveRecord::Migration[8.0]
110
110
  def change
111
111
  add_column :ahoy_messages, :coupon_id, :integer
112
112
  end
@@ -324,6 +324,16 @@ Get stats for a campaign
324
324
  AhoyEmail.stats("my-campaign")
325
325
  ```
326
326
 
327
+ ## HTML Parsing
328
+
329
+ By default, Nokogiri’s default HTML parser is used to rewrite links for UTM tagging and click analytics. This currently uses HTML4, which [only allows inline elements inside links](https://github.com/sparklemotion/nokogiri/issues/1876#issuecomment-468276937).
330
+
331
+ To use HTML5 parsing, create `config/initializers/ahoy_email.rb` with:
332
+
333
+ ```ruby
334
+ AhoyEmail.default_options[:html5] = true
335
+ ```
336
+
327
337
  ## History
328
338
 
329
339
  View the [changelog](https://github.com/ankane/ahoy_email/blob/master/CHANGELOG.md)
@@ -25,7 +25,7 @@ module Ahoy
25
25
  end
26
26
 
27
27
  redirect_options = {}
28
- redirect_options[:allow_other_host] = true if ActionPack::VERSION::MAJOR >= 7
28
+ redirect_options[:allow_other_host] = true
29
29
 
30
30
  if AhoyEmail::Utils.signature_verified?(legacy: legacy, token: token, campaign: campaign, url: url, signature: signature)
31
31
  data = {}
@@ -11,7 +11,7 @@ module AhoyEmail
11
11
  creds =
12
12
  if app.respond_to?(:credentials) && app.credentials.secret_key_base
13
13
  app.credentials
14
- elsif app.respond_to?(:secrets) && (Rails::VERSION::STRING.to_f < 7.1 || app.config.paths["config/secrets"].existent.any?)
14
+ elsif app.respond_to?(:secrets) && app.config.paths["config/secrets"].existent.any?
15
15
  app.secrets
16
16
  else
17
17
  app.config
@@ -63,6 +63,9 @@ module AhoyEmail
63
63
  # only call other options if needed
64
64
  if options[key]
65
65
  AhoyEmail::Utils::OPTION_KEYS[key].each do |k|
66
+ # make sure html5 only called once
67
+ next if options.key?(k)
68
+
66
69
  v = ahoy_options[k]
67
70
  options[k] = v.respond_to?(:call) ? instance_exec(&v) : v
68
71
  end
@@ -53,7 +53,7 @@ module AhoyEmail
53
53
  if html_part?
54
54
  part = message.html_part || message
55
55
 
56
- doc = Nokogiri::HTML::Document.parse(part.body.raw_source)
56
+ doc = parser_class.parse(part.body.raw_source)
57
57
  doc.css("a[href]").each do |link|
58
58
  uri = parse_uri(link["href"])
59
59
  next unless trackable?(uri)
@@ -92,6 +92,19 @@ module AhoyEmail
92
92
  end
93
93
  end
94
94
 
95
+ # use document instead of fragment
96
+ # https://github.com/ankane/ahoy_email/pull/150
97
+ def parser_class
98
+ case options[:html5]
99
+ when true
100
+ Nokogiri::HTML5::Document
101
+ when false
102
+ Nokogiri::HTML4::Document
103
+ else
104
+ Nokogiri::HTML::Document
105
+ end
106
+ end
107
+
95
108
  def html_part?
96
109
  (message.html_part || message).content_type =~ /html/
97
110
  end
@@ -2,8 +2,8 @@ module AhoyEmail
2
2
  class Utils
3
3
  OPTION_KEYS = {
4
4
  message: %i(message mailer user extra),
5
- utm_params: %i(utm_source utm_medium utm_term utm_content utm_campaign),
6
- click: %i(campaign url_options unsubscribe_links)
5
+ utm_params: %i(utm_source utm_medium utm_term utm_content utm_campaign html5),
6
+ click: %i(campaign url_options unsubscribe_links html5)
7
7
  }
8
8
 
9
9
  class << self
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "2.3.1"
2
+ VERSION = "2.5.0"
3
3
  end
data/lib/ahoy_email.rb CHANGED
@@ -48,7 +48,10 @@ module AhoyEmail
48
48
  click: false,
49
49
  campaign: nil,
50
50
  url_options: {},
51
- unsubscribe_links: false
51
+ unsubscribe_links: false,
52
+
53
+ # utm params and click analytics
54
+ html5: nil
52
55
  }
53
56
 
54
57
  self.track_method = lambda do |data|
@@ -34,8 +34,11 @@ module Ahoy
34
34
  when "lockbox"
35
35
  "t.text :to_ciphertext\n t.string :to_bidx, index: true"
36
36
  else
37
- # TODO add limit: 510 for Active Record encryption + MySQL?
38
- "t.string :to, index: true"
37
+ if encryption == "activerecord" && mysql?
38
+ "t.string :to, limit: 510, index: true"
39
+ else
40
+ "t.string :to, index: true"
41
+ end
39
42
  end
40
43
  end
41
44
 
@@ -63,6 +66,14 @@ module Ahoy
63
66
  "has_encrypted"
64
67
  end
65
68
  end
69
+
70
+ def mysql?
71
+ adapter =~ /mysql|trilogy/i
72
+ end
73
+
74
+ def adapter
75
+ ActiveRecord::Base.connection_db_config.adapter.to_s
76
+ end
66
77
  end
67
78
  end
68
79
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: actionmailer
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.1'
18
+ version: '7.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '6.1'
25
+ version: '7.1'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: addressable
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +65,6 @@ dependencies:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0.4'
69
- description:
70
68
  email: andrew@ankane.org
71
69
  executables: []
72
70
  extensions: []
@@ -108,7 +106,6 @@ homepage: https://github.com/ankane/ahoy_email
108
106
  licenses:
109
107
  - MIT
110
108
  metadata: {}
111
- post_install_message:
112
109
  rdoc_options: []
113
110
  require_paths:
114
111
  - lib
@@ -116,15 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
113
  requirements:
117
114
  - - ">="
118
115
  - !ruby/object:Gem::Version
119
- version: '3'
116
+ version: '3.2'
120
117
  required_rubygems_version: !ruby/object:Gem::Requirement
121
118
  requirements:
122
119
  - - ">="
123
120
  - !ruby/object:Gem::Version
124
121
  version: '0'
125
122
  requirements: []
126
- rubygems_version: 3.5.16
127
- signing_key:
123
+ rubygems_version: 3.6.7
128
124
  specification_version: 4
129
125
  summary: First-party email analytics for Rails
130
126
  test_files: []