google-analytics-rails 1.1.0 → 1.1.1
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 +2 -2
- data/CHANGELOG.markdown +5 -0
- data/README.markdown +1 -1
- data/lib/google-analytics/events/event_renderer.rb +4 -9
- data/lib/google-analytics/rails/view_helpers.rb +3 -0
- data/lib/google-analytics/version.rb +1 -1
- data/test/async_tracking_queue_test.rb +12 -12
- data/test/event_collection_renderer_test.rb +11 -2
- data/test/event_renderer_test.rb +4 -4
- data/test/rails/views_helper_test.rb +31 -31
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9237482619d3cc567f0190f9279b949e45671bc
|
4
|
+
data.tar.gz: c32c4208d568145c4e6ca07f22f5fa0960e97824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0960adf90b52e1bf2a4dc5e6f6c879d1ba98870acfcc4d781f4c1b7d78be189ababa7ab492be31199d7853708591790103c304ce61f38695f8e6386f2c62b8e8'
|
7
|
+
data.tar.gz: f77d3211e125e777488d5897a006651cc89151e2b7ac0467ddef1ec811d74c350991cc106985964a90b4af120f7d799b68427cc54c44273cc95a0284075e2381
|
data/.travis.yml
CHANGED
@@ -3,12 +3,12 @@ bundler_args: --without development
|
|
3
3
|
before_install:
|
4
4
|
- gem update bundler
|
5
5
|
rvm:
|
6
|
-
- 1.9.2
|
7
6
|
- 1.9.3
|
8
7
|
- 2.0.0
|
9
8
|
- 2.1
|
10
9
|
- 2.2.1
|
11
10
|
- 2.3.0
|
11
|
+
- 2.4.0
|
12
12
|
- rbx-2
|
13
13
|
- ruby-head
|
14
14
|
matrix:
|
@@ -23,4 +23,4 @@ matrix:
|
|
23
23
|
- rvm: jruby-head
|
24
24
|
- rvm: rbx-2
|
25
25
|
- rvm: ruby-head
|
26
|
-
fast_finish: true
|
26
|
+
fast_finish: true
|
data/CHANGELOG.markdown
CHANGED
data/README.markdown
CHANGED
@@ -11,23 +11,18 @@ module GoogleAnalytics
|
|
11
11
|
|
12
12
|
def to_s
|
13
13
|
if @event.class.name == 'GoogleAnalytics::Events::SetupAnalytics'
|
14
|
-
|
14
|
+
%{ga("#{@event.action}",#{array_to_json([@event.name, *@event.params])});}
|
15
15
|
elsif @event.single_event?
|
16
|
-
|
16
|
+
%{ga("#{@tracker_id ? [@tracker_id, @event.action].join('.') : @event.action}");}
|
17
17
|
else
|
18
|
-
|
18
|
+
%{ga("#{@tracker_id ? [@tracker_id, @event.action].join('.') : @event.action}",#{array_to_json([@event.name, *@event.params])});}
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def array_to_json(array)
|
25
|
-
array.map {|
|
26
|
-
end
|
27
|
-
|
28
|
-
def string_to_json(string)
|
29
|
-
# replace double quotes with single ones
|
30
|
-
string.to_json.gsub(/^"/, "'").gsub(/"$/, "'")
|
25
|
+
array.map {|val| val.to_json } .join(',')
|
31
26
|
end
|
32
27
|
end
|
33
28
|
end
|
@@ -11,10 +11,10 @@ class AsyncTrackingQueueTest < Test::Unit::TestCase
|
|
11
11
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
12
12
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
13
13
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
14
|
-
ga(
|
15
|
-
ga(
|
16
|
-
ga(
|
17
|
-
ga(
|
14
|
+
ga("send","event",1);
|
15
|
+
ga("send","event",2);
|
16
|
+
ga("t2.send","event",1);
|
17
|
+
ga("t2.send","event",2);
|
18
18
|
</script>
|
19
19
|
JAVASCRIPT
|
20
20
|
|
@@ -37,10 +37,10 @@ ga('t2.send','event',2);
|
|
37
37
|
# VALID_DOUBLECLICK_SNIPPET = <<-JAVASCRIPT
|
38
38
|
# <script type="text/javascript">
|
39
39
|
# var _gaq = _gaq || [];
|
40
|
-
# _gaq.push([
|
41
|
-
# _gaq.push([
|
42
|
-
# _gaq.push([
|
43
|
-
# _gaq.push([
|
40
|
+
# _gaq.push(["event1",1]);
|
41
|
+
# _gaq.push(["event2",2]);
|
42
|
+
# _gaq.push(["t2.event1",1]);
|
43
|
+
# _gaq.push(["t2.event2",2]);
|
44
44
|
# (function() {
|
45
45
|
# var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
46
46
|
# ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
|
@@ -70,10 +70,10 @@ ga('t2.send','event',2);
|
|
70
70
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
71
71
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
72
72
|
})(window,document,'script','http://127.0.0.1/custom.js','ga');
|
73
|
-
ga(
|
74
|
-
ga(
|
75
|
-
ga(
|
76
|
-
ga(
|
73
|
+
ga("send","event",1);
|
74
|
+
ga("send","event",2);
|
75
|
+
ga("t2.send","event",1);
|
76
|
+
ga("t2.send","event",2);
|
77
77
|
</script>
|
78
78
|
JAVASCRIPT
|
79
79
|
|
@@ -8,7 +8,16 @@ class EventCollectionRendererTest < Test::Unit::TestCase
|
|
8
8
|
event_collection << GA::Event.new('send', 'evt', '3')
|
9
9
|
|
10
10
|
ecr = GA::EventCollectionRenderer.new(event_collection, nil)
|
11
|
-
assert_equal(
|
11
|
+
assert_equal(%{ga("send","evt","1");\nga("send","evt","2");\nga("send","evt","3");}, ecr.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_event_collection_renderer_escapes_quotes
|
15
|
+
event_collection = GA::EventCollection.new
|
16
|
+
event_collection << GA::Event.new('send', 'evt', "foo'sbar")
|
17
|
+
event_collection << GA::Event.new('send', 'evt', "foo\"sbar")
|
18
|
+
|
19
|
+
ecr = GA::EventCollectionRenderer.new(event_collection, nil)
|
20
|
+
assert_equal(%{ga("send","evt","foo'sbar");\nga("send","evt","foo\\"sbar");}, ecr.to_s)
|
12
21
|
end
|
13
22
|
|
14
23
|
def test_event_collection_renderer_yield_proper_javascript_snippit_for_custom_tracker
|
@@ -18,6 +27,6 @@ class EventCollectionRendererTest < Test::Unit::TestCase
|
|
18
27
|
event_collection << GA::Event.new('send', 'evt', 3)
|
19
28
|
|
20
29
|
ecr = GA::EventCollectionRenderer.new(event_collection, 't2')
|
21
|
-
assert_equal(
|
30
|
+
assert_equal(%{ga("t2.send","evt",1);\nga("t2.send","evt",2);\nga("t2.send","evt",3);}, ecr.to_s)
|
22
31
|
end
|
23
32
|
end
|
data/test/event_renderer_test.rb
CHANGED
@@ -3,12 +3,12 @@ require 'test_helper'
|
|
3
3
|
class EventRendererTest < Test::Unit::TestCase
|
4
4
|
def test_event_renderer_yield_proper_javascript_snippit_for_default_tracker
|
5
5
|
er = GA::EventRenderer.new(GA::Event.new('send', 'something', 1, 2, 3), nil)
|
6
|
-
assert_equal(
|
6
|
+
assert_equal(%{ga("send","something",1,2,3);}, er.to_s)
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_event_renderer_yield_proper_javascript_snippit_for_custom_tracker
|
10
10
|
er = GA::EventRenderer.new(GA::Event.new('send', 'something', 1, 2, 3), 't2')
|
11
|
-
assert_equal(
|
11
|
+
assert_equal(%{ga("t2.send","something",1,2,3);}, er.to_s)
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_event_renderer_yield_proper_javascript_snippit_for_custom_tracker_creation
|
@@ -19,10 +19,10 @@ class EventRendererTest < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
def test_single_event_renderer_yield_proper_javascript_snippit_for_transaction_send
|
21
21
|
er = GA::EventRenderer.new(GA::Events::Ecommerce::TrackTransaction.new, nil)
|
22
|
-
assert_equal(
|
22
|
+
assert_equal(%{ga("ecommerce:send");}, er.to_s)
|
23
23
|
end
|
24
24
|
def test_single_event_renderer_yield_proper_javascript_snippit_for_transaction_send_with_custom_tracker
|
25
25
|
er = GA::EventRenderer.new(GA::Events::Ecommerce::TrackTransaction.new, 't2')
|
26
|
-
assert_equal(
|
26
|
+
assert_equal(%{ga("t2.ecommerce:send");}, er.to_s)
|
27
27
|
end
|
28
28
|
end
|
@@ -17,8 +17,8 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
17
17
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
18
18
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
19
19
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
20
|
-
ga(
|
21
|
-
ga(
|
20
|
+
ga("create","TEST","auto");
|
21
|
+
ga("send","pageview");
|
22
22
|
</script>
|
23
23
|
JAVASCRIPT
|
24
24
|
|
@@ -29,24 +29,24 @@ ga('send','pageview');
|
|
29
29
|
def test_analytics_init_with_special_name
|
30
30
|
str = analytics_init(:name => 't2').to_s
|
31
31
|
assert(str.include?(VALID_JS_INCLUDE))
|
32
|
-
assert_match(/.+ga\(
|
32
|
+
assert_match(/.+ga\("create","TEST",\{.+\}\);.+/m, str)
|
33
33
|
assert_match(/.+"cookieDomain":"auto".+/m, str)
|
34
34
|
assert_match(/.+"name":"t2".+/m, str)
|
35
|
-
assert_match(/.+ga\(
|
35
|
+
assert_match(/.+ga\("t2.send","pageview"\);.+/m, str)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_analytics_init_with_virtual_pageview
|
39
39
|
str = analytics_init(:page => '/some/virtual/url').to_s
|
40
40
|
assert(str.include?(VALID_JS_INCLUDE))
|
41
|
-
assert_match(/.+ga\(
|
42
|
-
assert_match(/.+ga\(
|
41
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
42
|
+
assert_match(/.+ga\("send","pageview","\/some\/virtual\/url"\);.+/m, str)
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_analytics_init_with_virtual_pageview_and_custom_title
|
46
46
|
str = analytics_init(:page => '/some/virtual/url', :title => 'Hello World').to_s
|
47
47
|
assert(str.include?(VALID_JS_INCLUDE))
|
48
|
-
assert_match(/.+ga\(
|
49
|
-
assert_match(/.+ga\(
|
48
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
49
|
+
assert_match(/.+ga\("send","pageview".+/m, str)
|
50
50
|
assert_match(/.+"page":"\/some\/virtual\/url".+/m, str)
|
51
51
|
assert_match(/.+"title":"Hello World".+/m, str)
|
52
52
|
end
|
@@ -54,77 +54,77 @@ ga('send','pageview');
|
|
54
54
|
def test_analytics_init_with_custom_tracker
|
55
55
|
str = analytics_init(:tracker => 'UA-CUSTOM-XX').to_s
|
56
56
|
assert(str.include?(VALID_JS_INCLUDE))
|
57
|
-
assert_match(/.+ga\(
|
58
|
-
assert_match(/.+ga\(
|
57
|
+
assert_match(/.+ga\("create","UA-CUSTOM-XX","auto"\);.+/m, str)
|
58
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_analytics_init_with_custom_domain
|
62
62
|
str = analytics_init(:domain => 'example.com').to_s
|
63
63
|
assert(str.include?(VALID_JS_INCLUDE))
|
64
|
-
assert_match(/.+ga\(
|
65
|
-
assert_match(/.+ga\(
|
64
|
+
assert_match(/.+ga\("create","TEST",\{"cookieDomain":"example.com"\}\);.+/m, str)
|
65
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_local_analytics_init
|
69
69
|
str = analytics_init(:local => true).to_s
|
70
70
|
assert(str.include?(VALID_JS_INCLUDE))
|
71
|
-
assert_match(/.+ga\(
|
71
|
+
assert_match(/.+ga\("create","TEST",\{.+\}\);.+/m, str)
|
72
72
|
assert_match(/.+"cookieDomain":"none".+/m, str)
|
73
73
|
assert_match(/.+"allowLinker":true.+/m, str)
|
74
|
-
assert_match(/.+ga\(
|
74
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_analytics_init_with_anonymized_ip
|
78
78
|
str = analytics_init(:anonymize => true).to_s
|
79
79
|
assert(str.include?(VALID_JS_INCLUDE))
|
80
|
-
assert_match(/.+ga\(
|
81
|
-
assert_match(/.+ga\(
|
82
|
-
assert_match(/.+ga\(
|
80
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
81
|
+
assert_match(/.+ga\("set","anonymizeIp",true\);.+/m, str)
|
82
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_analytics_init_with_link_attribution
|
86
86
|
str = analytics_init(:enhanced_link_attribution => true).to_s
|
87
87
|
assert(str.include?(VALID_JS_INCLUDE))
|
88
|
-
assert_match(/.+ga\(
|
89
|
-
assert_match(/.+ga\(
|
90
|
-
assert_match(/.+ga\(
|
88
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
89
|
+
assert_match(/.+ga\("require","linkid"\);.+/m, str)
|
90
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_analytics_init_with_events
|
94
94
|
str = analytics_init(:add_events => GA::Events::SetAllowLinker.new(true)).to_s
|
95
95
|
assert(str.include?(VALID_JS_INCLUDE))
|
96
|
-
assert_match(/.+ga\(
|
96
|
+
assert_match(/.+ga\("create","TEST",\{.+\}\);.+/m, str)
|
97
97
|
assert_match(/.+"cookieDomain":"auto".+/m, str)
|
98
98
|
assert_match(/.+"allowLinker":true.+/m, str)
|
99
|
-
assert_match(/.+ga\(
|
99
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
100
100
|
end
|
101
101
|
|
102
102
|
def test_analytics_init_with_samplerate_events
|
103
103
|
str = analytics_init(:add_events => GA::Events::SetSiteSpeedSampleRate.new(5)).to_s
|
104
104
|
assert(str.include?(VALID_JS_INCLUDE))
|
105
|
-
assert_match(/.+ga\(
|
105
|
+
assert_match(/.+ga\("create","TEST",\{.+\}\);.+/m, str)
|
106
106
|
assert_match(/.+"cookieDomain":"auto".+/m, str)
|
107
107
|
assert_match(/.+"siteSpeedSampleRate":5.+/m, str)
|
108
|
-
assert_match(/.+ga\(
|
108
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_analytics_init_with_custom_vars
|
112
112
|
str = analytics_init(:custom_vars => GA::Events::SetCustomVar.new(1, 'test', 'hoge',1)).to_s
|
113
113
|
assert(str.include?(VALID_JS_INCLUDE))
|
114
|
-
assert_match(/.+ga\(
|
115
|
-
assert_match(/.+ga\(
|
116
|
-
assert_match(/.+ga\(
|
114
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
115
|
+
assert_match(/.+ga\("set","dimension1","hoge"\);.+/m, str)
|
116
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
117
117
|
end
|
118
118
|
|
119
119
|
def test_analytics_init_with_custom_dimension
|
120
120
|
str = analytics_init(:custom_vars => GA::Events::SetCustomDimension.new(1, 'hoge')).to_s
|
121
121
|
assert(str.include?(VALID_JS_INCLUDE))
|
122
|
-
assert_match(/.+ga\(
|
123
|
-
assert_match(/.+ga\(
|
124
|
-
assert_match(/.+ga\(
|
122
|
+
assert_match(/.+ga\("create","TEST","auto"\);.+/m, str)
|
123
|
+
assert_match(/.+ga\("set","dimension1","hoge"\);.+/m, str)
|
124
|
+
assert_match(/.+ga\("send","pageview"\);.+/m, str)
|
125
125
|
end
|
126
126
|
|
127
|
-
VALID_TRACK_EVENT =
|
127
|
+
VALID_TRACK_EVENT = %{ga("send","event","Videos","Play","Gone With the Wind",null);}
|
128
128
|
|
129
129
|
def test_analytics_track_event
|
130
130
|
event = analytics_track_event("Videos", "Play", "Gone With the Wind")
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoit Garret
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Rails helpers to manage google analytics tracking
|
15
15
|
email:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.5.2
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Rails helpers to manage google analytics tracking
|