ahoy_email 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +30 -10
- data/app/models/ahoy/click.rb +5 -0
- data/lib/ahoy_email/database_subscriber.rb +42 -0
- data/lib/ahoy_email/processor.rb +2 -2
- data/lib/ahoy_email/redis_subscriber.rb +1 -1
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/ahoy_email.rb +1 -0
- 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_generator.rb +0 -2
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b84f8c566d81a470ba99f4318c2d7dd3f1b3fae6b05155491f486cbdbff7c0a6
|
4
|
+
data.tar.gz: 8ab62441cf6df6b4ab6af401a9cbed8864ac634d28dd728f6b83bfd743dce284
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf70b92f9ba7b0d91324eae1927fe49464c3b3a76293272570559526064d20a1df5a3859a350dac9d6708113b787e8566a8db58cb6bc881d463ae2f4581865c8
|
7
|
+
data.tar.gz: 62019c44c7e66c5d3858c9862d20276dbb876d024ca21d1d8691e3969944778c493fa3e988e0e22e2253c7515a6d453d2f11c794867941fa024017c9f28eeb02
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 2.1.0 (2021-09-25)
|
2
|
+
|
3
|
+
- Fixed mailer `default_url_options` not being applied to click links
|
4
|
+
|
5
|
+
## 2.0.3 (2021-03-31)
|
6
|
+
|
7
|
+
- Fixed `utm_params` and `track_clicks` stripping `<head>` tags from messages
|
8
|
+
|
9
|
+
## 2.0.2 (2021-03-14)
|
10
|
+
|
11
|
+
- Added support for Mongoid to database subscriber
|
12
|
+
|
13
|
+
## 2.0.1 (2021-03-08)
|
14
|
+
|
15
|
+
- Added database subscriber
|
16
|
+
|
1
17
|
## 2.0.0 (2021-03-06)
|
2
18
|
|
3
19
|
- Made `to` field encrypted by default for new installations
|
data/README.md
CHANGED
@@ -200,7 +200,23 @@ Skip specific links with:
|
|
200
200
|
|
201
201
|
## Click Analytics
|
202
202
|
|
203
|
-
You can track click-through rate to see how well campaigns are performing. Stats can be stored in
|
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.
|
204
|
+
|
205
|
+
#### Database
|
206
|
+
|
207
|
+
Run:
|
208
|
+
|
209
|
+
```sh
|
210
|
+
rails generate ahoy:clicks
|
211
|
+
rails db:migrate
|
212
|
+
```
|
213
|
+
|
214
|
+
And create `config/initializers/ahoy_email.rb` with:
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
AhoyEmail.subscribers << AhoyEmail::DatabaseSubscriber
|
218
|
+
AhoyEmail.api = true
|
219
|
+
```
|
204
220
|
|
205
221
|
#### Redis
|
206
222
|
|
@@ -232,7 +248,7 @@ class EmailSubscriber
|
|
232
248
|
# your code
|
233
249
|
end
|
234
250
|
|
235
|
-
def stats(campaign
|
251
|
+
def stats(campaign)
|
236
252
|
# optional, for AhoyEmail.stats
|
237
253
|
end
|
238
254
|
end
|
@@ -241,7 +257,7 @@ AhoyEmail.subscribers << EmailSubscriber
|
|
241
257
|
AhoyEmail.api = true
|
242
258
|
````
|
243
259
|
|
244
|
-
###
|
260
|
+
### Usage
|
245
261
|
|
246
262
|
Add to mailers you want to track
|
247
263
|
|
@@ -251,6 +267,8 @@ class CouponMailer < ApplicationMailer
|
|
251
267
|
end
|
252
268
|
```
|
253
269
|
|
270
|
+
If storing stats in the database, the mailer should also use `has_history`
|
271
|
+
|
254
272
|
Use only and except to limit actions
|
255
273
|
|
256
274
|
```ruby
|
@@ -267,6 +285,14 @@ class CouponMailer < ApplicationMailer
|
|
267
285
|
end
|
268
286
|
```
|
269
287
|
|
288
|
+
You can also use a proc
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
class CouponMailer < ApplicationMailer
|
292
|
+
track_clicks campaign: -> { "coupon-#{action_name}" }
|
293
|
+
end
|
294
|
+
```
|
295
|
+
|
270
296
|
Skip specific links with:
|
271
297
|
|
272
298
|
```erb
|
@@ -287,13 +313,7 @@ AhoyEmail.default_options[:url_options] = {host: "mydomain.com"}
|
|
287
313
|
|
288
314
|
### Stats
|
289
315
|
|
290
|
-
Get stats for
|
291
|
-
|
292
|
-
```ruby
|
293
|
-
AhoyEmail.stats
|
294
|
-
```
|
295
|
-
|
296
|
-
Get stats for a specific campaign
|
316
|
+
Get stats for a campaign
|
297
317
|
|
298
318
|
```ruby
|
299
319
|
AhoyEmail.stats("my-campaign")
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module AhoyEmail
|
2
|
+
class DatabaseSubscriber
|
3
|
+
def track_send(event)
|
4
|
+
# use has_history to store on Ahoy::Messages
|
5
|
+
end
|
6
|
+
|
7
|
+
def track_click(event)
|
8
|
+
Ahoy::Click.create!(campaign: event[:campaign], token: event[:token])
|
9
|
+
end
|
10
|
+
|
11
|
+
def stats(campaign)
|
12
|
+
sends = Ahoy::Message.where(campaign: campaign).count
|
13
|
+
|
14
|
+
if defined?(ActiveRecord) && Ahoy::Click < ActiveRecord::Base
|
15
|
+
result = Ahoy::Click.where(campaign: campaign).select("COUNT(*) AS clicks, COUNT(DISTINCT token) AS unique_clicks").to_a[0]
|
16
|
+
clicks = result.clicks
|
17
|
+
unique_clicks = result.unique_clicks
|
18
|
+
else
|
19
|
+
clicks = Ahoy::Click.where(campaign: campaign).count
|
20
|
+
# TODO use aggregation framework
|
21
|
+
unique_clicks = Ahoy::Click.where(campaign: campaign).distinct(:token).count
|
22
|
+
end
|
23
|
+
|
24
|
+
if sends > 0 || clicks > 0
|
25
|
+
{
|
26
|
+
sends: sends,
|
27
|
+
clicks: clicks,
|
28
|
+
unique_clicks: unique_clicks,
|
29
|
+
ctr: 100 * unique_clicks / sends.to_f
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def campaigns
|
35
|
+
if defined?(ActiveRecord) && Ahoy::Message < ActiveRecord::Base
|
36
|
+
Ahoy::Message.where.not(campaign: nil).distinct.pluck(:campaign)
|
37
|
+
else
|
38
|
+
Ahoy::Message.where(campaign: {"$ne" => nil}).distinct(:campaign)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ahoy_email/processor.rb
CHANGED
@@ -53,7 +53,7 @@ module AhoyEmail
|
|
53
53
|
if html_part?
|
54
54
|
part = message.html_part || message
|
55
55
|
|
56
|
-
doc = Nokogiri::HTML::
|
56
|
+
doc = Nokogiri::HTML::Document.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)
|
@@ -123,7 +123,7 @@ module AhoyEmail
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def url_for(opt)
|
126
|
-
opt = (
|
126
|
+
opt = (mailer.default_url_options || {})
|
127
127
|
.merge(options[:url_options])
|
128
128
|
.merge(opt)
|
129
129
|
AhoyEmail::Engine.routes.url_helpers.url_for(opt)
|
data/lib/ahoy_email/version.rb
CHANGED
data/lib/ahoy_email.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rails/generators/active_record"
|
2
|
+
|
3
|
+
module Ahoy
|
4
|
+
module Generators
|
5
|
+
module Clicks
|
6
|
+
class ActiverecordGenerator < Rails::Generators::Base
|
7
|
+
include ActiveRecord::Generators::Migration
|
8
|
+
source_root File.join(__dir__, "templates")
|
9
|
+
|
10
|
+
def copy_migration
|
11
|
+
migration_template "migration.rb", "db/migrate/create_ahoy_clicks.rb", migration_version: migration_version
|
12
|
+
end
|
13
|
+
|
14
|
+
def migration_version
|
15
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Ahoy
|
4
|
+
module Generators
|
5
|
+
module Clicks
|
6
|
+
class MongoidGenerator < Rails::Generators::Base
|
7
|
+
source_root File.join(__dir__, "templates")
|
8
|
+
|
9
|
+
def copy_templates
|
10
|
+
template "mongoid.rb", "app/models/ahoy/click.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :ahoy_clicks do |t|
|
4
|
+
t.string :campaign, index: true
|
5
|
+
t.string :token
|
6
|
+
end
|
7
|
+
|
8
|
+
add_column :ahoy_messages, :campaign, :string
|
9
|
+
add_index :ahoy_messages, :campaign
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Ahoy
|
4
|
+
module Generators
|
5
|
+
class ClicksGenerator < Rails::Generators::Base
|
6
|
+
def copy_templates
|
7
|
+
activerecord = defined?(ActiveRecord)
|
8
|
+
mongoid = defined?(Mongoid)
|
9
|
+
|
10
|
+
selection =
|
11
|
+
if activerecord && mongoid
|
12
|
+
puts <<-MSG
|
13
|
+
|
14
|
+
Which data store would you like to use?
|
15
|
+
1. Active Record (default)
|
16
|
+
2. Mongoid
|
17
|
+
MSG
|
18
|
+
|
19
|
+
ask(">")
|
20
|
+
elsif activerecord
|
21
|
+
"1"
|
22
|
+
else
|
23
|
+
"2"
|
24
|
+
end
|
25
|
+
|
26
|
+
case selection
|
27
|
+
when "", "1"
|
28
|
+
invoke "ahoy:clicks:activerecord"
|
29
|
+
when "2"
|
30
|
+
invoke "ahoy:clicks:mongoid"
|
31
|
+
else
|
32
|
+
abort "Error: must enter a number [1-2]"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
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.
|
4
|
+
version: 2.1.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: 2021-
|
11
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -77,9 +77,11 @@ files:
|
|
77
77
|
- LICENSE.txt
|
78
78
|
- README.md
|
79
79
|
- app/controllers/ahoy/messages_controller.rb
|
80
|
+
- app/models/ahoy/click.rb
|
80
81
|
- app/models/ahoy/message.rb
|
81
82
|
- config/routes.rb
|
82
83
|
- lib/ahoy_email.rb
|
84
|
+
- lib/ahoy_email/database_subscriber.rb
|
83
85
|
- lib/ahoy_email/engine.rb
|
84
86
|
- lib/ahoy_email/mailer.rb
|
85
87
|
- lib/ahoy_email/message_subscriber.rb
|
@@ -89,6 +91,11 @@ files:
|
|
89
91
|
- lib/ahoy_email/tracker.rb
|
90
92
|
- lib/ahoy_email/utils.rb
|
91
93
|
- lib/ahoy_email/version.rb
|
94
|
+
- lib/generators/ahoy/clicks/activerecord_generator.rb
|
95
|
+
- lib/generators/ahoy/clicks/mongoid_generator.rb
|
96
|
+
- lib/generators/ahoy/clicks/templates/migration.rb.tt
|
97
|
+
- lib/generators/ahoy/clicks/templates/mongoid.rb.tt
|
98
|
+
- lib/generators/ahoy/clicks_generator.rb
|
92
99
|
- lib/generators/ahoy/messages/activerecord_generator.rb
|
93
100
|
- lib/generators/ahoy/messages/mongoid_generator.rb
|
94
101
|
- lib/generators/ahoy/messages/templates/migration.rb.tt
|
@@ -115,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
122
|
- !ruby/object:Gem::Version
|
116
123
|
version: '0'
|
117
124
|
requirements: []
|
118
|
-
rubygems_version: 3.2.
|
125
|
+
rubygems_version: 3.2.22
|
119
126
|
signing_key:
|
120
127
|
specification_version: 4
|
121
128
|
summary: First-party email analytics for Rails
|