google-analytics-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70b6e1110fba9b2d091febdb2d912910f21ccc5d
4
- data.tar.gz: 5035c20f6adb7e9b8b26e8910cc3bc11eb042b58
3
+ metadata.gz: d1026e04facb047892c44b293f01e87c63af110c
4
+ data.tar.gz: 052fff54d9f1dc5dcb2b9972764bfaac52492f18
5
5
  SHA512:
6
- metadata.gz: e335e89f26431aa80ca0f0343625c5fe9a7bab1ee118455fbf9bd5212d2a09b1ed40082735d91185c1384d8807f6cd9c432e411a11106f27009f8de3e21e5b61
7
- data.tar.gz: 14afca1b8c06c2813c679f80083f8413934b7d3d51408d5960bbf2dd80bec15f3b4d45881bf15386f61e5d34f15a810c824bad7a18826d1720ec33f5dc693909
6
+ metadata.gz: 011c446e38f25ca1fdb7b1eb1079fd584fdca5d79b1ff6141d6943c24d8caf802772241f38af6a3a888db0e25180b8b162146104dbf64d8a0cbfb6f172b4aec0
7
+ data.tar.gz: c4b798ef8c48bff11a32a9c0f33f4830312fe84560fe0c72ac138abff89c212d83f4306cd03237f6c9c6f5e5708a0c624dfd728af93bab3e040e32f284b8708e
@@ -1,11 +1,14 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
+ before_install:
4
+ - gem update bundler
3
5
  rvm:
4
- - 1.8.7
5
6
  - 1.9.2
6
7
  - 1.9.3
7
8
  - 2.0.0
8
9
  - 2.1
10
+ - 2.2.1
11
+ - 2.3.0
9
12
  - rbx-2
10
13
  - ruby-head
11
14
  matrix:
@@ -1,3 +1,16 @@
1
+ 1.1.0
2
+ =====
3
+
4
+ * Added User ID Options [PR#30](https://github.com/bgarret/google-analytics-rails/pull/30)
5
+ * Added Premium Account flag [PR#31](https://github.com/bgarret/google-analytics-rails/pull/31)
6
+ * Added Custom Metrics & Dimensions 0-20/0-200 [PR#31](https://github.com/bgarret/google-analytics-rails/pull/31)
7
+ * Removed support for Ruby 1.8.7
8
+
9
+ 1.0.0
10
+ =====
11
+
12
+ * Moved to Universal Analytics
13
+
1
14
  0.0.6
2
15
  =====
3
16
 
data/Gemfile CHANGED
@@ -15,6 +15,7 @@ end
15
15
 
16
16
  group :test do
17
17
  gem 'json'
18
+ gem 'test-unit'
18
19
  end
19
20
 
20
21
  # Specify your gem's dependencies in google-analytics-rails.gemspec
@@ -9,7 +9,7 @@ Installation
9
9
 
10
10
  Add the following to your `Gemfile`:
11
11
 
12
- gem 'google-analytics-rails', '1.0.0'
12
+ gem 'google-analytics-rails', '1.1.0'
13
13
 
14
14
  Then run:
15
15
 
@@ -52,11 +52,11 @@ Production only
52
52
  `config/environments/production.rb`:
53
53
 
54
54
  # replace this with your tracker code
55
- GA.tracker = "UA-xxxxxx-x"
55
+ GA.tracker = "UA-112233-4"
56
56
 
57
57
  `app/views/layout/application.html.erb`, in the `<head>` tag :
58
58
 
59
- <%= analytics_init if Rails.env.production? %>
59
+ <%= analytics_init if GoogleAnalytics.valid_tracker? %>
60
60
 
61
61
  With DoubleClick instead of vanilla Google Analytics script
62
62
  -----------------------------------------------------------
@@ -64,29 +64,40 @@ With DoubleClick instead of vanilla Google Analytics script
64
64
  `config/environments/production.rb`:
65
65
 
66
66
  # replace this with your tracker code
67
- GA.tracker = "UA-xxxxxx-x"
67
+ GA.tracker = "UA-556677-8"
68
68
  GA.script_source = :doubleclick
69
69
 
70
70
  `app/views/layout/application.html.erb`, in the `<head>` tag :
71
71
 
72
- <%= analytics_init if Rails.env.production? %>
72
+ <%= analytics_init if GoogleAnalytics.valid_tracker? %>
73
73
 
74
- Different accounts for development and production
74
+ Different accounts for staging and production
75
75
  -------------------------------------------------
76
76
 
77
77
  `config/environments/production.rb`:
78
78
 
79
79
  # replace this with your production tracker code
80
- GA.tracker = "UA-xxxxxx-x"
80
+ GA.tracker = "UA-990011-2"
81
81
 
82
- `config/environments/development.rb`:
82
+ `config/environments/staging.rb`:
83
83
 
84
- # replace this with your development tracker code
85
- GA.tracker = "UA-xxxxxx-x"
84
+ # replace this with your staging tracker code
85
+ GA.tracker = "UA-334455-66"
86
86
 
87
87
  `app/views/layout/application.html.erb`, in the `<head>` tag :
88
88
 
89
- <%= analytics_init :local => Rails.env.development? %>
89
+ <%= analytics_init if GoogleAnalytics.valid_tracker? %>
90
+
91
+ Premium Google Analytics accounts
92
+ ---------------------------------
93
+
94
+ `config/environments/production.rb`:
95
+
96
+ # add this if you have a premium account and need to use the additional dimension/metric indices
97
+ # - premium accounts are allowed to have 200 custom dimensions/metrics
98
+ # - regular accounts are allowed 20
99
+ # see also: https://support.google.com/analytics/answer/2709828?hl=en#Limits
100
+ GA.premium_account = true
90
101
 
91
102
  License
92
103
  =======
@@ -3,19 +3,16 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "google-analytics/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "google-analytics-rails"
7
- s.version = GoogleAnalytics::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Benoit Garret", "Ufuk Kayserilioglu"]
10
- s.email = ["benoit.garret@gadz.org", "ufuk@paralaus.com"]
11
- s.homepage = "https://github.com/bgarret/google-analytics-rails"
12
- s.summary = %q{Rails 3 helpers to manage google analytics tracking}
13
- s.description = %q{Rails 3 helpers to manage google analytics tracking}
14
-
15
- s.rubyforge_project = "google-analytics-rails"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
6
+ s.name = "google-analytics-rails"
7
+ s.version = GoogleAnalytics::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benoit Garret", "Ufuk Kayserilioglu"]
10
+ s.email = ["benoit.garret@gadz.org", "ufuk@paralaus.com"]
11
+ s.homepage = "https://github.com/bgarret/google-analytics-rails"
12
+ s.summary = %q{Rails helpers to manage google analytics tracking}
13
+ s.description = %q{Rails helpers to manage google analytics tracking}
14
+ s.required_ruby_version = '>= 1.9.3'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
17
+ s.require_paths = ["lib"]
21
18
  end
@@ -15,6 +15,10 @@ module GoogleAnalytics
15
15
  :default => "'//www.google-analytics.com/analytics.js'",
16
16
  :doubleclick => "'//stats.g.doubleclick.net/dc.js'",
17
17
  }
18
+ # @private
19
+ MAX_REGULAR_INDICES = 20
20
+ # @private
21
+ MAX_PREMIUM_INDICES = 200
18
22
 
19
23
  # Get the current tracker id (*UA-xxxxxx-x*).
20
24
  # @return [String]
@@ -47,14 +51,26 @@ module GoogleAnalytics
47
51
  @@src = src
48
52
  end
49
53
  end
54
+
55
+ # @return [Boolean]
56
+ def self.premium_account?
57
+ @@premium_account ||= false
58
+ end
59
+
60
+ # Set whether or not the property is held under a premium account
61
+ # @param [Boolean]
62
+ def self.premium_account=(value)
63
+ @@premium_account = value
64
+ end
65
+
66
+ # Return the maximum number of custom dimension/metric indices for this type of account
67
+ # @return [Integer]
68
+ def self.max_custom_indices
69
+ premium_account? ? MAX_PREMIUM_INDICES : MAX_REGULAR_INDICES
70
+ end
50
71
  end
51
72
 
52
73
  # Alias for {GoogleAnalytics}
53
74
  GA = GoogleAnalytics
54
75
 
55
- if defined?(Rails)
56
- require 'google-analytics/rails/railtie'
57
-
58
- # Alias for {GoogleAnalytics::Rails}
59
- GAR = GoogleAnalytics::Rails
60
- end
76
+ require 'google-analytics/rails/railtie'
@@ -23,7 +23,8 @@ module GoogleAnalytics
23
23
  :cookieExpires => opts.delete(:cookieExpires),
24
24
  :sampleRate => opts.delete(:sampleRate),
25
25
  :siteSpeedSampleRate => opts.delete(:siteSpeedSampleRate),
26
- :name => opts.delete(:name)
26
+ :name => opts.delete(:name),
27
+ :userId => opts.delete(:userId) || opts.delete(:uid)
27
28
  }.reject{|k,v| !v }
28
29
  end
29
30
  end
@@ -124,13 +125,13 @@ module GoogleAnalytics
124
125
 
125
126
  class SetCustomDimension < Event
126
127
  def initialize(index, value)
127
- raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
128
+ raise ArgumentError, "The index has to be between 1 and #{GA.max_custom_indices}" unless (1..GA.max_custom_indices).include?(index.to_i)
128
129
  super('set', "dimension#{index}", value.to_s)
129
130
  end
130
131
  end
131
132
  class SetCustomMetric < Event
132
133
  def initialize(index, value)
133
- raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
134
+ raise ArgumentError, "The index has to be between 1 and #{GA.max_custom_indices}" unless (1..GA.max_custom_indices).include?(index.to_i)
134
135
  super('set', "metric#{index}", value.to_s)
135
136
  end
136
137
  end
@@ -1,12 +1,18 @@
1
1
  # coding: utf-8
2
+ begin
3
+ require 'rails/railtie'
4
+ rescue LoadError
5
+ else
6
+ require 'google-analytics/rails/view_helpers'
2
7
 
3
- require 'google-analytics/rails/view_helpers'
4
-
5
- module GoogleAnalytics::Rails
6
- # @private
7
- class Railtie < ::Rails::Railtie
8
- initializer "google-analytics-rails" do
9
- ActionView::Base.send :include, ViewHelpers
8
+ module GoogleAnalytics::Rails
9
+ # @private
10
+ class Railtie < ::Rails::Railtie
11
+ initializer 'google-analytics-rails' do
12
+ ActionView::Base.send :include, ViewHelpers
13
+ end
10
14
  end
11
15
  end
16
+ # Alias for {GoogleAnalytics::Rails}
17
+ GAR = GoogleAnalytics::Rails
12
18
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module GoogleAnalytics
4
4
  # Gem version
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
@@ -10,6 +10,7 @@ class EventRendererTest < Test::Unit::TestCase
10
10
  er = GA::EventRenderer.new(GA::Event.new('send', 'something', 1, 2, 3), 't2')
11
11
  assert_equal("ga('t2.send','something',1,2,3);", er.to_s)
12
12
  end
13
+
13
14
  def test_event_renderer_yield_proper_javascript_snippit_for_custom_tracker_creation
14
15
  er = GA::EventRenderer.new(GA::Events::SetupAnalytics.new('TEST', {:name => 't2'}), 't2')
15
16
  assert_match(Regexp.new('"cookieDomain":"auto"'), er.to_s)
@@ -1,6 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GAEventsTest < Test::Unit::TestCase
4
+ def setup
5
+ GA.premium_account = false
6
+ end
7
+
4
8
  def test_default_account_creation
5
9
  event = GA::Events::SetupAnalytics.new('ABC123')
6
10
  assert_equal('create', event.action)
@@ -13,6 +17,21 @@ class GAEventsTest < Test::Unit::TestCase
13
17
  assert_equal('ABC123', event.name)
14
18
  assert_equal([{:cookieDomain=>"example.com"}], event.params)
15
19
  end
20
+
21
+ def test_account_creation_with_user_id
22
+ event = GA::Events::SetupAnalytics.new('ABC123', {:cookieDomain => 'example.com', :userId => 10})
23
+ assert_equal('create', event.action)
24
+ assert_equal('ABC123', event.name)
25
+ assert_equal([{:cookieDomain=>"example.com", :userId => 10}], event.params)
26
+ end
27
+
28
+ def test_account_creation_with_using_uid_for_user
29
+ event = GA::Events::SetupAnalytics.new('ABC123', {:cookieDomain => 'example.com', :uid => 10})
30
+ assert_equal('create', event.action)
31
+ assert_equal('ABC123', event.name)
32
+ assert_equal([{:cookieDomain=>"example.com", :userId => 10}], event.params)
33
+ end
34
+
16
35
  def test_account_creation_with_no_cookie_domain
17
36
  event = GA::Events::SetupAnalytics.new('ABC123', 'none')
18
37
  assert_equal('create', event.action)
@@ -69,6 +88,25 @@ class GAEventsTest < Test::Unit::TestCase
69
88
  assert_equal(['Search', 'Executed', 'Son of Sam', 1], event.params)
70
89
  end
71
90
 
91
+ def test_max_custom_indices_regular
92
+ assert_equal(GA::MAX_REGULAR_INDICES, GA.max_custom_indices)
93
+ end
94
+
95
+ def test_premium_account_defaults_to_false
96
+ GA.premium_account = nil
97
+ assert_equal(false, GA.premium_account?)
98
+ end
99
+
100
+ def test_max_custom_indices_defaults_to_regular
101
+ GA.premium_account = nil
102
+ assert_equal(GA::MAX_REGULAR_INDICES, GA.max_custom_indices)
103
+ end
104
+
105
+ def test_max_custom_indices_premium
106
+ GA.premium_account = true
107
+ assert_equal(GA::MAX_PREMIUM_INDICES, GA.max_custom_indices)
108
+ end
109
+
72
110
  def test_set_custom_dimension
73
111
  event = GA::Events::SetCustomDimension.new(1, 2)
74
112
  assert_equal('set', event.action)
@@ -76,9 +114,29 @@ class GAEventsTest < Test::Unit::TestCase
76
114
  assert_equal(['2'], event.params)
77
115
  end
78
116
 
117
+ def test_set_max_custom_dimension
118
+ assert_nothing_raised do
119
+ GA::Events::SetCustomDimension.new(GA::MAX_REGULAR_INDICES, 1)
120
+ end
121
+ end
122
+
79
123
  def test_set_custom_dimension_with_invalid_index
80
124
  assert_raise ArgumentError do
81
- GA::Events::SetCustomDimension.new(6, 1)
125
+ GA::Events::SetCustomDimension.new(GA::MAX_REGULAR_INDICES + 1, 1)
126
+ end
127
+ end
128
+
129
+ def test_set_max_custom_dimension_premium_account
130
+ GA.premium_account = true
131
+ assert_nothing_raised do
132
+ GA::Events::SetCustomDimension.new(GA::MAX_PREMIUM_INDICES, 1)
133
+ end
134
+ end
135
+
136
+ def test_set_custom_dimension_with_invalid_index_premium_account
137
+ GA.premium_account = true
138
+ assert_raise ArgumentError do
139
+ GA::Events::SetCustomDimension.new(GA::MAX_PREMIUM_INDICES + 1, 1)
82
140
  end
83
141
  end
84
142
 
@@ -89,9 +147,29 @@ class GAEventsTest < Test::Unit::TestCase
89
147
  assert_equal(['2'], event.params)
90
148
  end
91
149
 
150
+ def test_set_max_custom_metric
151
+ assert_nothing_raised do
152
+ GA::Events::SetCustomMetric.new(GA::MAX_REGULAR_INDICES, 1)
153
+ end
154
+ end
155
+
92
156
  def test_set_custom_metric_with_invalid_index
93
157
  assert_raise ArgumentError do
94
- GA::Events::SetCustomMetric.new(6, 1)
158
+ GA::Events::SetCustomMetric.new(GA::MAX_REGULAR_INDICES + 1, 1)
159
+ end
160
+ end
161
+
162
+ def test_set_max_custom_metric_premium_account
163
+ GA.premium_account = true
164
+ assert_nothing_raised do
165
+ GA::Events::SetCustomDimension.new(GA::MAX_PREMIUM_INDICES, 1)
166
+ end
167
+ end
168
+
169
+ def test_set_custom_metric_with_invalid_index_premium_account
170
+ GA.premium_account = true
171
+ assert_raise ArgumentError do
172
+ GA::Events::SetCustomDimension.new(GA::MAX_PREMIUM_INDICES + 1, 1)
95
173
  end
96
174
  end
97
175
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-analytics-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Garret
@@ -9,9 +9,9 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-12 00:00:00.000000000 Z
12
+ date: 2016-02-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Rails 3 helpers to manage google analytics tracking
14
+ description: Rails helpers to manage google analytics tracking
15
15
  email:
16
16
  - benoit.garret@gadz.org
17
17
  - ufuk@paralaus.com
@@ -56,24 +56,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: 1.9.3
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubyforge_project: google-analytics-rails
66
+ rubyforge_project:
67
67
  rubygems_version: 2.4.8
68
68
  signing_key:
69
69
  specification_version: 4
70
- summary: Rails 3 helpers to manage google analytics tracking
71
- test_files:
72
- - test/async_tracking_queue_test.rb
73
- - test/event_collection_renderer_test.rb
74
- - test/event_collection_test.rb
75
- - test/event_renderer_test.rb
76
- - test/gaq_events_test.rb
77
- - test/rails/views_helper_test.rb
78
- - test/test_helper.rb
70
+ summary: Rails helpers to manage google analytics tracking
71
+ test_files: []
79
72
  has_rdoc: