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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c79ec78f1bb79fdbac0163b6994a2e05ccb7cca5
4
- data.tar.gz: b7cf7d0a4b3aef2f5abc0cef62a9b4cc2d6464d7
3
+ metadata.gz: 0023fcfa943b89987bbb9cfcd2c03cbe6c42114b
4
+ data.tar.gz: 84184569fc5b4d6aa38a0af45a74a90a3779535e
5
5
  SHA512:
6
- metadata.gz: 995215ff6e64cf073191cea14726d22591756bec030aa7a4c45e3c3f472076aa1f4f9357aca46494a3705f3034b348a16d186b8ae981028203763b47f1f6d2e0
7
- data.tar.gz: 704551ca2d01c8d33e8017263f4c3bd0425e5620373b494d97ff6ddb920b00262064d623a7edb035ab77bd979fad3052c0d71d20b63a4cc85c460a39722db1d6
6
+ metadata.gz: c9c0ec1c40f51bedd55765f3407df00d98549483737b6c23e500d088716f48f3777401d42c0ff7577324b8b6f285922c5b99cf293f115e0ab4120954e10ef705
7
+ data.tar.gz: 693da6b38cc7853e945f38202c6b12a3282274e8ae6851d3bfed798b6afee0b15aa2ad5d0deaff669ec908c896733f1ac1e15e3f2056a904cb204b70e22cb33b
data/.travis.yml CHANGED
@@ -8,3 +8,4 @@ gemfile:
8
8
  - gemfiles/actionmailer3_2.gemfile
9
9
  - gemfiles/actionmailer4_0.gemfile
10
10
  - gemfiles/actionmailer4_1.gemfile
11
+ - gemfiles/actionmailer4_2.gemfile
data/Appraisals CHANGED
@@ -9,3 +9,7 @@ end
9
9
  appraise 'actionmailer4_1' do
10
10
  gem 'actionmailer', '~> 4.1.0'
11
11
  end
12
+
13
+ appraise 'actionmailer4_2' do
14
+ gem 'actionmailer', '~> 4.2.0'
15
+ end
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
@@ -3,5 +3,3 @@ require "bundler/gem_tasks"
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
  task :default => :spec
6
-
7
- require 'appraisal'
@@ -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).tap do |parsed|
21
- parsed.query_values = (parsed.query_values || {}).reverse_merge(params) if parsed.absolute?
22
- end.to_s.html_safe
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
@@ -74,7 +74,7 @@ module GoogleAnalyticsMailer # :nodoc:
74
74
  # Return a UriBuilder instance
75
75
  # @return [UriBuilder]
76
76
  def builder
77
- @_builder ||= UriBuilder.new
77
+ @_builder ||= UriBuilder.new controller.class.google_analytics_filter
78
78
  end
79
79
 
80
80
  end
@@ -1,4 +1,4 @@
1
1
  module GoogleAnalyticsMailer
2
2
  # Application version
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  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
@@ -4,6 +4,7 @@ describe GoogleAnalyticsMailer::UrlFor do
4
4
 
5
5
  before(:each) do
6
6
  controller.stub(computed_analytics_params: {utm_source: 'foo'})
7
+ controller.class.stub(google_analytics_filter: nil)
7
8
  end
8
9
 
9
10
  describe '#with_google_analytics_params' do
@@ -29,12 +29,9 @@ describe GoogleAnalyticsMailer do
29
29
 
30
30
  end
31
31
 
32
- class UserMailer < ActionMailer::Base
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.2.1
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: 2014-11-06 00:00:00.000000000 Z
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.2
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