middleman-google-analytics 1.0.2 → 1.1.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 +3 -3
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +2 -3
- data/features/google_analytics.feature +123 -0
- data/features/{universal.feature → google_analytics_universal.feature} +32 -92
- data/fixtures/across-a-domain-app/config.rb +4 -0
- data/fixtures/{test-app-universal/source/index.html.erb → across-a-domain-app/source/google-analytics-universal.html.erb} +0 -0
- data/fixtures/{test-app/source/index.html.erb → across-a-domain-app/source/google-analytics.html.erb} +0 -0
- data/fixtures/across-multiple-domains-app/config.rb +5 -0
- data/fixtures/across-multiple-domains-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/across-multiple-domains-app/source/google-analytics.html.erb +1 -0
- data/fixtures/anonymize-ip-app/config.rb +4 -0
- data/fixtures/anonymize-ip-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/anonymize-ip-app/source/google-analytics.html.erb +1 -0
- data/fixtures/basic-app/config.rb +3 -0
- data/fixtures/basic-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/basic-app/source/google-analytics.html.erb +1 -0
- data/fixtures/compress-js-app/config.rb +4 -0
- data/fixtures/compress-js-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/compress-js-app/source/google-analytics.html.erb +1 -0
- data/fixtures/debug-app/config.rb +4 -0
- data/fixtures/debug-app/source/google-analytics.html.erb +1 -0
- data/fixtures/disable-app/config.rb +4 -0
- data/fixtures/disable-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/disable-app/source/google-analytics.html.erb +1 -0
- data/fixtures/full-app/config.rb +9 -0
- data/fixtures/full-app/source/google-analytics-universal.html.erb +1 -0
- data/fixtures/full-app/source/google-analytics.html.erb +1 -0
- data/lib/middleman-google-analytics/analytics.js.erb +1 -3
- data/lib/middleman-google-analytics/extension.rb +10 -17
- data/lib/middleman-google-analytics/ga.js.erb +1 -3
- data/lib/middleman-google-analytics/helpers.rb +29 -0
- data/lib/middleman-google-analytics/version.rb +1 -1
- metadata +31 -9
- data/features/helper.feature +0 -191
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a51b2ac371e8473750df8ecd42cc01e50a2ccfff
|
|
4
|
+
data.tar.gz: 4f8721f1ca33bdffecdc0da50645bfa418f8a8b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 868b3bd4f25e4cb9655f55b78abb46a9e384f535cf7711e4d345bf536136b49b99850c181c2c0d6ae102e843774abbc8cfbe8813c0d09a8f19cdf8aafa6411bb
|
|
7
|
+
data.tar.gz: e7f1f30c3975d168d1c9c9d710c087c590bde2f45fa0daed5362611e53e35141cfbb4801b393d32f37b3e9b0604b2cb26576c50a1307c0c8a1e883a401535ecc
|
data/.travis.yml
CHANGED
|
@@ -2,17 +2,17 @@ language: ruby
|
|
|
2
2
|
|
|
3
3
|
rvm:
|
|
4
4
|
- ruby-head
|
|
5
|
-
- 2.
|
|
5
|
+
- 2.2.0
|
|
6
|
+
- 2.1.5
|
|
6
7
|
- 2.0.0
|
|
7
8
|
- 1.9.3
|
|
8
9
|
- jruby-19mode
|
|
9
10
|
|
|
10
|
-
# Bug in jRuby w/ Rouge: https://github.com/jruby/jruby/issues/1392
|
|
11
11
|
matrix:
|
|
12
12
|
allow_failures:
|
|
13
13
|
- rvm: ruby-head
|
|
14
14
|
- rvm: jruby-19mode
|
|
15
15
|
|
|
16
|
-
script:
|
|
16
|
+
script: bundle exec rake test
|
|
17
17
|
|
|
18
18
|
env: TEST=true
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Feature: Google Analytics tag helper
|
|
2
|
+
|
|
3
|
+
Scenario: Basic tracking code
|
|
4
|
+
Given the Server is running at "basic-app"
|
|
5
|
+
When I go to "/google-analytics.html"
|
|
6
|
+
Then I should see:
|
|
7
|
+
"""
|
|
8
|
+
<script type="text/javascript">
|
|
9
|
+
var _gaq = _gaq || [];
|
|
10
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
11
|
+
_gaq.push(["_trackPageview"]);
|
|
12
|
+
(function() {
|
|
13
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
14
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
15
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
16
|
+
})();
|
|
17
|
+
</script>
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
Scenario: On debug mode
|
|
21
|
+
Given the Server is running at "debug-app"
|
|
22
|
+
When I go to "/google-analytics.html"
|
|
23
|
+
Then I should see:
|
|
24
|
+
"""
|
|
25
|
+
<script type="text/javascript">
|
|
26
|
+
var _gaq = _gaq || [];
|
|
27
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
28
|
+
_gaq.push(["_trackPageview"]);
|
|
29
|
+
(function() {
|
|
30
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
31
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/u/ga_debug.js';
|
|
32
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
33
|
+
})();
|
|
34
|
+
</script>
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
Scenario: Tracking across a domain and its subdomains
|
|
38
|
+
Given the Server is running at "across-a-domain-app"
|
|
39
|
+
When I go to "/google-analytics.html"
|
|
40
|
+
Then I should see:
|
|
41
|
+
"""
|
|
42
|
+
<script type="text/javascript">
|
|
43
|
+
var _gaq = _gaq || [];
|
|
44
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
45
|
+
_gaq.push(["_setDomainName", "example.com"]);
|
|
46
|
+
_gaq.push(["_trackPageview"]);
|
|
47
|
+
(function() {
|
|
48
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
49
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
50
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
51
|
+
})();
|
|
52
|
+
</script>
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
Scenario: Tracking across multiple domains and subdomains
|
|
56
|
+
Given the Server is running at "across-multiple-domains-app"
|
|
57
|
+
When I go to "/google-analytics.html"
|
|
58
|
+
Then I should see:
|
|
59
|
+
"""
|
|
60
|
+
<script type="text/javascript">
|
|
61
|
+
var _gaq = _gaq || [];
|
|
62
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
63
|
+
_gaq.push(["_setDomainName", "example.com"]);
|
|
64
|
+
_gaq.push(["_setAllowLinker", true]);
|
|
65
|
+
_gaq.push(["_trackPageview"]);
|
|
66
|
+
(function() {
|
|
67
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
68
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
69
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
70
|
+
})();
|
|
71
|
+
</script>
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
Scenario: Removing the last octet of the IP address
|
|
75
|
+
Given the Server is running at "anonymize-ip-app"
|
|
76
|
+
When I go to "/google-analytics.html"
|
|
77
|
+
Then I should see:
|
|
78
|
+
"""
|
|
79
|
+
<script type="text/javascript">
|
|
80
|
+
var _gaq = _gaq || [];
|
|
81
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
82
|
+
_gaq.push(["_gat._anonymizeIp"]);
|
|
83
|
+
_gaq.push(["_trackPageview"]);
|
|
84
|
+
(function() {
|
|
85
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
86
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
87
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
88
|
+
})();
|
|
89
|
+
</script>
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
Scenario: Disable tracking in development environment
|
|
93
|
+
Given the Server is running at "disable-app"
|
|
94
|
+
When I go to "/google-analytics.html"
|
|
95
|
+
Then I should see ""
|
|
96
|
+
But I should not see:
|
|
97
|
+
"""
|
|
98
|
+
<script type="text/javascript">
|
|
99
|
+
var _gaq = _gaq || [];
|
|
100
|
+
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
101
|
+
(function() {
|
|
102
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
103
|
+
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
104
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
105
|
+
})();
|
|
106
|
+
</script>
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
Scenario: Compress the JavaScript code
|
|
110
|
+
Given the Server is running at "compress-js-app"
|
|
111
|
+
When I go to "/google-analytics.html"
|
|
112
|
+
Then I should see:
|
|
113
|
+
"""
|
|
114
|
+
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-123456-78"]),_gaq.push(["_trackPageview"]),function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"==document.location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();</script>
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
Scenario: Full options
|
|
118
|
+
Given the Server is running at "full-app"
|
|
119
|
+
When I go to "/google-analytics.html"
|
|
120
|
+
Then I should see:
|
|
121
|
+
"""
|
|
122
|
+
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-123456-78"]),_gaq.push(["_setDomainName","example.com"]),_gaq.push(["_setAllowLinker",!0]),_gaq.push(["_gat._anonymizeIp"]),_gaq.push(["_trackPageview"]),function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"//ssl":"//www")+".google-analytics.com/u/ga_debug.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}();</script>
|
|
123
|
+
"""
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
Feature: Google Analytics
|
|
1
|
+
Feature: Google Analytics Universal tag helper
|
|
2
2
|
|
|
3
3
|
Scenario: Basic tracking code
|
|
4
|
-
Given
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
activate :google_analytics do |ga|
|
|
8
|
-
ga.tracking_id = 'UA-123456-78'
|
|
9
|
-
end
|
|
10
|
-
"""
|
|
11
|
-
Given the Server is running at "test-app-universal"
|
|
12
|
-
When I go to "/"
|
|
13
|
-
Then I should see:
|
|
4
|
+
Given the Server is running at "basic-app"
|
|
5
|
+
When I go to "/google-analytics-universal.html"
|
|
6
|
+
Then I should see:
|
|
14
7
|
"""
|
|
15
8
|
<script type="text/javascript">
|
|
16
9
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
@@ -23,17 +16,9 @@ Feature: Google Analytics universal tag helper
|
|
|
23
16
|
"""
|
|
24
17
|
|
|
25
18
|
Scenario: Tracking across a domain and its subdomains
|
|
26
|
-
Given
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
activate :google_analytics do |ga|
|
|
30
|
-
ga.tracking_id = 'UA-123456-78'
|
|
31
|
-
ga.domain_name = 'example.com'
|
|
32
|
-
end
|
|
33
|
-
"""
|
|
34
|
-
Given the Server is running at "test-app-universal"
|
|
35
|
-
When I go to "/"
|
|
36
|
-
Then I should see:
|
|
19
|
+
Given the Server is running at "across-a-domain-app"
|
|
20
|
+
When I go to "/google-analytics-universal.html"
|
|
21
|
+
Then I should see:
|
|
37
22
|
"""
|
|
38
23
|
<script type="text/javascript">
|
|
39
24
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
@@ -46,18 +31,9 @@ Feature: Google Analytics universal tag helper
|
|
|
46
31
|
"""
|
|
47
32
|
|
|
48
33
|
Scenario: Tracking across multiple domains and subdomains
|
|
49
|
-
Given
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
activate :google_analytics do |ga|
|
|
53
|
-
ga.tracking_id = 'UA-123456-78'
|
|
54
|
-
ga.domain_name = 'example.com'
|
|
55
|
-
ga.allow_linker = true
|
|
56
|
-
end
|
|
57
|
-
"""
|
|
58
|
-
Given the Server is running at "test-app-universal"
|
|
59
|
-
When I go to "/"
|
|
60
|
-
Then I should see:
|
|
34
|
+
Given the Server is running at "across-multiple-domains-app"
|
|
35
|
+
When I go to "/google-analytics-universal.html"
|
|
36
|
+
Then I should see:
|
|
61
37
|
"""
|
|
62
38
|
<script type="text/javascript">
|
|
63
39
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
@@ -70,17 +46,9 @@ Feature: Google Analytics universal tag helper
|
|
|
70
46
|
"""
|
|
71
47
|
|
|
72
48
|
Scenario: Removing the last octet of the IP address
|
|
73
|
-
Given
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
activate :google_analytics do |ga|
|
|
77
|
-
ga.tracking_id = 'UA-123456-78'
|
|
78
|
-
ga.anonymize_ip = true
|
|
79
|
-
end
|
|
80
|
-
"""
|
|
81
|
-
Given the Server is running at "test-app-universal"
|
|
82
|
-
When I go to "/"
|
|
83
|
-
Then I should see:
|
|
49
|
+
Given the Server is running at "anonymize-ip-app"
|
|
50
|
+
When I go to "/google-analytics-universal.html"
|
|
51
|
+
Then I should see:
|
|
84
52
|
"""
|
|
85
53
|
<script type="text/javascript">
|
|
86
54
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
@@ -94,60 +62,32 @@ Feature: Google Analytics universal tag helper
|
|
|
94
62
|
"""
|
|
95
63
|
|
|
96
64
|
Scenario: Disable tracking in development environment
|
|
97
|
-
Given
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
111
|
-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
112
|
-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
113
|
-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
114
|
-
ga('create', 'UA-123456-78', 'auto');
|
|
115
|
-
</script>
|
|
116
|
-
"""
|
|
65
|
+
Given the Server is running at "disable-app"
|
|
66
|
+
When I go to "/google-analytics-universal.html"
|
|
67
|
+
Then I should see ""
|
|
68
|
+
But I should not see:
|
|
69
|
+
"""
|
|
70
|
+
<script type="text/javascript">
|
|
71
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
72
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
73
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
74
|
+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
75
|
+
ga('create', 'UA-123456-78', 'auto');
|
|
76
|
+
</script>
|
|
77
|
+
"""
|
|
117
78
|
|
|
118
79
|
Scenario: Compress the JavaScript code
|
|
119
|
-
Given
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
activate :google_analytics do |ga|
|
|
123
|
-
ga.tracking_id = 'UA-123456-78'
|
|
124
|
-
ga.minify = true
|
|
125
|
-
end
|
|
126
|
-
"""
|
|
127
|
-
Given the Server is running at "test-app-universal"
|
|
128
|
-
When I go to "/"
|
|
129
|
-
Then I should see:
|
|
80
|
+
Given the Server is running at "compress-js-app"
|
|
81
|
+
When I go to "/google-analytics-universal.html"
|
|
82
|
+
Then I should see:
|
|
130
83
|
"""
|
|
131
84
|
<script type="text/javascript">!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src=n,s.parentNode.insertBefore(o,s)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-123456-78","auto"),ga("send","pageview");</script>
|
|
132
85
|
"""
|
|
133
86
|
|
|
134
87
|
Scenario: Full options
|
|
135
|
-
Given
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
activate :google_analytics do |ga|
|
|
139
|
-
ga.tracking_id = 'UA-123456-78'
|
|
140
|
-
ga.domain_name = 'example.com'
|
|
141
|
-
ga.debug = true
|
|
142
|
-
ga.allow_linker = true
|
|
143
|
-
ga.anonymize_ip = true
|
|
144
|
-
ga.development = true
|
|
145
|
-
ga.minify = true
|
|
146
|
-
end
|
|
147
|
-
"""
|
|
148
|
-
Given the Server is running at "test-app-universal"
|
|
149
|
-
When I go to "/"
|
|
150
|
-
Then I should see:
|
|
88
|
+
Given the Server is running at "full-app"
|
|
89
|
+
When I go to "/google-analytics-universal.html"
|
|
90
|
+
Then I should see:
|
|
151
91
|
"""
|
|
152
92
|
<script type="text/javascript">!function(e,a,n,t,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(n),s=a.getElementsByTagName(n)[0],o.async=1,o.src=t,s.parentNode.insertBefore(o,s)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-123456-78","example.com",{allowLinker:!0}),ga("set","anonymizeIp",!0),ga("send","pageview");</script>
|
|
153
93
|
"""
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_universal_tag %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= google_analytics_tag %>
|
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
ga = []
|
|
7
7
|
ga << "ga('create', #{create_options.join(', ')});"
|
|
8
8
|
ga << "ga('set', 'anonymizeIp', true);" if @options.anonymize_ip
|
|
9
|
-
|
|
10
|
-
ga << "ga('send', 'pageview');"
|
|
11
|
-
end
|
|
9
|
+
ga << "ga('send', 'pageview');"
|
|
12
10
|
%>
|
|
13
11
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
14
12
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'middleman-google-analytics/helpers'
|
|
2
2
|
|
|
3
3
|
module Middleman
|
|
4
4
|
class GoogleAnalyticsExtension < Extension
|
|
@@ -20,32 +20,25 @@ module Middleman
|
|
|
20
20
|
def after_configuration
|
|
21
21
|
unless options.tracking_id
|
|
22
22
|
$stderr.puts 'Google Analytics: Please specify a property ID'
|
|
23
|
-
raise 'No property ID given'
|
|
23
|
+
raise 'No property ID given' if display?
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
if options.allow_linker and not options.domain_name
|
|
27
27
|
$stderr.puts 'Google Analytics: Please specify a domain_name when ' \
|
|
28
28
|
'using allow_linker'
|
|
29
|
-
raise 'No domain_name given'
|
|
29
|
+
raise 'No domain_name given' if display?
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
helpers do
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
file = File.join(File.dirname(__FILE__), 'ga.js.erb')
|
|
37
|
-
content = ERB.new(File.read(file)).result(binding)
|
|
38
|
-
content = Uglifier.compile(content) if google_analytics_settings.minify
|
|
39
|
-
content_tag(:script, content, type: 'text/javascript')
|
|
40
|
-
end
|
|
34
|
+
include ::Middleman::GoogleAnalytics::Helpers
|
|
35
|
+
end
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
content = Uglifier.compile(content) if google_analytics_settings.minify
|
|
47
|
-
content_tag(:script, content, type: 'text/javascript')
|
|
48
|
-
end
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def display?
|
|
40
|
+
app.build? || app.development? && options.development
|
|
49
41
|
end
|
|
42
|
+
|
|
50
43
|
end
|
|
51
44
|
end
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
gaq << ['_setDomainName', "#{@options.domain_name}"] if @options.domain_name
|
|
6
6
|
gaq << ['_setAllowLinker', true] if @options.allow_linker
|
|
7
7
|
gaq << ['_gat._anonymizeIp'] if @options.anonymize_ip
|
|
8
|
-
|
|
9
|
-
gaq << ['_trackPageview']
|
|
10
|
-
end
|
|
8
|
+
gaq << ['_trackPageview']
|
|
11
9
|
%>
|
|
12
10
|
var _gaq = _gaq || [];
|
|
13
11
|
<%= gaq.map! { |x| "_gaq.push(#{x});" }.join("\n ") %>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'uglifier'
|
|
2
|
+
|
|
3
|
+
module Middleman
|
|
4
|
+
module GoogleAnalytics
|
|
5
|
+
module Helpers
|
|
6
|
+
|
|
7
|
+
def google_analytics_tag
|
|
8
|
+
render_script('ga.js.erb')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def google_analytics_universal_tag
|
|
12
|
+
render_script('analytics.js.erb')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def render_script(template)
|
|
18
|
+
return nil if development? && !google_analytics_settings.development
|
|
19
|
+
|
|
20
|
+
@options = google_analytics_settings
|
|
21
|
+
file = File.join(File.dirname(__FILE__), template)
|
|
22
|
+
content = ERB.new(File.read(file)).result(binding)
|
|
23
|
+
content = Uglifier.compile(content) if google_analytics_settings.minify
|
|
24
|
+
content_tag(:script, content, type: 'text/javascript')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: middleman-google-analytics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Bayerlein
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: middleman-core
|
|
@@ -61,15 +61,37 @@ files:
|
|
|
61
61
|
- LICENSE
|
|
62
62
|
- README.md
|
|
63
63
|
- Rakefile
|
|
64
|
-
- features/
|
|
64
|
+
- features/google_analytics.feature
|
|
65
|
+
- features/google_analytics_universal.feature
|
|
65
66
|
- features/support/env.rb
|
|
66
|
-
-
|
|
67
|
-
- fixtures/
|
|
68
|
-
- fixtures/
|
|
67
|
+
- fixtures/across-a-domain-app/config.rb
|
|
68
|
+
- fixtures/across-a-domain-app/source/google-analytics-universal.html.erb
|
|
69
|
+
- fixtures/across-a-domain-app/source/google-analytics.html.erb
|
|
70
|
+
- fixtures/across-multiple-domains-app/config.rb
|
|
71
|
+
- fixtures/across-multiple-domains-app/source/google-analytics-universal.html.erb
|
|
72
|
+
- fixtures/across-multiple-domains-app/source/google-analytics.html.erb
|
|
73
|
+
- fixtures/anonymize-ip-app/config.rb
|
|
74
|
+
- fixtures/anonymize-ip-app/source/google-analytics-universal.html.erb
|
|
75
|
+
- fixtures/anonymize-ip-app/source/google-analytics.html.erb
|
|
76
|
+
- fixtures/basic-app/config.rb
|
|
77
|
+
- fixtures/basic-app/source/google-analytics-universal.html.erb
|
|
78
|
+
- fixtures/basic-app/source/google-analytics.html.erb
|
|
79
|
+
- fixtures/compress-js-app/config.rb
|
|
80
|
+
- fixtures/compress-js-app/source/google-analytics-universal.html.erb
|
|
81
|
+
- fixtures/compress-js-app/source/google-analytics.html.erb
|
|
82
|
+
- fixtures/debug-app/config.rb
|
|
83
|
+
- fixtures/debug-app/source/google-analytics.html.erb
|
|
84
|
+
- fixtures/disable-app/config.rb
|
|
85
|
+
- fixtures/disable-app/source/google-analytics-universal.html.erb
|
|
86
|
+
- fixtures/disable-app/source/google-analytics.html.erb
|
|
87
|
+
- fixtures/full-app/config.rb
|
|
88
|
+
- fixtures/full-app/source/google-analytics-universal.html.erb
|
|
89
|
+
- fixtures/full-app/source/google-analytics.html.erb
|
|
69
90
|
- lib/middleman-google-analytics.rb
|
|
70
91
|
- lib/middleman-google-analytics/analytics.js.erb
|
|
71
92
|
- lib/middleman-google-analytics/extension.rb
|
|
72
93
|
- lib/middleman-google-analytics/ga.js.erb
|
|
94
|
+
- lib/middleman-google-analytics/helpers.rb
|
|
73
95
|
- lib/middleman-google-analytics/version.rb
|
|
74
96
|
- middleman-google-analytics.gemspec
|
|
75
97
|
homepage: https://github.com/danielbayerlein/middleman-google-analytics
|
|
@@ -92,12 +114,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
114
|
version: '0'
|
|
93
115
|
requirements: []
|
|
94
116
|
rubyforge_project:
|
|
95
|
-
rubygems_version: 2.
|
|
117
|
+
rubygems_version: 2.4.5
|
|
96
118
|
signing_key:
|
|
97
119
|
specification_version: 4
|
|
98
120
|
summary: A Middleman plugin for handling Google Analytics tracking code.
|
|
99
121
|
test_files:
|
|
100
|
-
- features/
|
|
122
|
+
- features/google_analytics.feature
|
|
123
|
+
- features/google_analytics_universal.feature
|
|
101
124
|
- features/support/env.rb
|
|
102
|
-
- features/universal.feature
|
|
103
125
|
has_rdoc:
|
data/features/helper.feature
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
Feature: Google Analytics tag helper
|
|
2
|
-
|
|
3
|
-
Scenario: Basic tracking code
|
|
4
|
-
Given a fixture app "test-app"
|
|
5
|
-
And a file named "config.rb" with:
|
|
6
|
-
"""
|
|
7
|
-
activate :google_analytics do |ga|
|
|
8
|
-
ga.tracking_id = 'UA-123456-78'
|
|
9
|
-
end
|
|
10
|
-
"""
|
|
11
|
-
Given the Server is running at "test-app"
|
|
12
|
-
When I go to "/"
|
|
13
|
-
Then I should see:
|
|
14
|
-
"""
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
var _gaq = _gaq || [];
|
|
17
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
18
|
-
_gaq.push(["_trackPageview"]);
|
|
19
|
-
(function() {
|
|
20
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
21
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
22
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
23
|
-
})();
|
|
24
|
-
</script>
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
Scenario: On debug mode
|
|
28
|
-
Given a fixture app "test-app"
|
|
29
|
-
And a file named "config.rb" with:
|
|
30
|
-
"""
|
|
31
|
-
activate :google_analytics do |ga|
|
|
32
|
-
ga.tracking_id = 'UA-123456-78'
|
|
33
|
-
ga.debug = true
|
|
34
|
-
end
|
|
35
|
-
"""
|
|
36
|
-
Given the Server is running at "test-app"
|
|
37
|
-
When I go to "/"
|
|
38
|
-
Then I should see:
|
|
39
|
-
"""
|
|
40
|
-
<script type="text/javascript">
|
|
41
|
-
var _gaq = _gaq || [];
|
|
42
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
43
|
-
_gaq.push(["_trackPageview"]);
|
|
44
|
-
(function() {
|
|
45
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
46
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/u/ga_debug.js';
|
|
47
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
48
|
-
})();
|
|
49
|
-
</script>
|
|
50
|
-
"""
|
|
51
|
-
|
|
52
|
-
Scenario: Tracking across a domain and its subdomains
|
|
53
|
-
Given a fixture app "test-app"
|
|
54
|
-
And a file named "config.rb" with:
|
|
55
|
-
"""
|
|
56
|
-
activate :google_analytics do |ga|
|
|
57
|
-
ga.tracking_id = 'UA-123456-78'
|
|
58
|
-
ga.domain_name = 'example.com'
|
|
59
|
-
end
|
|
60
|
-
"""
|
|
61
|
-
Given the Server is running at "test-app"
|
|
62
|
-
When I go to "/"
|
|
63
|
-
Then I should see:
|
|
64
|
-
"""
|
|
65
|
-
<script type="text/javascript">
|
|
66
|
-
var _gaq = _gaq || [];
|
|
67
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
68
|
-
_gaq.push(["_setDomainName", "example.com"]);
|
|
69
|
-
_gaq.push(["_trackPageview"]);
|
|
70
|
-
(function() {
|
|
71
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
72
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
73
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
74
|
-
})();
|
|
75
|
-
</script>
|
|
76
|
-
"""
|
|
77
|
-
|
|
78
|
-
Scenario: Tracking across multiple domains and subdomains
|
|
79
|
-
Given a fixture app "test-app"
|
|
80
|
-
And a file named "config.rb" with:
|
|
81
|
-
"""
|
|
82
|
-
activate :google_analytics do |ga|
|
|
83
|
-
ga.tracking_id = 'UA-123456-78'
|
|
84
|
-
ga.domain_name = 'example.com'
|
|
85
|
-
ga.allow_linker = true
|
|
86
|
-
end
|
|
87
|
-
"""
|
|
88
|
-
Given the Server is running at "test-app"
|
|
89
|
-
When I go to "/"
|
|
90
|
-
Then I should see:
|
|
91
|
-
"""
|
|
92
|
-
<script type="text/javascript">
|
|
93
|
-
var _gaq = _gaq || [];
|
|
94
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
95
|
-
_gaq.push(["_setDomainName", "example.com"]);
|
|
96
|
-
_gaq.push(["_setAllowLinker", true]);
|
|
97
|
-
_gaq.push(["_trackPageview"]);
|
|
98
|
-
(function() {
|
|
99
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
100
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
101
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
102
|
-
})();
|
|
103
|
-
</script>
|
|
104
|
-
"""
|
|
105
|
-
|
|
106
|
-
Scenario: Removing the last octet of the IP address
|
|
107
|
-
Given a fixture app "test-app"
|
|
108
|
-
And a file named "config.rb" with:
|
|
109
|
-
"""
|
|
110
|
-
activate :google_analytics do |ga|
|
|
111
|
-
ga.tracking_id = 'UA-123456-78'
|
|
112
|
-
ga.anonymize_ip = true
|
|
113
|
-
end
|
|
114
|
-
"""
|
|
115
|
-
Given the Server is running at "test-app"
|
|
116
|
-
When I go to "/"
|
|
117
|
-
Then I should see:
|
|
118
|
-
"""
|
|
119
|
-
<script type="text/javascript">
|
|
120
|
-
var _gaq = _gaq || [];
|
|
121
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
122
|
-
_gaq.push(["_gat._anonymizeIp"]);
|
|
123
|
-
_gaq.push(["_trackPageview"]);
|
|
124
|
-
(function() {
|
|
125
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
126
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
127
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
128
|
-
})();
|
|
129
|
-
</script>
|
|
130
|
-
"""
|
|
131
|
-
|
|
132
|
-
Scenario: Disable tracking in development environment
|
|
133
|
-
Given a fixture app "test-app"
|
|
134
|
-
And a file named "config.rb" with:
|
|
135
|
-
"""
|
|
136
|
-
activate :google_analytics do |ga|
|
|
137
|
-
ga.tracking_id = 'UA-123456-78'
|
|
138
|
-
ga.development = false
|
|
139
|
-
end
|
|
140
|
-
"""
|
|
141
|
-
Given the Server is running at "test-app"
|
|
142
|
-
When I go to "/"
|
|
143
|
-
Then I should see:
|
|
144
|
-
"""
|
|
145
|
-
<script type="text/javascript">
|
|
146
|
-
var _gaq = _gaq || [];
|
|
147
|
-
_gaq.push(["_setAccount", "UA-123456-78"]);
|
|
148
|
-
(function() {
|
|
149
|
-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
150
|
-
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
|
|
151
|
-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
152
|
-
})();
|
|
153
|
-
</script>
|
|
154
|
-
"""
|
|
155
|
-
|
|
156
|
-
Scenario: Compress the JavaScript code
|
|
157
|
-
Given a fixture app "test-app"
|
|
158
|
-
And a file named "config.rb" with:
|
|
159
|
-
"""
|
|
160
|
-
activate :google_analytics do |ga|
|
|
161
|
-
ga.tracking_id = 'UA-123456-78'
|
|
162
|
-
ga.minify = true
|
|
163
|
-
end
|
|
164
|
-
"""
|
|
165
|
-
Given the Server is running at "test-app"
|
|
166
|
-
When I go to "/"
|
|
167
|
-
Then I should see:
|
|
168
|
-
"""
|
|
169
|
-
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-123456-78"]),_gaq.push(["_trackPageview"]),function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"==document.location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();</script>
|
|
170
|
-
"""
|
|
171
|
-
|
|
172
|
-
Scenario: Full options
|
|
173
|
-
Given a fixture app "test-app"
|
|
174
|
-
And a file named "config.rb" with:
|
|
175
|
-
"""
|
|
176
|
-
activate :google_analytics do |ga|
|
|
177
|
-
ga.tracking_id = 'UA-123456-78'
|
|
178
|
-
ga.domain_name = 'example.com'
|
|
179
|
-
ga.debug = true
|
|
180
|
-
ga.allow_linker = true
|
|
181
|
-
ga.anonymize_ip = true
|
|
182
|
-
ga.development = true
|
|
183
|
-
ga.minify = true
|
|
184
|
-
end
|
|
185
|
-
"""
|
|
186
|
-
Given the Server is running at "test-app"
|
|
187
|
-
When I go to "/"
|
|
188
|
-
Then I should see:
|
|
189
|
-
"""
|
|
190
|
-
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-123456-78"]),_gaq.push(["_setDomainName","example.com"]),_gaq.push(["_setAllowLinker",!0]),_gaq.push(["_gat._anonymizeIp"]),_gaq.push(["_trackPageview"]),function(){var e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=("https:"==document.location.protocol?"//ssl":"//www")+".google-analytics.com/u/ga_debug.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a)}();</script>
|
|
191
|
-
"""
|