ahoy_email 2.3.1 → 2.4.0

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
  SHA256:
3
- metadata.gz: 238e4d5f6eb74588ea6d9d628cce5b7c69fa584741280c9d766fa13c5ef8164a
4
- data.tar.gz: 3dedf13c78c400d139bb9450fc01ceb1a56c844b463ff0cafdf12fc7f6553573
3
+ metadata.gz: e11cd64d52d35113df4fe7e29042683f3f5de6aa256ef75ae8f8455d2d1eec1f
4
+ data.tar.gz: f38baf49086ddaa1759243644074da6486cddbb0793c1d71e93e352228f12b66
5
5
  SHA512:
6
- metadata.gz: 4cc75f90c29e23f1c4dc5e87cfa626cbff9a6a0f3c23850f5813bb3890f1afbc72912e94bc8fb5f15f87c0f32794c7031f5559d0255d52065412e73dba793985
7
- data.tar.gz: 559b2bec029c2d659c10799ff38453b939ff615f84a7a4041670badf3b96c8faa91d9f6037f9147d0003422197bdc430ddd2e075f391391c01905cb522abc2f6
6
+ metadata.gz: dd32bc570175e43d4b601d1b6bf7289f44c51912fe3b5f3fafc86cfbd505a4aa40b8c7ea224cfa0c29d790d0d9994acc92d0d143d4a482152539fec1904cce9b
7
+ data.tar.gz: 81e1d2e90a4a82621b5fb3b755653f6536cc755f3702c9d89a57e0be90b6ea1111b6cf5b737093f37e859c1c5742f137492b1ee41841125b6504623c6bd830da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 2.4.0 (2024-11-11)
2
+
3
+ - Added `html5` option
4
+ - Improved generator for Active Record encryption and MySQL
5
+ - Removed support for Ruby < 3.1 and Rails < 7
6
+ - Removed support for Mongoid < 8
7
+
1
8
  ## 2.3.1 (2024-09-09)
2
9
 
3
10
  - Fixed deprecation warning with Rails 7.1
@@ -180,4 +187,14 @@ Breaking changes
180
187
 
181
188
  ## 0.1.0 (2014-04-29)
182
189
 
183
- - First major release
190
+ - Changed option names
191
+
192
+ ## 0.0.2 (2014-04-29)
193
+
194
+ - Added open and click tracking
195
+ - Added UTM parameters
196
+ - Rescue errors
197
+
198
+ ## 0.0.1 (2014-04-28)
199
+
200
+ - 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 = {}
@@ -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.4.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,14 @@
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.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-09 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -116,14 +116,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '3'
119
+ version: '3.1'
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.5.16
126
+ rubygems_version: 3.5.22
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: First-party email analytics for Rails