middleman-google-analytics 2.1.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.travis.yml +2 -4
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile-v3 +3 -0
  7. data/README.md +13 -26
  8. data/features/google_analytics.feature +93 -80
  9. data/features/support/env.rb +5 -1
  10. data/fixtures/debug-trace-app/config.rb +4 -0
  11. data/fixtures/debug-trace-app/source/google-analytics.html.erb +1 -0
  12. data/fixtures/disable-app/config.rb +1 -1
  13. data/fixtures/full-app/config.rb +0 -2
  14. data/fixtures/test-app/config.rb +4 -0
  15. data/fixtures/test-app/source/google-analytics.html.erb +1 -0
  16. data/lib/middleman-google-analytics/analytics.js.erb +22 -16
  17. data/lib/middleman-google-analytics/extension.rb +21 -13
  18. data/lib/middleman-google-analytics/helpers.rb +2 -24
  19. data/lib/middleman-google-analytics/version.rb +1 -1
  20. data/middleman-google-analytics.gemspec +1 -1
  21. metadata +16 -17
  22. data/features/google_analytics_universal.feature +0 -128
  23. data/fixtures/across-a-domain-app/source/google-analytics-universal.html.erb +0 -1
  24. data/fixtures/across-multiple-domains-app/source/google-analytics-universal.html.erb +0 -1
  25. data/fixtures/anonymize-ip-app/source/google-analytics-universal.html.erb +0 -1
  26. data/fixtures/basic-app/source/google-analytics-universal.html.erb +0 -1
  27. data/fixtures/compress-js-app/source/google-analytics-universal.html.erb +0 -1
  28. data/fixtures/disable-app/source/google-analytics-universal.html.erb +0 -1
  29. data/fixtures/enhanced-link-attribution-app/source/google-analytics-universal.html.erb +0 -1
  30. data/fixtures/full-app/source/google-analytics-universal.html.erb +0 -1
  31. data/fixtures/output-app/source/javascripts/google_analytics_universal.js.erb +0 -1
  32. data/lib/middleman-google-analytics/analytics_universal.js.erb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e23e08a1ab92df94ca9e642988fc860d71be8cf3
4
- data.tar.gz: c8ac62f5b5a757e311106e6bf71ed02a7632227c
3
+ metadata.gz: 592753ab2adb1299af38fc1c261428fe52b8d198
4
+ data.tar.gz: '0029b5744e153cc2e7b461e623f22c7787dd3bc6'
5
5
  SHA512:
6
- metadata.gz: 8dd6b1b4631fd37010a40a3e81abe553907c4bf2f415b874b2dd9d48f0780ec39b8c6fe004f10bc1135ce8487f5b145b5164ab8fdb118ecc0736e945c8ff33e2
7
- data.tar.gz: 6ea82dfa561267b0b9c39999eb51a5c049091b3723308b45d8146ab804bd539a8ef7cb7d817101b72773858aa62fb08cc50726a6996f0d7b16794eaa2321bf92
6
+ metadata.gz: 5c80f8e8fda26c4e470fe709dc254c7b6d4416f2ba88ae7343624fd1f5d69629988c0e7757ce5ab3bad929f7e6fc0cf1df909f759d9092044fbcf855ab02f443
7
+ data.tar.gz: ea9f1955309cb4e2e398d0ef11ff36d52f9584ee1c2b34cb356e012fff0a433d3bc45438133b8be2442ad85fb1bc47079387aad7b5f791ce1576d2d2f276296e
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -6,10 +6,8 @@ before_script:
6
6
 
7
7
  rvm:
8
8
  - ruby-head
9
- - 2.3.0
10
- - 2.2.4
11
- - 2.1.9
12
- - 2.0.0
9
+ - 2.3.3
10
+ - 2.2.6
13
11
 
14
12
  os:
15
13
  - linux
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.0 (2016-??-??)
4
+
5
+ * Remove the old GA implementation. The Universal Analytics tag is the new
6
+ operating standard for the Google Analytics tracking tag.
7
+
8
+ See: https://support.google.com/analytics/answer/2790010
9
+
10
+ Rename `google_analytics_universal_tag` to `google_analytics_tag`.
11
+ * `debug`, `debug_trace` and `test` option added, see https://developers.google.com/analytics/devguides/collection/analyticsjs/debugging
12
+ * `disable` option added to disable the extension.
13
+ * Drop support for Ruby 2.1 and 2.0
14
+ * Coveralls added.
15
+
3
16
  ## 2.1.1 (2016-04-26)
4
17
 
5
18
  * Incompatibility of uglifier with the latest version of Middleman fixed, see #26.
data/Gemfile CHANGED
@@ -11,6 +11,10 @@ gem 'rake', '~> 10.3', require: false
11
11
  gem 'yard', '~> 0.8', require: false
12
12
 
13
13
  # Test tools
14
+ gem 'capybara', '~> 2.5', require: false
14
15
  gem 'cucumber', '~> 2.0', require: false
15
16
  gem 'aruba', '~> 0.7.4', require: false
16
17
  gem 'rspec', '~> 3.0', require: false
18
+
19
+ # Code Quality
20
+ gem 'coveralls', '~> 0.8', require: false
data/Gemfile-v3 CHANGED
@@ -13,3 +13,6 @@ gem 'yard', '~> 0.8', require: false
13
13
  gem 'cucumber', '~> 2.0', require: false
14
14
  gem 'aruba', '~> 0.10.0', require: false
15
15
  gem 'rspec', '~> 3.0', require: false
16
+
17
+ # Code Quality
18
+ gem 'coveralls', '~> 0.8', require: false
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/middleman-google-analytics.svg)](http://badge.fury.io/rb/middleman-google-analytics)
4
4
  [![Build Status](https://travis-ci.org/danielbayerlein/middleman-google-analytics.svg?branch=master)](https://travis-ci.org/danielbayerlein/middleman-google-analytics)
5
5
  [![Dependency Status](https://gemnasium.com/danielbayerlein/middleman-google-analytics.svg)](https://gemnasium.com/danielbayerlein/middleman-google-analytics)
6
+ [![Coverage Status](https://coveralls.io/repos/github/danielbayerlein/middleman-google-analytics/badge.svg?branch=master)](https://coveralls.io/github/danielbayerlein/middleman-google-analytics?branch=master)
6
7
 
7
8
  **middleman-google-analytics** is a [Middleman](http://middlemanapp.com)
8
9
  extension that generates
@@ -14,7 +15,7 @@ keeps your config in `config.rb`, where it belongs.
14
15
  1. Specify the dependency in your project's `Gemfile`:
15
16
 
16
17
  ```ruby
17
- gem 'middleman-google-analytics', '~> 2.1'
18
+ gem 'middleman-google-analytics', '~> 3.0'
18
19
  ```
19
20
 
20
21
  2. Activate the Google Analytics extension in your project's `config.rb`:
@@ -26,47 +27,27 @@ keeps your config in `config.rb`, where it belongs.
26
27
  end
27
28
  ```
28
29
 
29
- 3. In your layout, after your footer, call `google_analytics_tag` or
30
- `google_analytics_universal_tag` and include the results in the page:
30
+ 3. In your layout, after your footer, call `google_analytics_tag` and include
31
+ the results in the page:
31
32
 
32
33
  **Haml:**
33
34
 
34
35
  ```haml
35
- # Google Analytics
36
36
  = google_analytics_tag
37
37
  ```
38
38
 
39
- ```haml
40
- # Universal Analytics
41
- = google_analytics_universal_tag
42
- ```
43
-
44
39
  **ERB:**
45
40
 
46
41
  ```erb
47
- # Google Analytics
48
42
  <%= google_analytics_tag %>
49
43
  ```
50
44
 
51
- ```erb
52
- # Universal Analytics
53
- <%= google_analytics_universal_tag %>
54
- ```
55
-
56
45
  **JavaScript with ERB (js.erb):**
57
46
 
58
47
  ```erb
59
- # Google Analytics
60
48
  <%= google_analytics_tag %>
61
49
  ```
62
50
 
63
- ```erb
64
- # Universal Analytics
65
- <%= google_analytics_universal_tag %>
66
- ```
67
-
68
- :bulb: Note: [The Universal Analytics tag is the new operating standard for the Google Analytics tracking tag.](https://support.google.com/analytics/answer/2790010)
69
-
70
51
  ## Configuration
71
52
 
72
53
  ```ruby
@@ -86,11 +67,17 @@ activate :google_analytics do |ga|
86
67
  # Enhanced Link Attribution (default = false)
87
68
  ga.enhanced_link_attribution = false
88
69
 
89
- # Tracking Code Debugger (default = false)
70
+ # Log detail messages to the console (default = false)
90
71
  ga.debug = false
91
72
 
92
- # Tracking in development environment (default = true)
93
- ga.development = true
73
+ # Trace debugging will output more verbose information to the console (default = false)
74
+ ga.debug_trace = false
75
+
76
+ # Disable extension (default = false)
77
+ ga.disable = true
78
+
79
+ # Testing your implementation without sending hits (default = true) in development
80
+ ga.test = true
94
81
 
95
82
  # Compress the JavaScript code (default = false)
96
83
  ga.minify = false
@@ -6,31 +6,12 @@ Feature: Google Analytics tag helper
6
6
  Then I should see:
7
7
  """
8
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
- })();
9
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
10
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
11
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
12
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
13
+ ga('create', 'UA-123456-78', 'auto');
14
+ ga('send', 'pageview');
34
15
  </script>
35
16
  """
36
17
 
@@ -40,15 +21,12 @@ Feature: Google Analytics tag helper
40
21
  Then I should see:
41
22
  """
42
23
  <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
- })();
24
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
25
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
26
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
27
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
28
+ ga('create', 'UA-123456-78', 'example.com');
29
+ ga('send', 'pageview');
52
30
  </script>
53
31
  """
54
32
 
@@ -58,16 +36,12 @@ Feature: Google Analytics tag helper
58
36
  Then I should see:
59
37
  """
60
38
  <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
- })();
39
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
40
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
41
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
42
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
43
+ ga('create', 'UA-123456-78', 'example.com', {'allowLinker': true});
44
+ ga('send', 'pageview');
71
45
  </script>
72
46
  """
73
47
 
@@ -77,15 +51,13 @@ Feature: Google Analytics tag helper
77
51
  Then I should see:
78
52
  """
79
53
  <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
- })();
54
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
55
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
56
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
57
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
58
+ ga('create', 'UA-123456-78', 'auto');
59
+ ga('set', 'anonymizeIp', true);
60
+ ga('send', 'pageview');
89
61
  </script>
90
62
  """
91
63
 
@@ -99,7 +71,7 @@ Feature: Google Analytics tag helper
99
71
  When I go to "/google-analytics.html"
100
72
  Then I should see:
101
73
  """
102
- <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>
74
+ <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>
103
75
  """
104
76
 
105
77
  Scenario: Enhanced Link Attribution
@@ -108,15 +80,13 @@ Feature: Google Analytics tag helper
108
80
  Then I should see:
109
81
  """
110
82
  <script type="text/javascript">
111
- var _gaq = _gaq || [];
112
- _gaq.push(["_setAccount", "UA-123456-78"]);
113
- _gaq.push(["_require", "inpage_linkid", "//www.google-analytics.com/plugins/ga/inpage_linkid.js"]);
114
- _gaq.push(["_trackPageview"]);
115
- (function() {
116
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
117
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
118
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
119
- })();
83
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
84
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
85
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
86
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
87
+ ga('create', 'UA-123456-78', 'auto');
88
+ ga('require', 'linkid');
89
+ ga('send', 'pageview');
120
90
  </script>
121
91
  """
122
92
 
@@ -125,7 +95,38 @@ Feature: Google Analytics tag helper
125
95
  When I go to "/google-analytics.html"
126
96
  Then I should see:
127
97
  """
128
- <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(["_require","inpage_linkid","//www.google-analytics.com/plugins/ga/inpage_linkid.js"]),_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>
98
+ <script type="text/javascript">!function(e,a,n,t,c,i,o){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,i=a.createElement(n),o=a.getElementsByTagName(n)[0],i.async=1,i.src=t,o.parentNode.insertBefore(i,o)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-123456-78","example.com",{allowLinker:!0}),ga("set","anonymizeIp",!0),ga("require","linkid"),ga("send","pageview");</script>
99
+ """
100
+
101
+ Scenario: Debugging
102
+ Given the Server is running at "debug-app"
103
+ When I go to "/google-analytics.html"
104
+ Then I should see:
105
+ """
106
+ <script type="text/javascript">
107
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
108
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
109
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
110
+ })(window,document,'script','//www.google-analytics.com/analytics_debug.js','ga');
111
+ ga('create', 'UA-123456-78', 'auto');
112
+ ga('send', 'pageview');
113
+ </script>
114
+ """
115
+
116
+ Scenario: Trace debugging
117
+ Given the Server is running at "debug-trace-app"
118
+ When I go to "/google-analytics.html"
119
+ Then I should see:
120
+ """
121
+ <script type="text/javascript">
122
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
123
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
124
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
125
+ })(window,document,'script','//www.google-analytics.com/analytics_debug.js','ga');
126
+ window.ga_debug = {trace: true};
127
+ ga('create', 'UA-123456-78', 'auto');
128
+ ga('send', 'pageview');
129
+ </script>
129
130
  """
130
131
 
131
132
  Scenario: JavaScript output style
@@ -133,14 +134,28 @@ Feature: Google Analytics tag helper
133
134
  When I go to "/javascripts/google_analytics.js"
134
135
  Then I should see:
135
136
  """
136
- var _gaq = _gaq || [];
137
- _gaq.push(["_setAccount", "UA-123456-78"]);
138
- _gaq.push(["_trackPageview"]);
139
- (function() {
140
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
141
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
142
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
143
- })();
137
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
138
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
139
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
140
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
141
+ ga('create', 'UA-123456-78', 'auto');
142
+ ga('send', 'pageview');
143
+ """
144
+
145
+ Scenario: Test implementation without sending hits
146
+ Given the Server is running at "test-app"
147
+ When I go to "/google-analytics.html"
148
+ Then I should see:
149
+ """
150
+ <script type="text/javascript">
151
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
152
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
153
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
154
+ })(window,document,'script','//www.google-analytics.com/analytics_debug.js','ga');
155
+ ga('create', 'UA-123456-78', 'auto');
156
+ ga('set', 'sendHitTask', null);
157
+ ga('send', 'pageview');
158
+ </script>
144
159
  """
145
160
 
146
161
  Scenario: Build HTML with default configuration
@@ -150,13 +165,11 @@ Feature: Google Analytics tag helper
150
165
  Then the file "google-analytics.html" should contain:
151
166
  """
152
167
  <script type="text/javascript">
153
- var _gaq = _gaq || [];
154
- _gaq.push(["_setAccount", "UA-123456-78"]);
155
- _gaq.push(["_trackPageview"]);
156
- (function() {
157
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
158
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
159
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
160
- })();
168
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
169
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
170
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
171
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
172
+ ga('create', 'UA-123456-78', 'auto');
173
+ ga('send', 'pageview');
161
174
  </script>
162
175
  """
@@ -1,5 +1,9 @@
1
- PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
1
  ENV['TEST'] = 'true'
2
+
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
3
7
  require 'middleman-core'
4
8
  require 'middleman-core/step_definitions'
5
9
  require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-google-analytics')
@@ -0,0 +1,4 @@
1
+ activate :google_analytics do |ga|
2
+ ga.tracking_id = 'UA-123456-78'
3
+ ga.debug_trace = true
4
+ end
@@ -0,0 +1 @@
1
+ <%= google_analytics_tag %>
@@ -1,4 +1,4 @@
1
1
  activate :google_analytics do |ga|
2
2
  ga.tracking_id = 'UA-123456-78'
3
- ga.development = false
3
+ ga.disable = true
4
4
  end
@@ -1,11 +1,9 @@
1
1
  activate :google_analytics do |ga|
2
2
  ga.tracking_id = 'UA-123456-78'
3
3
  ga.domain_name = 'example.com'
4
- ga.debug = true
5
4
  ga.allow_linker = true
6
5
  ga.enhanced_link_attribution = true
7
6
  ga.anonymize_ip = true
8
- ga.development = true
9
7
  ga.minify = true
10
8
  ga.output = :html
11
9
  end
@@ -0,0 +1,4 @@
1
+ activate :google_analytics do |ga|
2
+ ga.tracking_id = 'UA-123456-78'
3
+ ga.test = true
4
+ end
@@ -0,0 +1 @@
1
+ <%= google_analytics_tag %>
@@ -1,19 +1,25 @@
1
1
  <%
2
- file = @options.debug ? 'u/ga_debug' : 'ga'
3
- pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js'
2
+ script = if @options.debug || @options.debug_trace || @options.test
3
+ 'analytics_debug.js'
4
+ else
5
+ 'analytics.js'
6
+ end
4
7
 
5
- gaq = []
6
- gaq << ['_setAccount', "#{@options.tracking_id}"]
7
- gaq << ['_setDomainName', "#{@options.domain_name}"] if @options.domain_name
8
- gaq << ['_setAllowLinker', true] if @options.allow_linker
9
- gaq << ['_gat._anonymizeIp'] if @options.anonymize_ip
10
- gaq << ['_require', 'inpage_linkid', pluginUrl] if @options.enhanced_link_attribution
11
- gaq << ['_trackPageview']
8
+ create_options = []
9
+ create_options << "'#{@options.tracking_id}'"
10
+ create_options << "'#{@options.domain_name || :auto}'"
11
+ create_options << "{'allowLinker': true}" if @options.allow_linker
12
+
13
+ ga = []
14
+ ga << "window.ga_debug = {trace: true};" if @options.debug_trace
15
+ ga << "ga('create', #{create_options.join(', ')});"
16
+ ga << "ga('set', 'sendHitTask', null);" if @options.test
17
+ ga << "ga('set', 'anonymizeIp', true);" if @options.anonymize_ip
18
+ ga << "ga('require', 'linkid');" if @options.enhanced_link_attribution
19
+ ga << "ga('send', 'pageview');"
12
20
  %>
13
- var _gaq = _gaq || [];
14
- <%= gaq.map! { |x| "_gaq.push(#{x});" }.join("\n") %>
15
- (function() {
16
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
17
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/<%= file %>.js';
18
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
19
- })();
21
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
22
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
23
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
24
+ })(window,document,'script','//www.google-analytics.com/<%= script %>','ga');
25
+ <%= ga.join("\n") %>
@@ -6,30 +6,31 @@ module Middleman
6
6
  option :tracking_id, nil, 'Property ID'
7
7
  option :anonymize_ip, false, 'Removing the last octet of the IP address'
8
8
  option :domain_name, nil, 'Tracking across a domain and its subdomains'
9
- option :allow_linker, false, 'Tracking across multiple domains and ' \
10
- 'subdomains'
9
+ option :allow_linker, false, 'Tracking across multiple domains and subdomains'
11
10
  option :enhanced_link_attribution, false, 'Enhanced Link Attribution'
12
- option :debug, false, 'Tracking Code Debugger'
13
- option :development, true, 'Tracking in development environment'
11
+ option :disable, false, 'Disable extension'
12
+ option :debug, false, 'Log detail messages to the console'
13
+ option :debug_trace, false, 'Trace debugging will output more verbose information to the console'
14
+ option :test, false, 'Testing your implementation without sending hits'
14
15
  option :minify, false, 'Compress the JavaScript code'
15
16
  option :output, :html, 'Output style - :html includes <script> tag'
16
17
 
17
18
  def after_configuration
19
+ options.test = true if legacy_development?
20
+
18
21
  unless options.tracking_id
19
22
  $stderr.puts 'Google Analytics: Please specify a property ID'
20
- raise ArgumentError, 'No property ID given' if display?
23
+ raise ArgumentError, 'No property ID given' if app.build?
21
24
  end
22
25
 
23
26
  if options.allow_linker and not options.domain_name
24
- $stderr.puts 'Google Analytics: Please specify a domain_name when ' \
25
- 'using allow_linker'
26
- raise ArgumentError, 'No domain_name given' if display?
27
+ $stderr.puts 'Google Analytics: Please specify a domain_name when using allow_linker'
28
+ raise ArgumentError, 'No domain_name given' if app.build?
27
29
  end
28
30
 
29
31
  unless [:html, :js].include?(options.output.try(:to_sym))
30
- $stderr.puts 'Google Analytics: Please specify a valid output ' \
31
- 'type (html|js).'
32
- raise ArgumentError, 'Only "html" or "js" allowed' if display?
32
+ $stderr.puts 'Google Analytics: Please specify a valid output type (html|js).'
33
+ raise ArgumentError, 'Only "html" or "js" allowed' if app.build?
33
34
  end
34
35
  end
35
36
 
@@ -39,8 +40,15 @@ module Middleman
39
40
 
40
41
  private
41
42
 
42
- def display?
43
- app.build? || app.development? && options.development
43
+ def legacy_development?
44
+ return false if ENV['TEST'] == 'true'
45
+
46
+ # Middleman 3.4
47
+ is_development = try(:development?)
48
+ return is_development unless is_development.nil?
49
+
50
+ # Middleman 4.x
51
+ app.development?
44
52
  end
45
53
 
46
54
  end
@@ -7,21 +7,11 @@ module Middleman
7
7
  module Helpers
8
8
 
9
9
  def google_analytics_tag
10
- render_script('analytics.js.erb')
11
- end
12
-
13
- def google_analytics_universal_tag
14
- render_script('analytics_universal.js.erb')
15
- end
16
-
17
- private
18
-
19
- def render_script(template)
20
10
  options = extensions[:google_analytics].options
21
11
 
22
- return nil if legacy_development? && !options.development
12
+ return nil if options.disable
23
13
 
24
- file = File.join(File.dirname(__FILE__), template)
14
+ file = File.join(File.dirname(__FILE__), 'analytics.js.erb')
25
15
  context = { options: options }
26
16
  content = Erubis::FastEruby.new(File.read(file)).evaluate(context)
27
17
  content = Uglifier.compile(content) if options.minify
@@ -41,18 +31,6 @@ module Middleman
41
31
  str
42
32
  end
43
33
 
44
- # Support for Middleman >= 3.4
45
- def legacy_development?
46
- # Middleman 3.4
47
- is_development = try(:development?)
48
- unless is_development.nil?
49
- return is_development
50
- end
51
-
52
- # Middleman 4.x
53
- app.development?
54
- end
55
-
56
34
  end
57
35
  end
58
36
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module GoogleAnalytics
3
- VERSION = '2.1.1'
3
+ VERSION = '3.0.0'
4
4
  end
5
5
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  # Middleman 3.4.1 requires "uglifier ~> 2.5"
24
24
  # Middleman 4.1.7 requires "uglifier ~> 3.0"
25
25
  s.add_dependency('uglifier', ['>= 2.5', '< 4.0'])
26
- s.add_dependency('activesupport', ['~> 4.1'])
26
+ s.add_dependency('activesupport', ['>= 4.1', '< 5.1'])
27
27
  s.add_dependency('erubis')
28
28
  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: 2.1.1
4
+ version: 3.0.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: 2016-04-26 00:00:00.000000000 Z
12
+ date: 2016-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -49,16 +49,22 @@ dependencies:
49
49
  name: activesupport
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.1'
55
+ - - "<"
56
+ - !ruby/object:Gem::Version
57
+ version: '5.1'
55
58
  type: :runtime
56
59
  prerelease: false
57
60
  version_requirements: !ruby/object:Gem::Requirement
58
61
  requirements:
59
- - - "~>"
62
+ - - ">="
60
63
  - !ruby/object:Gem::Version
61
64
  version: '4.1'
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.1'
62
68
  - !ruby/object:Gem::Dependency
63
69
  name: erubis
64
70
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +88,7 @@ executables: []
82
88
  extensions: []
83
89
  extra_rdoc_files: []
84
90
  files:
91
+ - ".coveralls.yml"
85
92
  - ".gitignore"
86
93
  - ".travis.yml"
87
94
  - CHANGELOG.md
@@ -91,40 +98,33 @@ files:
91
98
  - README.md
92
99
  - Rakefile
93
100
  - features/google_analytics.feature
94
- - features/google_analytics_universal.feature
95
101
  - features/support/env.rb
96
102
  - fixtures/across-a-domain-app/config.rb
97
- - fixtures/across-a-domain-app/source/google-analytics-universal.html.erb
98
103
  - fixtures/across-a-domain-app/source/google-analytics.html.erb
99
104
  - fixtures/across-multiple-domains-app/config.rb
100
- - fixtures/across-multiple-domains-app/source/google-analytics-universal.html.erb
101
105
  - fixtures/across-multiple-domains-app/source/google-analytics.html.erb
102
106
  - fixtures/anonymize-ip-app/config.rb
103
- - fixtures/anonymize-ip-app/source/google-analytics-universal.html.erb
104
107
  - fixtures/anonymize-ip-app/source/google-analytics.html.erb
105
108
  - fixtures/basic-app/config.rb
106
- - fixtures/basic-app/source/google-analytics-universal.html.erb
107
109
  - fixtures/basic-app/source/google-analytics.html.erb
108
110
  - fixtures/compress-js-app/config.rb
109
- - fixtures/compress-js-app/source/google-analytics-universal.html.erb
110
111
  - fixtures/compress-js-app/source/google-analytics.html.erb
111
112
  - fixtures/debug-app/config.rb
112
113
  - fixtures/debug-app/source/google-analytics.html.erb
114
+ - fixtures/debug-trace-app/config.rb
115
+ - fixtures/debug-trace-app/source/google-analytics.html.erb
113
116
  - fixtures/disable-app/config.rb
114
- - fixtures/disable-app/source/google-analytics-universal.html.erb
115
117
  - fixtures/disable-app/source/google-analytics.html.erb
116
118
  - fixtures/enhanced-link-attribution-app/config.rb
117
- - fixtures/enhanced-link-attribution-app/source/google-analytics-universal.html.erb
118
119
  - fixtures/enhanced-link-attribution-app/source/google-analytics.html.erb
119
120
  - fixtures/full-app/config.rb
120
- - fixtures/full-app/source/google-analytics-universal.html.erb
121
121
  - fixtures/full-app/source/google-analytics.html.erb
122
122
  - fixtures/output-app/config.rb
123
123
  - fixtures/output-app/source/javascripts/google_analytics.js.erb
124
- - fixtures/output-app/source/javascripts/google_analytics_universal.js.erb
124
+ - fixtures/test-app/config.rb
125
+ - fixtures/test-app/source/google-analytics.html.erb
125
126
  - lib/middleman-google-analytics.rb
126
127
  - lib/middleman-google-analytics/analytics.js.erb
127
- - lib/middleman-google-analytics/analytics_universal.js.erb
128
128
  - lib/middleman-google-analytics/extension.rb
129
129
  - lib/middleman-google-analytics/helpers.rb
130
130
  - lib/middleman-google-analytics/version.rb
@@ -149,12 +149,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.5.1
152
+ rubygems_version: 2.5.2
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: A Middleman plugin for handling Google Analytics tracking code.
156
156
  test_files:
157
157
  - features/google_analytics.feature
158
- - features/google_analytics_universal.feature
159
158
  - features/support/env.rb
160
159
  has_rdoc:
@@ -1,128 +0,0 @@
1
- Feature: Google Analytics Universal tag helper
2
-
3
- Scenario: Basic tracking code
4
- Given the Server is running at "basic-app"
5
- When I go to "/google-analytics-universal.html"
6
- Then I should see:
7
- """
8
- <script type="text/javascript">
9
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
10
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
11
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
12
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
13
- ga('create', 'UA-123456-78', 'auto');
14
- ga('send', 'pageview');
15
- </script>
16
- """
17
-
18
- Scenario: Tracking across a domain and its subdomains
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:
22
- """
23
- <script type="text/javascript">
24
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
25
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
26
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
27
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
28
- ga('create', 'UA-123456-78', 'example.com');
29
- ga('send', 'pageview');
30
- </script>
31
- """
32
-
33
- Scenario: Tracking across multiple domains and subdomains
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:
37
- """
38
- <script type="text/javascript">
39
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
40
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
41
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
42
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
43
- ga('create', 'UA-123456-78', 'example.com', {'allowLinker': true});
44
- ga('send', 'pageview');
45
- </script>
46
- """
47
-
48
- Scenario: Removing the last octet of the IP address
49
- Given the Server is running at "anonymize-ip-app"
50
- When I go to "/google-analytics-universal.html"
51
- Then I should see:
52
- """
53
- <script type="text/javascript">
54
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
55
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
56
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
57
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
58
- ga('create', 'UA-123456-78', 'auto');
59
- ga('set', 'anonymizeIp', true);
60
- ga('send', 'pageview');
61
- </script>
62
- """
63
-
64
- Scenario: Disable tracking in development environment
65
- Given the Server is running at "disable-app"
66
- When I go to "/google-analytics-universal.html"
67
- Then I should see "0" lines
68
-
69
- Scenario: Compress the JavaScript code
70
- Given the Server is running at "compress-js-app"
71
- When I go to "/google-analytics-universal.html"
72
- Then I should see:
73
- """
74
- <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>
75
- """
76
-
77
- Scenario: Enhanced Link Attribution
78
- Given the Server is running at "enhanced-link-attribution-app"
79
- When I go to "/google-analytics-universal.html"
80
- Then I should see:
81
- """
82
- <script type="text/javascript">
83
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
84
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
85
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
86
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
87
- ga('create', 'UA-123456-78', 'auto');
88
- ga('require', 'linkid');
89
- ga('send', 'pageview');
90
- </script>
91
- """
92
-
93
- Scenario: Full options
94
- Given the Server is running at "full-app"
95
- When I go to "/google-analytics-universal.html"
96
- Then I should see:
97
- """
98
- <script type="text/javascript">!function(e,a,n,t,c,i,o){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,i=a.createElement(n),o=a.getElementsByTagName(n)[0],i.async=1,i.src=t,o.parentNode.insertBefore(i,o)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-123456-78","example.com",{allowLinker:!0}),ga("set","anonymizeIp",!0),ga("require","linkid"),ga("send","pageview");</script>
99
- """
100
-
101
- Scenario: JavaScript output style
102
- Given the Server is running at "output-app"
103
- When I go to "/javascripts/google_analytics_universal.js"
104
- Then I should see:
105
- """
106
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
107
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
108
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
109
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
110
- ga('create', 'UA-123456-78', 'auto');
111
- ga('send', 'pageview');
112
- """
113
-
114
- Scenario: Build HTML with default configuration
115
- Given a fixture app "basic-app"
116
- And a successfully built app at "basic-app"
117
- When I cd to "build"
118
- Then the file "google-analytics-universal.html" should contain:
119
- """
120
- <script type="text/javascript">
121
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
122
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
123
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
124
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
125
- ga('create', 'UA-123456-78', 'auto');
126
- ga('send', 'pageview');
127
- </script>
128
- """
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1 +0,0 @@
1
- <%= google_analytics_universal_tag %>
@@ -1,17 +0,0 @@
1
- <%
2
- create_options = []
3
- create_options << "'#{@options.tracking_id}'"
4
- create_options << "'#{@options.domain_name || :auto}'"
5
- create_options << "{'allowLinker': true}" if @options.allow_linker
6
-
7
- ga = []
8
- ga << "ga('create', #{create_options.join(', ')});"
9
- ga << "ga('set', 'anonymizeIp', true);" if @options.anonymize_ip
10
- ga << "ga('require', 'linkid');" if @options.enhanced_link_attribution
11
- ga << "ga('send', 'pageview');"
12
- %>
13
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
14
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
15
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
16
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
17
- <%= ga.join("\n") %>