google-analytics-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ 0.0.3
2
+ =====
3
+
4
+ * Fix #8, the directives were in the wrong order in development mode (thanks to @garnould).
5
+ * Add support for the `_anonymizeIp` event (thanks to @rmoriz).
6
+ * Add support for the `_deleteCustomVar` directive (thanks to @eirc).
7
+
8
+ 0.0.2
9
+ =====
10
+
11
+ * Documentation updates
12
+ * Custom variable support (thanks to @asm).
13
+ * `_setSiteSpeedSampleRate()` method support (thanks to @nikosd).
14
+ * Event collection `size` method (thanks to @brundage).
15
+
16
+ 0.0.1
17
+ =====
18
+
19
+ Initial release.
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "google-analytics-rails"
16
16
 
17
+ s.add_development_dependency "rake"
17
18
  s.add_development_dependency "yard"
18
19
  s.add_development_dependency "redcarpet"
19
20
  s.add_development_dependency "activesupport", "~>3.0"
@@ -47,10 +47,36 @@ module GoogleAnalytics
47
47
 
48
48
  class SetCustomVar < Event
49
49
  def initialize(index, name, value, opt_scope)
50
+ raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
50
51
  super('_setCustomVar', index.to_i, name.to_s, value.to_s, opt_scope.to_i)
51
52
  end
52
53
  end
53
54
 
55
+ class DeleteCustomVar < Event
56
+ def initialize(index)
57
+ raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
58
+ super('_deleteCustomVar', index.to_i)
59
+ end
60
+ end
61
+
62
+ # @see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gat#_gat._anonymizeIp
63
+ #
64
+ # Anonymize the visitor IP address. This seems to be mandatory for European websites and actively enforced
65
+ # for German ones.
66
+ #
67
+ # See the following comment by Roland Moriz for more information:
68
+ # https://github.com/bgarret/google-analytics-rails/pull/6#issuecomment-5946066
69
+ #
70
+ # JavaScript equivalent:
71
+ #
72
+ # _gaq.push(['_gat._anonymizeIp']);
73
+ #
74
+ class AnonymizeIp < Event
75
+ def initialize
76
+ super('_gat._anonymizeIp')
77
+ end
78
+ end
79
+
54
80
  # @see http://code.google.com/apis/analytics/docs/tracking/gaTrackingEcommerce.html
55
81
  module Ecommerce
56
82
  # JavaScript equivalent:
@@ -57,6 +57,10 @@ module GoogleAnalytics::Rails
57
57
  # The optional virtual page view to track through {GoogleAnalytics::Events::TrackPageview}
58
58
  # @option options [String] :tracker
59
59
  # The tracker to use instead of the default {GoogleAnalytics.tracker}
60
+ # @option options [Boolean] :anonymize
61
+ # Whether to anonymize the visitor ip or not.
62
+ # This is required for european websites and actively enforced for german ones,
63
+ # see {GoogleAnalytics::Events::AnonymizeIp}.
60
64
  #
61
65
  # @example Set the local bit in development mode
62
66
  # analytics_init :local => Rails.env.development?
@@ -73,6 +77,7 @@ module GoogleAnalytics::Rails
73
77
  end
74
78
 
75
79
  local = options.delete(:local) || false
80
+ anonymize = options.delete(:anonymize) || false
76
81
  events = options.delete(:add_events) || []
77
82
  events = [events] unless events.is_a?(Array)
78
83
 
@@ -80,12 +85,14 @@ module GoogleAnalytics::Rails
80
85
 
81
86
  # unshift => reverse order
82
87
  events.unshift GA::Events::TrackPageview.new(options[:page])
83
- events.unshift GA::Events::SetAccount.new(tracker)
84
-
88
+ # anonymize if needed before tracking the page view
89
+ events.unshift GA::Events::AnonymizeIp.new if anonymize
85
90
  if local
86
- events.push GA::Events::SetDomainName.new('none')
87
- events.push GA::Events::SetAllowLinker.new(true)
91
+ events.unshift GA::Events::SetDomainName.new('none')
92
+ events.unshift GA::Events::SetAllowLinker.new(true)
88
93
  end
94
+ events.unshift GA::Events::SetAccount.new(tracker)
95
+
89
96
 
90
97
  events.each do |event|
91
98
  queue << event
@@ -1,4 +1,4 @@
1
1
  module GoogleAnalytics
2
2
  # Gem version
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
@@ -61,6 +61,30 @@ class GAEventsTest < Test::Unit::TestCase
61
61
  assert_equal([1, 'VarName1', 'VarVal1', 1], event.params)
62
62
  end
63
63
 
64
+ def test_set_custom_var_with_invalid_index
65
+ assert_raise ArgumentError do
66
+ GA::Events::SetCustomVar.new(6, 'VarName1', 'VarVal1', 1)
67
+ end
68
+ end
69
+
70
+ def test_delete_custom_var
71
+ event = GA::Events::DeleteCustomVar.new(1)
72
+ assert_equal('_deleteCustomVar', event.name)
73
+ assert_equal([1], event.params)
74
+ end
75
+
76
+ def test_delete_custom_var_with_invalid_index
77
+ assert_raise ArgumentError do
78
+ GA::Events::DeleteCustomVar.new(6)
79
+ end
80
+ end
81
+
82
+ def test_anonymize_ip_event
83
+ event = GA::Events::AnonymizeIp.new
84
+ assert_equal('_gat._anonymizeIp', event.name)
85
+ assert_equal([], event.params)
86
+ end
87
+
64
88
  def test_ecommerce_add_transaction_event
65
89
  event = GA::Events::Ecommerce::AddTransaction.new(1, 'ACME', 123.45, 13.27, 75.35, 'Dallas', 'TX', 'USA')
66
90
  assert_equal('_addTrans', event.name)
@@ -59,9 +59,9 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga
59
59
  <script type="text/javascript">
60
60
  var _gaq = _gaq || [];
61
61
  _gaq.push(['_setAccount','TEST']);
62
- _gaq.push(['_trackPageview']);
63
- _gaq.push(['_setDomainName','none']);
64
62
  _gaq.push(['_setAllowLinker',true]);
63
+ _gaq.push(['_setDomainName','none']);
64
+ _gaq.push(['_trackPageview']);
65
65
  (function() {
66
66
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
67
67
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
@@ -74,6 +74,24 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga
74
74
  assert_equal(VALID_LOCAL_INIT, analytics_init(:local => true))
75
75
  end
76
76
 
77
+ VALID_INIT_WITH_ANONYMIZED_IP = <<-JAVASCRIPT
78
+ <script type="text/javascript">
79
+ var _gaq = _gaq || [];
80
+ _gaq.push(['_setAccount','TEST']);
81
+ _gaq.push(['_gat._anonymizeIp']);
82
+ _gaq.push(['_trackPageview']);
83
+ (function() {
84
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
85
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
86
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
87
+ })();
88
+ </script>
89
+ JAVASCRIPT
90
+
91
+ def test_analytics_init_with_anonymized_ip
92
+ assert_equal(VALID_INIT_WITH_ANONYMIZED_IP, analytics_init(:anonymize => true))
93
+ end
94
+
77
95
  VALID_EVENT_INIT = <<-JAVASCRIPT
78
96
  <script type="text/javascript">
79
97
  var _gaq = _gaq || [];
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: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000Z
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: yard
16
- requirement: &82570290 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
19
35
  - - ! '>='
@@ -21,10 +37,15 @@ dependencies:
21
37
  version: '0'
22
38
  type: :development
23
39
  prerelease: false
24
- version_requirements: *82570290
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
25
46
  - !ruby/object:Gem::Dependency
26
47
  name: redcarpet
27
- requirement: &82570070 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,10 +53,15 @@ dependencies:
32
53
  version: '0'
33
54
  type: :development
34
55
  prerelease: false
35
- version_requirements: *82570070
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: activesupport
38
- requirement: &82569800 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ~>
@@ -43,7 +69,12 @@ dependencies:
43
69
  version: '3.0'
44
70
  type: :development
45
71
  prerelease: false
46
- version_requirements: *82569800
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
47
78
  description: Rails helpers to manage google analytics tracking
48
79
  email:
49
80
  - benoit.garret@gadz.org
@@ -53,6 +84,7 @@ extra_rdoc_files: []
53
84
  files:
54
85
  - .gitignore
55
86
  - .yardopts
87
+ - CHANGELOG.markdown
56
88
  - Gemfile
57
89
  - README.markdown
58
90
  - Rakefile
@@ -95,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
127
  version: '0'
96
128
  requirements: []
97
129
  rubyforge_project: google-analytics-rails
98
- rubygems_version: 1.8.10
130
+ rubygems_version: 1.8.24
99
131
  signing_key:
100
132
  specification_version: 3
101
133
  summary: Rails helpers to manage google analytics tracking