google_analytics_mailer 0.2.1 → 0.3.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 +4 -4
- data/.travis.yml +1 -0
- data/Appraisals +4 -0
- data/Changelog.md +5 -0
- data/Rakefile +0 -2
- data/gemfiles/actionmailer4_2.gemfile +20 -0
- data/lib/google_analytics_mailer/uri_builder.rb +8 -3
- data/lib/google_analytics_mailer/url_for.rb +1 -1
- data/lib/google_analytics_mailer/version.rb +1 -1
- data/lib/google_analytics_mailer.rb +4 -2
- data/spec/helpers/url_for_spec.rb +1 -0
- data/spec/lib/google_analytics_mailer_spec.rb +31 -4
- data/spec/lib/uri_builder_spec.rb +12 -0
- data/spec/support/views/filtered_mailer/welcome.html.erb +9 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0023fcfa943b89987bbb9cfcd2c03cbe6c42114b
|
4
|
+
data.tar.gz: 84184569fc5b4d6aa38a0af45a74a90a3779535e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c0ec1c40f51bedd55765f3407df00d98549483737b6c23e500d088716f48f3777401d42c0ff7577324b8b6f285922c5b99cf293f115e0ab4120954e10ef705
|
7
|
+
data.tar.gz: 693da6b38cc7853e945f38202c6b12a3282274e8ae6851d3bfed798b6afee0b15aa2ad5d0deaff669ec908c896733f1ac1e15e3f2056a904cb204b70e22cb33b
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/Changelog.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
Not released changes
|
2
2
|
|
3
|
+
## 0.3.0, released 2015-19-06
|
4
|
+
|
5
|
+
* Added `filter` option to optionally filter URLs to rewrite. Thanks [afn](https://github.com/afn)
|
6
|
+
* Testing support for ActionMailer 4.2
|
7
|
+
|
3
8
|
## 0.2.1, released 2014-11-06
|
4
9
|
|
5
10
|
* Testing support for ActionMailer 4.1
|
data/Rakefile
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "redcarpet"
|
6
|
+
gem "yard"
|
7
|
+
gem "coveralls", :require => false
|
8
|
+
gem "rake"
|
9
|
+
gem "rails", ">= 3.2.0"
|
10
|
+
gem "rspec-rails", "~> 2.14.0"
|
11
|
+
gem "email_spec", ">= 1.5.0"
|
12
|
+
gem "appraisal", "~> 1.0.2"
|
13
|
+
gem "actionmailer", "~> 4.2.0"
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "sqlite3"
|
17
|
+
gem "minitest"
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec :path => "../"
|
@@ -2,6 +2,9 @@ require 'addressable/uri'
|
|
2
2
|
|
3
3
|
# Class used to do the actual insertion of parameters
|
4
4
|
class GoogleAnalyticsMailer::UriBuilder
|
5
|
+
def initialize(filter=nil)
|
6
|
+
@filter = filter
|
7
|
+
end
|
5
8
|
|
6
9
|
# Append google analytics params to the given uri
|
7
10
|
# @param [String] uri the original uri
|
@@ -17,9 +20,11 @@ class GoogleAnalyticsMailer::UriBuilder
|
|
17
20
|
# if no params return untouched url
|
18
21
|
return uri if params.empty?
|
19
22
|
# build the final url
|
20
|
-
::Addressable::URI.parse(uri)
|
21
|
-
|
22
|
-
|
23
|
+
parsed = ::Addressable::URI.parse(uri)
|
24
|
+
return uri if @filter && !@filter.call(parsed)
|
25
|
+
|
26
|
+
parsed.query_values = (parsed.query_values || {}).reverse_merge(params) if parsed.absolute?
|
27
|
+
parsed.to_s.html_safe
|
23
28
|
end
|
24
29
|
|
25
30
|
end
|
@@ -9,7 +9,7 @@ require 'active_support/concern'
|
|
9
9
|
module GoogleAnalyticsMailer
|
10
10
|
|
11
11
|
# These are the currently GA allowed get params for link tagging
|
12
|
-
VALID_ANALYTICS_PARAMS = [:utm_source, :utm_medium, :utm_campaign, :utm_term, :utm_content]
|
12
|
+
VALID_ANALYTICS_PARAMS = [:utm_source, :utm_medium, :utm_campaign, :utm_term, :utm_content, :filter]
|
13
13
|
|
14
14
|
# Enable google analytics link tagging for the mailer (or controller) which call this method
|
15
15
|
#
|
@@ -24,12 +24,14 @@ module GoogleAnalyticsMailer
|
|
24
24
|
raise ArgumentError, "Invalid parameters keys #{params.keys - VALID_ANALYTICS_PARAMS}"
|
25
25
|
end
|
26
26
|
|
27
|
+
filter = params.delete(:filter)
|
28
|
+
|
27
29
|
# add accessor for class level parameters
|
28
30
|
cattr_accessor(:google_analytics_class_params) { params }
|
31
|
+
cattr_accessor(:google_analytics_filter) { filter }
|
29
32
|
|
30
33
|
# include the module which provides the actual functionality
|
31
34
|
include GoogleAnalytics
|
32
|
-
|
33
35
|
end
|
34
36
|
|
35
37
|
# Allow usage also in controllers since they have the same structure of ActionMailer
|
@@ -29,12 +29,9 @@ describe GoogleAnalyticsMailer do
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
class
|
32
|
+
class AbstractMailer < ActionMailer::Base
|
33
33
|
default :from => 'no-reply@example.com'
|
34
34
|
|
35
|
-
# declare url parameters for this mailer
|
36
|
-
google_analytics_mailer utm_source: 'newsletter', utm_medium: 'email' # etc
|
37
|
-
|
38
35
|
# simulate url helper
|
39
36
|
helper do
|
40
37
|
def newsletter_url params = {}
|
@@ -57,7 +54,37 @@ describe GoogleAnalyticsMailer do
|
|
57
54
|
def welcome3
|
58
55
|
mail(to: 'user@example.com')
|
59
56
|
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class UserMailer < AbstractMailer
|
60
|
+
# declare url parameters for this mailer
|
61
|
+
google_analytics_mailer utm_source: 'newsletter', utm_medium: 'email' # etc
|
62
|
+
end
|
63
|
+
|
64
|
+
class FilteredMailer < AbstractMailer
|
65
|
+
# declare url parameters for this mailer
|
66
|
+
google_analytics_mailer utm_source: 'newsletter', utm_medium: 'email', filter: ->(uri) { uri.host == 'www.example.com' }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe FilteredMailer do
|
70
|
+
|
71
|
+
# see view in spec/support/views/user_mailer/welcome.html.erb
|
72
|
+
describe '#welcome' do
|
73
|
+
|
74
|
+
subject { FilteredMailer.welcome }
|
75
|
+
|
76
|
+
it 'should have analytics link with params taken from class definition' do
|
77
|
+
subject.should have_body_text 'http://www.example.com/newsletter?utm_medium=email&utm_source=newsletter'
|
78
|
+
end
|
60
79
|
|
80
|
+
it 'should have analytics link with overridden params' do
|
81
|
+
subject.should have_body_text 'http://www.example.com/newsletter?utm_medium=email&utm_source=my_newsletter'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should have non-http link with no tracking' do
|
85
|
+
subject.should have_body_text '"http://www.external.com/"'
|
86
|
+
end
|
87
|
+
end
|
61
88
|
end
|
62
89
|
|
63
90
|
describe UserMailer do
|
@@ -20,6 +20,18 @@ describe GoogleAnalyticsMailer::UriBuilder do
|
|
20
20
|
subject.build('http://www.example.com', {}).should == 'http://www.example.com'
|
21
21
|
end
|
22
22
|
|
23
|
+
context 'with a filter' do
|
24
|
+
subject { GoogleAnalyticsMailer::UriBuilder.new ->(uri) { uri.host == 'www.example.com' } }
|
25
|
+
|
26
|
+
it 'should add GA parameters to URIs that match the filter' do
|
27
|
+
subject.build('http://www.example.com', utm_campaign: 'Foo Bar').should include 'utm_campaign=Foo%20Bar'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should not add GA parameters to URIs that do not match the filter' do
|
31
|
+
subject.build('http://www.external.com', utm_campaign: 'Foo Bar').should_not include 'utm_campaign=Foo%20Bar'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
23
35
|
end
|
24
36
|
|
25
37
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Newsletter title</h1>
|
2
|
+
<div class="body">
|
3
|
+
<!-- this will produce ?utm_medium=email&utm_source=newsletter because of class default params -->
|
4
|
+
<%= link_to('Read online', newsletter_url) %>
|
5
|
+
<!-- local parameters are not overridden, so this produces ?utm_medium=email&utm_source=my_newsletter -->
|
6
|
+
<%= link_to('Read online', newsletter_url(utm_source: 'my_newsletter')) %>
|
7
|
+
<!-- this will get filtered -->
|
8
|
+
<%= link_to('External link', 'http://www.external.com/') %>
|
9
|
+
</div>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_analytics_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Napoleoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- gemfiles/actionmailer3_2.gemfile
|
60
60
|
- gemfiles/actionmailer4_0.gemfile
|
61
61
|
- gemfiles/actionmailer4_1.gemfile
|
62
|
+
- gemfiles/actionmailer4_2.gemfile
|
62
63
|
- google_analytics_mailer.gemspec
|
63
64
|
- lib/google_analytics_mailer.rb
|
64
65
|
- lib/google_analytics_mailer/uri_builder.rb
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- spec/lib/google_analytics_mailer_spec.rb
|
69
70
|
- spec/lib/uri_builder_spec.rb
|
70
71
|
- spec/spec_helper.rb
|
72
|
+
- spec/support/views/filtered_mailer/welcome.html.erb
|
71
73
|
- spec/support/views/user_mailer/welcome.html.erb
|
72
74
|
- spec/support/views/user_mailer/welcome2.html.erb
|
73
75
|
- spec/support/views/user_mailer/welcome3.html.erb
|
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
93
|
version: '0'
|
92
94
|
requirements: []
|
93
95
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.4.
|
96
|
+
rubygems_version: 2.4.6
|
95
97
|
signing_key:
|
96
98
|
specification_version: 4
|
97
99
|
summary: This gem provides automatic Google Analytics tagged links in ActionMailer
|
@@ -101,6 +103,7 @@ test_files:
|
|
101
103
|
- spec/lib/google_analytics_mailer_spec.rb
|
102
104
|
- spec/lib/uri_builder_spec.rb
|
103
105
|
- spec/spec_helper.rb
|
106
|
+
- spec/support/views/filtered_mailer/welcome.html.erb
|
104
107
|
- spec/support/views/user_mailer/welcome.html.erb
|
105
108
|
- spec/support/views/user_mailer/welcome2.html.erb
|
106
109
|
- spec/support/views/user_mailer/welcome3.html.erb
|