ahoy_email 1.0.3 → 2.0.2
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 +4 -4
- data/CHANGELOG.md +56 -22
- data/LICENSE.txt +1 -1
- data/README.md +181 -135
- data/app/controllers/ahoy/messages_controller.rb +27 -45
- data/app/models/ahoy/click.rb +5 -0
- data/app/models/ahoy/message.rb +1 -1
- data/config/routes.rb +3 -0
- data/lib/ahoy_email.rb +34 -9
- data/lib/ahoy_email/database_subscriber.rb +42 -0
- data/lib/ahoy_email/engine.rb +3 -1
- data/lib/ahoy_email/mailer.rb +45 -17
- data/lib/ahoy_email/message_subscriber.rb +12 -0
- data/lib/ahoy_email/processor.rb +24 -43
- data/lib/ahoy_email/redis_subscriber.rb +79 -0
- data/lib/ahoy_email/tracker.rb +9 -3
- data/lib/ahoy_email/utils.rb +35 -0
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/generators/ahoy/clicks/activerecord_generator.rb +20 -0
- data/lib/generators/ahoy/clicks/mongoid_generator.rb +15 -0
- data/lib/generators/ahoy/clicks/templates/migration.rb.tt +11 -0
- data/lib/generators/ahoy/clicks/templates/mongoid.rb.tt +8 -0
- data/lib/generators/ahoy/clicks_generator.rb +37 -0
- data/lib/generators/ahoy/messages/activerecord_generator.rb +40 -0
- data/lib/generators/ahoy/messages/mongoid_generator.rb +21 -0
- data/lib/generators/{ahoy_email/templates/install.rb.tt → ahoy/messages/templates/migration.rb.tt} +2 -2
- data/lib/generators/ahoy/messages/templates/model_encrypted.rb.tt +8 -0
- data/lib/generators/ahoy/messages/templates/mongoid.rb.tt +12 -0
- data/lib/generators/ahoy/messages/templates/mongoid_encrypted.rb.tt +16 -0
- data/lib/generators/ahoy/messages_generator.rb +39 -0
- metadata +29 -113
- data/lib/generators/ahoy_email/install_generator.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12cfd52040334d8582ee01785c46c290d9a8e125d79ea5a5cddabed3d26ed144
|
4
|
+
data.tar.gz: db924f04d522c4bb9fd488fb34533349b231148170de637fff11ca34c6c18b36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba35f76f9d5bb2d52972ab648179e710c16eeda09bc51b4f91aff083bad354ec5dd6b8c98985b913efbf40c9e3215a3111e2a45978c647cf2fa8d9bd96519925
|
7
|
+
data.tar.gz: 1247bc81b9cc52a43ec480640c4c94989cfcf7ac4c0868c5c5cdeb0d85da013f93e9bc61993f78d94a8191819e6b7c76d6593f84d70203ed329793debbf7df2a
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,52 @@
|
|
1
|
-
##
|
1
|
+
## 2.0.2 (2021-03-14)
|
2
|
+
|
3
|
+
- Added support for Mongoid to database subscriber
|
4
|
+
|
5
|
+
## 2.0.1 (2021-03-08)
|
6
|
+
|
7
|
+
- Added database subscriber
|
8
|
+
|
9
|
+
## 2.0.0 (2021-03-06)
|
10
|
+
|
11
|
+
- Made `to` field encrypted by default for new installations
|
12
|
+
- Added click analytics for Redis
|
13
|
+
- Added send events to subscribers
|
14
|
+
- Removed support for Rails < 5.2
|
15
|
+
|
16
|
+
Breaking changes
|
17
|
+
|
18
|
+
- The `track` method has been broken into `has_history` for message history, `utm_params` for UTM tagging, and `track_clicks` for click analytics
|
19
|
+
- Message history is no longer enabled by default
|
20
|
+
- Open tracking has been removed
|
21
|
+
- `:message` is no longer included in click events
|
22
|
+
- Users are shown a link expired page when signature verification fails instead of being redirected to the homepage when `AhoyEmail.invalid_redirect_url` is not set
|
23
|
+
|
24
|
+
## 1.1.1 (2021-03-06)
|
25
|
+
|
26
|
+
- Added support for classes for subscribers
|
27
|
+
- Use `datetime` type in migration
|
28
|
+
|
29
|
+
## 1.1.0 (2019-07-15)
|
30
|
+
|
31
|
+
- Made `opened_at` optional with click tracking
|
32
|
+
- Fixed secret token for environment variables
|
33
|
+
- Removed support for Rails 4.2
|
34
|
+
|
35
|
+
## 1.0.3 (2019-02-18)
|
2
36
|
|
3
37
|
- Fixed custom message model
|
4
38
|
- Fixed `message` option with proc
|
5
39
|
|
6
|
-
## 1.0.2
|
40
|
+
## 1.0.2 (2018-10-02)
|
7
41
|
|
8
42
|
- Fixed error with Ruby < 2.5
|
9
43
|
- Fixed UTM parameters storage on model
|
10
44
|
|
11
|
-
## 1.0.1
|
45
|
+
## 1.0.1 (2018-09-27)
|
12
46
|
|
13
47
|
- Use observer instead of interceptor
|
14
48
|
|
15
|
-
## 1.0.0
|
49
|
+
## 1.0.0 (2018-09-27)
|
16
50
|
|
17
51
|
- Removed support for Rails < 4.2
|
18
52
|
|
@@ -25,91 +59,91 @@ Breaking changes
|
|
25
59
|
- `AhoyEmail.track` was removed in favor of `AhoyEmail.default_options`
|
26
60
|
- The `heuristic_parse` option was removed and is now the default
|
27
61
|
|
28
|
-
## 0.5.2
|
62
|
+
## 0.5.2 (2018-04-26)
|
29
63
|
|
30
64
|
- Fixed secret token for Rails 5.2
|
31
65
|
- Added `heuristic_parse` option
|
32
66
|
|
33
|
-
## 0.5.1
|
67
|
+
## 0.5.1 (2018-04-19)
|
34
68
|
|
35
69
|
- Fixed deprecation warning in Rails 5.2
|
36
70
|
- Added `unsubscribe_links` option
|
37
71
|
- Allow `message_model` to accept a proc
|
38
72
|
- Use `references` in migration
|
39
73
|
|
40
|
-
## 0.5.0
|
74
|
+
## 0.5.0 (2017-05-01)
|
41
75
|
|
42
76
|
- Added support for Rails 5.1
|
43
77
|
- Added `invalid_redirect_url`
|
44
78
|
|
45
|
-
## 0.4.0
|
79
|
+
## 0.4.0 (2016-09-01)
|
46
80
|
|
47
81
|
- Fixed `belongs_to` error in Rails 5
|
48
82
|
- Include `safely_block` gem without polluting global namespace
|
49
83
|
|
50
|
-
## 0.3.2
|
84
|
+
## 0.3.2 (2016-07-27)
|
51
85
|
|
52
86
|
- Fixed deprecation warning for Rails 5
|
53
87
|
- Do not track content by default on fresh installations
|
54
88
|
|
55
|
-
## 0.3.1
|
89
|
+
## 0.3.1 (2016-05-11)
|
56
90
|
|
57
91
|
- Fixed deprecation warnings
|
58
92
|
- Fixed `stack level too deep` error
|
59
93
|
|
60
|
-
## 0.3.0
|
94
|
+
## 0.3.0 (2015-12-16)
|
61
95
|
|
62
96
|
- Added safely for error reporting
|
63
97
|
- Fixed error with `to`
|
64
98
|
- Prevent duplicate records when mail called multiple times
|
65
99
|
|
66
|
-
## 0.2.4
|
100
|
+
## 0.2.4 (2015-07-29)
|
67
101
|
|
68
102
|
- Added `extra` option for extra attributes
|
69
103
|
|
70
|
-
## 0.2.3
|
104
|
+
## 0.2.3 (2015-03-22)
|
71
105
|
|
72
106
|
- Save utm parameters
|
73
107
|
- Added `url_options`
|
74
108
|
- Skip tracking for `mailto` links
|
75
109
|
- Only set secret token if not already set
|
76
110
|
|
77
|
-
## 0.2.2
|
111
|
+
## 0.2.2 (2014-08-31)
|
78
112
|
|
79
113
|
- Fixed secret token for Rails 4.1
|
80
114
|
- Fixed links with href
|
81
115
|
- Fixed message id for Rails 3.1
|
82
116
|
|
83
|
-
## 0.2.1
|
117
|
+
## 0.2.1 (2014-05-26)
|
84
118
|
|
85
119
|
- Added `only` and `except` options
|
86
120
|
|
87
|
-
## 0.2.0
|
121
|
+
## 0.2.0 (2014-05-10)
|
88
122
|
|
89
123
|
- Enable tracking when track is called by default
|
90
124
|
|
91
|
-
## 0.1.5
|
125
|
+
## 0.1.5 (2014-05-09)
|
92
126
|
|
93
127
|
- Rails 3 fix
|
94
128
|
|
95
|
-
## 0.1.4
|
129
|
+
## 0.1.4 (2014-05-04)
|
96
130
|
|
97
131
|
- Try not to rewrite unsubscribe links
|
98
132
|
|
99
|
-
## 0.1.3
|
133
|
+
## 0.1.3 (2014-05-03)
|
100
134
|
|
101
135
|
- Added `to` and `mailer` fields
|
102
136
|
- Added subscribers for open and click events
|
103
137
|
|
104
|
-
## 0.1.2
|
138
|
+
## 0.1.2 (2014-05-01)
|
105
139
|
|
106
140
|
- Added `AhoyEmail.track` (fix)
|
107
141
|
|
108
|
-
## 0.1.1
|
142
|
+
## 0.1.1 (2014-04-30)
|
109
143
|
|
110
144
|
- Use secure compare for signature verification
|
111
145
|
- Fixed deprecation warnings
|
112
146
|
|
113
|
-
## 0.1.0
|
147
|
+
## 0.1.0 (2014-04-29)
|
114
148
|
|
115
149
|
- First major release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,14 @@
|
|
1
1
|
# Ahoy Email
|
2
2
|
|
3
|
-
|
3
|
+
First-party email analytics for Rails
|
4
4
|
|
5
|
-
|
5
|
+
**Ahoy Email 2.0 was recently released** - see [how to upgrade](#upgrading)
|
6
6
|
|
7
|
-
|
8
|
-
- Easy UTM tagging
|
9
|
-
- Optional open and click tracking
|
10
|
-
|
11
|
-
**Ahoy Email 1.0 was recently released!** See [how to upgrade](#upgrading)
|
7
|
+
:fire: For web and native app analytics, check out [Ahoy](https://github.com/ankane/ahoy)
|
12
8
|
|
13
9
|
:bullettrain_side: To manage unsubscribes, check out [Mailkick](https://github.com/ankane/mailkick)
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
[](https://travis-ci.org/ankane/ahoy_email)
|
11
|
+
[](https://github.com/ankane/ahoy_email/actions)
|
18
12
|
|
19
13
|
## Installation
|
20
14
|
|
@@ -24,42 +18,65 @@ Add this line to your application’s Gemfile:
|
|
24
18
|
gem 'ahoy_email'
|
25
19
|
```
|
26
20
|
|
27
|
-
|
21
|
+
## Getting Started
|
22
|
+
|
23
|
+
There are three main features, which can be used independently:
|
24
|
+
|
25
|
+
- [Message history](#message-history)
|
26
|
+
- [UTM tagging](#utm-tagging)
|
27
|
+
- [Click analytics](#click-analytics)
|
28
|
+
|
29
|
+
## Message History
|
30
|
+
|
31
|
+
To encrypt email addresses, install [Lockbox](https://github.com/ankane/lockbox) and [Blind Index](https://github.com/ankane/blind_index) and run:
|
28
32
|
|
29
33
|
```sh
|
30
|
-
rails generate
|
34
|
+
rails generate ahoy:messages
|
31
35
|
rails db:migrate
|
32
36
|
```
|
33
37
|
|
34
|
-
|
38
|
+
If you prefer not to encrypt data, run:
|
35
39
|
|
36
|
-
|
40
|
+
```sh
|
41
|
+
rails generate ahoy:messages --unencrypted
|
42
|
+
rails db:migrate
|
43
|
+
```
|
37
44
|
|
38
|
-
|
45
|
+
Then, add to mailers:
|
39
46
|
|
40
47
|
```ruby
|
41
48
|
class CouponMailer < ApplicationMailer
|
42
|
-
|
49
|
+
has_history
|
43
50
|
end
|
44
51
|
```
|
45
52
|
|
46
|
-
|
53
|
+
Use the `Ahoy::Message` model to query messages:
|
47
54
|
|
48
55
|
```ruby
|
49
|
-
|
56
|
+
Ahoy::Message.last
|
50
57
|
```
|
51
58
|
|
52
|
-
|
59
|
+
Use only and except to limit actions
|
53
60
|
|
54
|
-
|
61
|
+
```ruby
|
62
|
+
class CouponMailer < ApplicationMailer
|
63
|
+
has_history only: [:welcome]
|
64
|
+
end
|
65
|
+
```
|
55
66
|
|
56
|
-
|
67
|
+
To store history for all mailers, create `config/initializers/ahoy_email.rb` with:
|
57
68
|
|
58
|
-
|
69
|
+
```ruby
|
70
|
+
AhoyEmail.default_options[:message] = true
|
71
|
+
```
|
72
|
+
|
73
|
+
### Users
|
74
|
+
|
75
|
+
By default, Ahoy Email tries `@user` then `params[:user]` then `User.find_by(email: message.to)` to find the user. You can pass a specific user with:
|
59
76
|
|
60
77
|
```ruby
|
61
78
|
class CouponMailer < ApplicationMailer
|
62
|
-
|
79
|
+
has_history user: -> { params[:some_user] }
|
63
80
|
end
|
64
81
|
```
|
65
82
|
|
@@ -79,25 +96,23 @@ And run:
|
|
79
96
|
user.messages
|
80
97
|
```
|
81
98
|
|
82
|
-
### Extra
|
99
|
+
### Extra Data
|
83
100
|
|
84
|
-
|
85
|
-
|
86
|
-
Create a migration to add extra attributes to the `ahoy_messages` table. For example:
|
101
|
+
Add extra data to messages. Create a migration like:
|
87
102
|
|
88
103
|
```ruby
|
89
|
-
class AddCouponIdToAhoyMessages < ActiveRecord::Migration[
|
104
|
+
class AddCouponIdToAhoyMessages < ActiveRecord::Migration[6.1]
|
90
105
|
def change
|
91
106
|
add_column :ahoy_messages, :coupon_id, :integer
|
92
107
|
end
|
93
108
|
end
|
94
109
|
```
|
95
110
|
|
96
|
-
|
111
|
+
And use:
|
97
112
|
|
98
113
|
```ruby
|
99
114
|
class CouponMailer < ApplicationMailer
|
100
|
-
|
115
|
+
has_history extra: {coupon_id: 1}
|
101
116
|
end
|
102
117
|
```
|
103
118
|
|
@@ -105,213 +120,244 @@ You can use a proc as well.
|
|
105
120
|
|
106
121
|
```ruby
|
107
122
|
class CouponMailer < ApplicationMailer
|
108
|
-
|
123
|
+
has_history extra: -> { {coupon_id: params[:coupon].id} }
|
109
124
|
end
|
110
125
|
```
|
111
126
|
|
112
|
-
###
|
127
|
+
### Options
|
113
128
|
|
114
|
-
|
129
|
+
Set global options
|
115
130
|
|
116
131
|
```ruby
|
117
|
-
|
118
|
-
track utm_params: true # use only/except to limit actions
|
119
|
-
end
|
132
|
+
AhoyEmail.default_options[:user] = -> { params[:admin] }
|
120
133
|
```
|
121
134
|
|
122
|
-
|
135
|
+
Use a different model
|
123
136
|
|
124
|
-
|
125
|
-
|
126
|
-
|
137
|
+
```ruby
|
138
|
+
AhoyEmail.message_model = -> { UserMessage }
|
139
|
+
```
|
127
140
|
|
128
|
-
|
141
|
+
Or fully customize how messages are tracked
|
129
142
|
|
130
143
|
```ruby
|
131
|
-
|
132
|
-
|
144
|
+
AhoyEmail.track_method = lambda do |data|
|
145
|
+
# your code
|
133
146
|
end
|
134
147
|
```
|
135
148
|
|
136
|
-
|
149
|
+
### Data Retention
|
137
150
|
|
138
|
-
|
139
|
-
|
151
|
+
Delete older data with:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
Ahoy::Message.where("created_at < ?", 1.year.ago).in_batches.delete_all
|
140
155
|
```
|
141
156
|
|
142
|
-
|
157
|
+
Delete data for a specific user with:
|
143
158
|
|
144
|
-
|
159
|
+
```ruby
|
160
|
+
Ahoy::Message.where(user_id: 1).in_batches.delete_all
|
161
|
+
```
|
145
162
|
|
146
|
-
|
163
|
+
## UTM Tagging
|
147
164
|
|
148
|
-
|
165
|
+
Use UTM tagging to attribute visits or conversions to an email campaign. Add UTM parameters to links with:
|
149
166
|
|
150
167
|
```ruby
|
151
|
-
class
|
152
|
-
|
153
|
-
add_column :ahoy_messages, :token, :string
|
154
|
-
add_column :ahoy_messages, :opened_at, :timestamp
|
155
|
-
add_column :ahoy_messages, :clicked_at, :timestamp
|
156
|
-
|
157
|
-
add_index :ahoy_messages, :token
|
158
|
-
end
|
168
|
+
class CouponMailer < ApplicationMailer
|
169
|
+
utm_params
|
159
170
|
end
|
160
171
|
```
|
161
172
|
|
162
|
-
|
173
|
+
The defaults are:
|
174
|
+
|
175
|
+
- `utm_medium` - `email`
|
176
|
+
- `utm_source` - the mailer name like `coupon_mailer`
|
177
|
+
- `utm_campaign` - the mailer action like `offer`
|
178
|
+
|
179
|
+
You can customize them with:
|
163
180
|
|
164
181
|
```ruby
|
165
|
-
|
182
|
+
class CouponMailer < ApplicationMailer
|
183
|
+
utm_params utm_campaign: -> { "coupon#{params[:coupon].id}" }
|
184
|
+
end
|
166
185
|
```
|
167
186
|
|
168
|
-
|
187
|
+
Use only and except to limit actions
|
169
188
|
|
170
189
|
```ruby
|
171
190
|
class CouponMailer < ApplicationMailer
|
172
|
-
|
191
|
+
utm_params only: [:welcome]
|
173
192
|
end
|
174
193
|
```
|
175
194
|
|
176
|
-
|
195
|
+
Skip specific links with:
|
177
196
|
|
178
|
-
|
197
|
+
```erb
|
198
|
+
<%= link_to "Go", some_url, data: {skip_utm_params: true} %>
|
199
|
+
```
|
179
200
|
|
180
|
-
|
201
|
+
## Click Analytics
|
181
202
|
|
182
|
-
|
183
|
-
https://chartkick.com
|
184
|
-
```
|
203
|
+
You can track click-through rate to see how well campaigns are performing. Stats can be stored in your database, Redis, or any other data store.
|
185
204
|
|
186
|
-
|
205
|
+
#### Database
|
187
206
|
|
188
|
-
|
189
|
-
https://yoursite.com/ahoy/messages/rAnDoMtOkEn/click?url=https%3A%2F%2Fchartkick.com&signature=...
|
190
|
-
```
|
207
|
+
Run:
|
191
208
|
|
192
|
-
|
209
|
+
```sh
|
210
|
+
rails generate ahoy:clicks
|
211
|
+
rails db:migrate
|
212
|
+
```
|
193
213
|
|
194
|
-
|
214
|
+
And create `config/initializers/ahoy_email.rb` with:
|
195
215
|
|
196
|
-
```
|
197
|
-
|
216
|
+
```ruby
|
217
|
+
AhoyEmail.subscribers << AhoyEmail::DatabaseSubscriber
|
218
|
+
AhoyEmail.api = true
|
198
219
|
```
|
199
220
|
|
200
|
-
|
221
|
+
#### Redis
|
222
|
+
|
223
|
+
Add this line to your application’s Gemfile:
|
201
224
|
|
202
225
|
```ruby
|
203
|
-
|
226
|
+
gem 'redis'
|
204
227
|
```
|
205
228
|
|
206
|
-
|
229
|
+
And create `config/initializers/ahoy_email.rb` with:
|
207
230
|
|
208
231
|
```ruby
|
209
|
-
|
232
|
+
# pass your Redis client if you already have one
|
233
|
+
AhoyEmail.subscribers << AhoyEmail::RedisSubscriber.new(redis: Redis.new)
|
234
|
+
AhoyEmail.api = true
|
210
235
|
```
|
211
236
|
|
212
|
-
####
|
237
|
+
#### Other
|
213
238
|
|
214
|
-
|
239
|
+
Create `config/initializers/ahoy_email.rb` with:
|
215
240
|
|
216
241
|
```ruby
|
217
242
|
class EmailSubscriber
|
218
|
-
def
|
243
|
+
def track_send(data)
|
219
244
|
# your code
|
220
245
|
end
|
221
246
|
|
222
|
-
def
|
247
|
+
def track_click(data)
|
223
248
|
# your code
|
224
249
|
end
|
250
|
+
|
251
|
+
def stats(campaign)
|
252
|
+
# optional, for AhoyEmail.stats
|
253
|
+
end
|
225
254
|
end
|
226
255
|
|
227
|
-
AhoyEmail.subscribers << EmailSubscriber
|
228
|
-
|
256
|
+
AhoyEmail.subscribers << EmailSubscriber
|
257
|
+
AhoyEmail.api = true
|
258
|
+
````
|
229
259
|
|
230
|
-
|
260
|
+
### Usage
|
231
261
|
|
232
|
-
|
233
|
-
class EmailSubscriber
|
234
|
-
def open(event)
|
235
|
-
event[:controller].ahoy.track "Email opened", message_id: event[:message].id
|
236
|
-
end
|
262
|
+
Add to mailers you want to track
|
237
263
|
|
238
|
-
|
239
|
-
|
240
|
-
|
264
|
+
```ruby
|
265
|
+
class CouponMailer < ApplicationMailer
|
266
|
+
track_clicks campaign: "my-campaign"
|
241
267
|
end
|
242
|
-
|
243
|
-
AhoyEmail.subscribers << EmailSubscriber.new
|
244
268
|
```
|
245
269
|
|
246
|
-
|
270
|
+
If storing stats in the database, the mailer should also use `has_history`
|
247
271
|
|
248
|
-
|
272
|
+
Use only and except to limit actions
|
249
273
|
|
250
274
|
```ruby
|
251
|
-
|
275
|
+
class CouponMailer < ApplicationMailer
|
276
|
+
track_clicks campaign: "my-campaign", only: [:welcome]
|
277
|
+
end
|
252
278
|
```
|
253
279
|
|
254
|
-
|
280
|
+
Or make it conditional
|
255
281
|
|
256
282
|
```ruby
|
257
|
-
|
283
|
+
class CouponMailer < ApplicationMailer
|
284
|
+
track_clicks campaign: "my-campaign", if: -> { params[:user].opted_in? }
|
285
|
+
end
|
258
286
|
```
|
259
287
|
|
260
|
-
|
288
|
+
Skip specific links with:
|
261
289
|
|
262
|
-
```
|
263
|
-
|
264
|
-
# your code
|
265
|
-
end
|
290
|
+
```erb
|
291
|
+
<%= link_to "Go", some_url, data: {skip_click: true} %>
|
266
292
|
```
|
267
293
|
|
268
|
-
|
294
|
+
By default, unsubscribe links are excluded. To change this, use:
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
AhoyEmail.default_options[:unsubscribe_links] = true
|
298
|
+
```
|
269
299
|
|
270
|
-
|
300
|
+
You can specify the domain to use with:
|
271
301
|
|
272
302
|
```ruby
|
273
|
-
|
274
|
-
|
303
|
+
AhoyEmail.default_options[:url_options] = {host: "mydomain.com"}
|
304
|
+
```
|
275
305
|
|
276
|
-
|
306
|
+
### Stats
|
277
307
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
308
|
+
Get stats for a campaign
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
AhoyEmail.stats("my-campaign")
|
283
312
|
```
|
284
313
|
|
285
314
|
## Upgrading
|
286
315
|
|
287
|
-
###
|
316
|
+
### 2.0
|
317
|
+
|
318
|
+
Ahoy Email 2.0 brings a number of changes. Here are a few to be aware of:
|
288
319
|
|
289
|
-
|
320
|
+
- The `to` field is encrypted by default for new installations. If you’d like to encrypt an existing installation, install [Lockbox](https://github.com/ankane/lockbox) and [Blind Index](https://github.com/ankane/blind_index) and follow the Lockbox instructions for [migrating existing data](https://github.com/ankane/lockbox#migrating-existing-data).
|
290
321
|
|
291
|
-
|
322
|
+
For the model, create `app/models/ahoy/message.rb` with:
|
292
323
|
|
293
324
|
```ruby
|
294
|
-
|
325
|
+
class Ahoy::Message < ActiveRecord::Base
|
326
|
+
self.table_name = "ahoy_messages"
|
295
327
|
|
296
|
-
|
297
|
-
|
298
|
-
|
328
|
+
belongs_to :user, polymorphic: true, optional: true
|
329
|
+
|
330
|
+
encrypts :to, migrating: true
|
331
|
+
blind_index :to, migrating: true
|
332
|
+
end
|
299
333
|
```
|
300
334
|
|
301
|
-
-
|
302
|
-
|
335
|
+
- The `track` method has been broken into:
|
336
|
+
|
337
|
+
- `has_history` for message history
|
338
|
+
- `utm_params` for UTM tagging
|
339
|
+
- `track_clicks` for click analytics
|
340
|
+
|
341
|
+
- Message history is no longer enabled by default. Add `has_history` to individual mailers, or create an initializer with:
|
303
342
|
|
304
343
|
```ruby
|
305
|
-
|
306
|
-
|
344
|
+
AhoyEmail.default_options[:message] = true
|
345
|
+
```
|
346
|
+
|
347
|
+
- For privacy, open tracking has been removed.
|
307
348
|
|
308
|
-
|
309
|
-
|
349
|
+
- For clicks, we encourage you to try [aggregate analytics](#click-analytics) to measure the performance of campaigns. You can use a library like [Rollup](https://github.com/ankane/rollup) to aggregate existing data, then drop the `token` and `clicked_at` columns.
|
350
|
+
|
351
|
+
To keep individual analytics, use `has_history` and `track_clicks campaign: false` and create an initializer with:
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
AhoyEmail.save_token = true
|
355
|
+
AhoyEmail.subscribers << AhoyEmail::MessageSubscriber
|
310
356
|
```
|
311
357
|
|
312
|
-
|
313
|
-
|
314
|
-
-
|
358
|
+
If you use a custom subscriber, `:message` is no longer included in click events. You can use `:token` to query the message if needed.
|
359
|
+
|
360
|
+
- Users are shown a link expired page when signature verification fails instead of being redirected to the homepage when `AhoyEmail.invalid_redirect_url` is not set
|
315
361
|
|
316
362
|
## History
|
317
363
|
|
@@ -326,11 +372,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
326
372
|
- Write, clarify, or fix documentation
|
327
373
|
- Suggest or add new features
|
328
374
|
|
329
|
-
To get started with development
|
375
|
+
To get started with development:
|
330
376
|
|
331
377
|
```sh
|
332
378
|
git clone https://github.com/ankane/ahoy_email.git
|
333
379
|
cd ahoy_email
|
334
380
|
bundle install
|
335
|
-
rake test
|
381
|
+
bundle exec rake test
|
336
382
|
```
|