ahoy_email 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +22 -10
- data/app/models/ahoy/click.rb +5 -0
- data/lib/ahoy_email.rb +1 -0
- data/lib/ahoy_email/database_subscriber.rb +31 -0
- data/lib/ahoy_email/redis_subscriber.rb +1 -1
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/generators/ahoy/clicks/activerecord_generator.rb +20 -0
- data/lib/generators/ahoy/clicks/templates/migration.rb.tt +11 -0
- data/lib/generators/ahoy/clicks_generator.rb +11 -0
- data/lib/generators/ahoy/messages_generator.rb +0 -2
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69eb9c77891a37c75ef7f7683211c90159cbb8aefd64fa14a0b1b35d2e16d0eb
|
4
|
+
data.tar.gz: a937ba8e9362d1c2551f5c193b9a3bbf1b4132f3df9ddb77f3f838f633fb2f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b12c970be432d7db95fdb8eaade5766f69fc7826a94f41474ba5c2a35da1ea85b6317f83250cb1c8f41c7fe876028b1377958709d2c84ff9bd303926ac8ab5a
|
7
|
+
data.tar.gz: 96dcc647ee3777e27b14d7628025d96ea92efce7160d36da0b066b72d9dc5aac8196008699a93673d81d0fdcb909aa69874b349dffdbaf0e32e4d7511a32df5a
|
data/CHANGELOG.md
CHANGED
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
|
@@ -287,13 +305,7 @@ AhoyEmail.default_options[:url_options] = {host: "mydomain.com"}
|
|
287
305
|
|
288
306
|
### Stats
|
289
307
|
|
290
|
-
Get stats for
|
291
|
-
|
292
|
-
```ruby
|
293
|
-
AhoyEmail.stats
|
294
|
-
```
|
295
|
-
|
296
|
-
Get stats for a specific campaign
|
308
|
+
Get stats for a campaign
|
297
309
|
|
298
310
|
```ruby
|
299
311
|
AhoyEmail.stats("my-campaign")
|
data/lib/ahoy_email.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
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
|
+
result = Ahoy::Click.where(campaign: campaign).select("COUNT(*) AS clicks, COUNT(DISTINCT token) AS unique_clicks").to_a[0]
|
14
|
+
clicks = result.clicks
|
15
|
+
unique_clicks = result.unique_clicks
|
16
|
+
|
17
|
+
if sends > 0 || clicks > 0
|
18
|
+
{
|
19
|
+
sends: sends,
|
20
|
+
clicks: clicks,
|
21
|
+
unique_clicks: unique_clicks,
|
22
|
+
ctr: 100 * unique_clicks / sends.to_f
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def campaigns
|
28
|
+
Ahoy::Message.where.not(campaign: nil).distinct.pluck(:campaign)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ahoy_email/version.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,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
|
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.0.
|
4
|
+
version: 2.0.1
|
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-03-
|
11
|
+
date: 2021-03-08 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,9 @@ 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/templates/migration.rb.tt
|
96
|
+
- lib/generators/ahoy/clicks_generator.rb
|
92
97
|
- lib/generators/ahoy/messages/activerecord_generator.rb
|
93
98
|
- lib/generators/ahoy/messages/mongoid_generator.rb
|
94
99
|
- lib/generators/ahoy/messages/templates/migration.rb.tt
|