middleman-google-analytics 0.1.1 → 1.0.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12d3bde3081dcdfcc610d145db3e1caf85f33f28
4
- data.tar.gz: bfeb5cd960ddf072e30634b89ca1a82aaf29c75a
3
+ metadata.gz: da21cec1aa7ac06146c3b1871e0badfd4fd4035d
4
+ data.tar.gz: fd559943bcb465f07197f18518698dbbcf0a2e56
5
5
  SHA512:
6
- metadata.gz: 537f59a5868a5d9c1f05f4617605c163d1096a5fb1b2ab920f821cb44bee5d11032a4e667bc8756c8e5a11f21d4da8c4eb873c21c623fe0851d0cabc74244c4f
7
- data.tar.gz: e3ff1c37d28ddd8e8c3213de014d5c23f331c7fc2bb9165dca240b2fe19b3718e4ec7379b6287e3e6740c0d617a62e32da78a51293f1bc51f3ec7b376a88b632
6
+ metadata.gz: d26e3849ab9f52348391adcbe552c1c0b41d65d7cf958ef151882da63ffdd07ee79962ca424bd8455f7eeae8eacb1da0bc0d5c0ef0b7a86f6337710202fe470d
7
+ data.tar.gz: 9162a558e071d855b19dd2e3533d1471f3bde5e02db65dd333b2a8c5f2d213cd463165290900673fc0e684605a124ae767e0d82fc9ca666e615fe3ff23b4ec90
data/.travis.yml CHANGED
@@ -1,14 +1,17 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
4
+ - ruby-head
5
+ - 2.1.1
6
6
  - 2.1.0
7
+ - 2.0.0
8
+ - 1.9.3
7
9
  - jruby-19mode
8
10
 
9
11
  # Bug in jRuby w/ Rouge: https://github.com/jruby/jruby/issues/1392
10
12
  matrix:
11
13
  allow_failures:
14
+ - rvm: ruby-head
12
15
  - rvm: jruby-19mode
13
16
 
14
17
  script: "bundle exec rake test"
data/CHANGELOG.md CHANGED
@@ -2,20 +2,23 @@
2
2
 
3
3
  ## HEAD (???)
4
4
 
5
+ * Refactoring Middleman::GoogleAnalytics.
6
+ * No longer compatible with Middleman < 3.2.
7
+ * Require Ruby 1.9.3 or greater.
8
+ * Development option for tracking in development environment.
9
+ * Minify option for compress the JavaScript code.
10
+
5
11
  ## 0.1.1 (2014-04-20)
6
12
 
7
13
  * Fix Universal Analytics code.
8
14
 
9
15
  ## 0.1.0 (2014-04-16)
10
16
 
11
- * Add Cucumber tests.
12
17
  * Add Universal Analytics support.
13
- * Cleanup README.
14
18
 
15
19
  ## 0.0.3 (2014-01-07)
16
20
 
17
21
  * Add license info to gemspec.
18
- * Add project status info to README.
19
22
 
20
23
  ## 0.0.2 (2013-10-16)
21
24
 
data/Gemfile CHANGED
@@ -4,14 +4,14 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem "rake", "~> 0.9.2"
8
- gem "rdoc", "~> 3.9"
9
- gem "yard", "~> 0.8.0"
7
+ gem 'rake'
8
+ gem 'rdoc'
9
+ gem 'yard'
10
10
  end
11
11
 
12
12
  group :test do
13
- gem "cucumber", "~> 1.3.1"
14
- gem "fivemat", :github => "tpope/fivemat"
15
- gem "aruba", "~> 0.5.1"
16
- gem "rspec", "~> 2.7"
13
+ gem 'cucumber'
14
+ gem 'fivemat', :github => 'tpope/fivemat'
15
+ gem 'aruba'
16
+ gem 'rspec'
17
17
  end
data/README.md CHANGED
@@ -23,7 +23,7 @@ keeps your config in `config.rb`, where it belongs.
23
23
  ```ruby
24
24
  # config.rb
25
25
  activate :google_analytics do |ga|
26
- ga.tracking_id = 'UA-XXXXXXX-X'
26
+ ga.tracking_id = 'UA-XXXXXXX-X' # Replace with your property ID.
27
27
  end
28
28
  ```
29
29
 
@@ -45,12 +45,12 @@ keeps your config in `config.rb`, where it belongs.
45
45
  **ERB:**
46
46
 
47
47
  ```erb
48
- <% # Google Analytics %>
48
+ # Google Analytics
49
49
  <%= google_analytics_tag %>
50
50
  ```
51
51
 
52
52
  ```erb
53
- <% # Universal Analytics %>
53
+ # Universal Analytics
54
54
  <%= google_analytics_universal_tag %>
55
55
  ```
56
56
 
@@ -58,31 +58,26 @@ keeps your config in `config.rb`, where it belongs.
58
58
 
59
59
  ```ruby
60
60
  activate :google_analytics do |ga|
61
- ga.tracking_id = 'UA-XXXXXXX-X' # property ID
62
- ga.debug = false # Manually set debug flag (if true, links to /u/ga_debug.js)
63
- ga.anonymize_ip = true # removing the last octet of the IP address
64
- ga.domain_name = 'example.com' # Track for (cross-domain tracking)
65
- ga.allow_linker = true # Multiple top-level domains (needs domain_name to be set)
66
- end
67
- ```
61
+ # Property ID (default = nil)
62
+ ga.tracking_id = 'UA-XXXXXXX-X'
68
63
 
69
- ## Only Including Tracking Code in Builds
64
+ # Removing the last octet of the IP address (default = false)
65
+ ga.anonymize_ip = false
70
66
 
71
- To include the tracking code only in builds, and not when running
72
- `middleman server`, simply add environment-specific configurations in your
73
- `config.rb`:
67
+ # Tracking across a domain and its subdomains (default = nil)
68
+ ga.domain_name = 'example.com'
74
69
 
75
- ```ruby
76
- configure :development do
77
- activate :google_analytics do |ga|
78
- ga.tracking_id = false
79
- end
80
- end
70
+ # Tracking across multiple domains and subdomains (default = false)
71
+ ga.allow_linker = false
81
72
 
82
- configure :build do
83
- activate :google_analytics do |ga|
84
- ga.tracking_id = 'UA-XXXXXXX-X'
85
- end
73
+ # Tracking Code Debugger (default = false)
74
+ ga.debug = false
75
+
76
+ # Tracking in development environment (default = true)
77
+ ga.development = true
78
+
79
+ # Compress the JavaScript code (default = false)
80
+ ga.minify = false
86
81
  end
87
82
  ```
88
83
 
@@ -97,6 +92,7 @@ display the GA tracking code.
97
92
  * For the initial code.
98
93
  * [Atsushi Nagase (@ngs)](https://github.com/ngs)
99
94
  * Cucumber tests and "Universal Analytics" support.
95
+ * [Contributors](../../graphs/contributors)
100
96
 
101
97
  ## Contributing
102
98
 
data/Rakefile CHANGED
@@ -9,6 +9,6 @@ end
9
9
 
10
10
  require 'rake/clean'
11
11
 
12
- task :test => ["cucumber"]
12
+ task :test => ['cucumber']
13
13
 
14
- task :default => :test
14
+ task :default => :test
@@ -6,7 +6,6 @@ Feature: Google Analytics tag helper
6
6
  """
7
7
  activate :google_analytics do |ga|
8
8
  ga.tracking_id = 'UA-123456-78'
9
- ga.debug = false
10
9
  end
11
10
  """
12
11
  Given the Server is running at "test-app"
@@ -50,16 +49,13 @@ Feature: Google Analytics tag helper
50
49
  </script>
51
50
  """
52
51
 
53
- Scenario: Set domain name
52
+ Scenario: Tracking across a domain and its subdomains
54
53
  Given a fixture app "test-app"
55
54
  And a file named "config.rb" with:
56
55
  """
57
56
  activate :google_analytics do |ga|
58
57
  ga.tracking_id = 'UA-123456-78'
59
58
  ga.domain_name = 'example.com'
60
- ga.debug = false
61
- ga.allow_linker = false
62
- ga.anonymize_ip = false
63
59
  end
64
60
  """
65
61
  Given the Server is running at "test-app"
@@ -79,16 +75,14 @@ Feature: Google Analytics tag helper
79
75
  </script>
80
76
  """
81
77
 
82
- Scenario: Multiple top-level domains
78
+ Scenario: Tracking across multiple domains and subdomains
83
79
  Given a fixture app "test-app"
84
80
  And a file named "config.rb" with:
85
81
  """
86
82
  activate :google_analytics do |ga|
87
83
  ga.tracking_id = 'UA-123456-78'
88
84
  ga.domain_name = 'example.com'
89
- ga.debug = false
90
85
  ga.allow_linker = true
91
- ga.anonymize_ip = false
92
86
  end
93
87
  """
94
88
  Given the Server is running at "test-app"
@@ -115,9 +109,6 @@ Feature: Google Analytics tag helper
115
109
  """
116
110
  activate :google_analytics do |ga|
117
111
  ga.tracking_id = 'UA-123456-78'
118
- ga.domain_name = nil
119
- ga.debug = false
120
- ga.allow_linker = false
121
112
  ga.anonymize_ip = true
122
113
  end
123
114
  """
@@ -137,16 +128,14 @@ Feature: Google Analytics tag helper
137
128
  })();
138
129
  </script>
139
130
  """
140
- Scenario: Full options
131
+
132
+ Scenario: Disable tracking in development environment
141
133
  Given a fixture app "test-app"
142
134
  And a file named "config.rb" with:
143
135
  """
144
136
  activate :google_analytics do |ga|
145
137
  ga.tracking_id = 'UA-123456-78'
146
- ga.domain_name = 'example.com'
147
- ga.debug = true
148
- ga.allow_linker = true
149
- ga.anonymize_ip = true
138
+ ga.development = false
150
139
  end
151
140
  """
152
141
  Given the Server is running at "test-app"
@@ -156,15 +145,47 @@ Feature: Google Analytics tag helper
156
145
  <script type="text/javascript">
157
146
  var _gaq = _gaq || [];
158
147
  _gaq.push(["_setAccount", "UA-123456-78"]);
159
- _gaq.push(["_setDomainName", "example.com"]);
160
- _gaq.push(["_setAllowLinker", true]);
161
- _gaq.push(["_gat._anonymizeIp"]);
162
- _gaq.push(["_trackPageview"]);
163
148
  (function() {
164
149
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
165
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/u/ga_debug.js';
150
+ ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
166
151
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
167
152
  })();
168
153
  </script>
169
154
  """
170
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
+ """
@@ -1,4 +1,4 @@
1
1
  PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
- require "middleman-core"
3
- require "middleman-core/step_definitions"
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
4
  require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-google-analytics')
@@ -6,10 +6,6 @@ Feature: Google Analytics universal tag helper
6
6
  """
7
7
  activate :google_analytics do |ga|
8
8
  ga.tracking_id = 'UA-123456-78'
9
- ga.domain_name = nil
10
- ga.debug = false
11
- ga.allow_linker = false
12
- ga.anonymize_ip = false
13
9
  end
14
10
  """
15
11
  Given the Server is running at "test-app-universal"
@@ -26,16 +22,13 @@ Feature: Google Analytics universal tag helper
26
22
  </script>
27
23
  """
28
24
 
29
- Scenario: Set domain name
25
+ Scenario: Tracking across a domain and its subdomains
30
26
  Given a fixture app "test-app-universal"
31
27
  And a file named "config.rb" with:
32
28
  """
33
29
  activate :google_analytics do |ga|
34
30
  ga.tracking_id = 'UA-123456-78'
35
31
  ga.domain_name = 'example.com'
36
- ga.debug = false
37
- ga.allow_linker = false
38
- ga.anonymize_ip = false
39
32
  end
40
33
  """
41
34
  Given the Server is running at "test-app-universal"
@@ -52,16 +45,14 @@ Feature: Google Analytics universal tag helper
52
45
  </script>
53
46
  """
54
47
 
55
- Scenario: Multiple top-level domains
48
+ Scenario: Tracking across multiple domains and subdomains
56
49
  Given a fixture app "test-app-universal"
57
50
  And a file named "config.rb" with:
58
51
  """
59
52
  activate :google_analytics do |ga|
60
53
  ga.tracking_id = 'UA-123456-78'
61
54
  ga.domain_name = 'example.com'
62
- ga.debug = false
63
55
  ga.allow_linker = true
64
- ga.anonymize_ip = false
65
56
  end
66
57
  """
67
58
  Given the Server is running at "test-app-universal"
@@ -84,9 +75,6 @@ Feature: Google Analytics universal tag helper
84
75
  """
85
76
  activate :google_analytics do |ga|
86
77
  ga.tracking_id = 'UA-123456-78'
87
- ga.domain_name = nil
88
- ga.debug = false
89
- ga.allow_linker = false
90
78
  ga.anonymize_ip = true
91
79
  end
92
80
  """
@@ -104,6 +92,45 @@ Feature: Google Analytics universal tag helper
104
92
  ga('send', 'pageview');
105
93
  </script>
106
94
  """
95
+
96
+ Scenario: Disable tracking in development environment
97
+ Given a fixture app "test-app-universal"
98
+ And a file named "config.rb" with:
99
+ """
100
+ activate :google_analytics do |ga|
101
+ ga.tracking_id = 'UA-123456-78'
102
+ ga.development = false
103
+ end
104
+ """
105
+ Given the Server is running at "test-app-universal"
106
+ When I go to "/"
107
+ Then I should see:
108
+ """
109
+ <script type="text/javascript">
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
+ """
117
+
118
+ Scenario: Compress the JavaScript code
119
+ Given a fixture app "test-app-universal"
120
+ And a file named "config.rb" with:
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:
130
+ """
131
+ <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
+ """
133
+
107
134
  Scenario: Full options
108
135
  Given a fixture app "test-app-universal"
109
136
  And a file named "config.rb" with:
@@ -114,19 +141,13 @@ Feature: Google Analytics universal tag helper
114
141
  ga.debug = true
115
142
  ga.allow_linker = true
116
143
  ga.anonymize_ip = true
144
+ ga.development = true
145
+ ga.minify = true
117
146
  end
118
147
  """
119
148
  Given the Server is running at "test-app-universal"
120
149
  When I go to "/"
121
150
  Then I should see:
122
151
  """
123
- <script type="text/javascript">
124
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
125
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
126
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
127
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
128
- ga('create', 'UA-123456-78', 'example.com', {'allowLinker': true});
129
- ga('set', 'anonymizeIp', true);
130
- ga('send', 'pageview');
131
- </script>
152
+ <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>
132
153
  """
@@ -1,11 +1,7 @@
1
- # Require core library
2
1
  require 'middleman-core'
2
+ require 'middleman-google-analytics/version'
3
3
 
4
- # Register extensions which can be activated
5
- # Make sure we have the version of Middleman we expect
6
4
  ::Middleman::Extensions.register(:google_analytics) do
7
5
  require 'middleman-google-analytics/extension'
8
-
9
- # Return the extension module
10
- ::Middleman::GoogleAnalytics
6
+ ::Middleman::GoogleAnalyticsExtension
11
7
  end
@@ -0,0 +1,17 @@
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
+ ga = []
7
+ ga << "ga('create', #{create_options.join(', ')});"
8
+ ga << "ga('set', 'anonymizeIp', true);" if @options.anonymize_ip
9
+ if build? || development? && @options.development
10
+ ga << "ga('send', 'pageview');"
11
+ end
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 ") %>
@@ -1,67 +1,50 @@
1
+ require 'uglifier'
2
+
1
3
  module Middleman
2
- module GoogleAnalytics
3
- class Options < Struct.new(:tracking_id, :anonymize_ip, :allow_linker, :domain_name, :debug); end
4
+ class GoogleAnalyticsExtension < Extension
5
+ option :tracking_id, nil, 'Property ID'
6
+ option :anonymize_ip, false, 'Removing the last octet of the IP address'
7
+ option :domain_name, nil, 'Tracking across a domain and its subdomains'
8
+ option :allow_linker, false, 'Tracking across multiple domains and ' \
9
+ 'subdomains'
10
+ option :debug, false, 'Tracking Code Debugger'
11
+ option :development, true, 'Tracking in development environment'
12
+ option :minify, false, 'Compress the JavaScript code'
4
13
 
5
- class << self
6
- def options
7
- @@options ||= Options.new
8
- end
14
+ def initialize(app, options_hash={}, &block)
15
+ super
9
16
 
10
- def registered(app, options={})
11
- @@options ||= Options.new(*options.values_at(*Options.members))
12
- yield @@options if block_given?
17
+ app.set :google_analytics_settings, options
18
+ end
13
19
 
14
- if @@options.allow_linker and not @@options.domain_name
15
- $stderr.puts 'Google Analytics: Please specify a domain_name when using allow_linker'
16
- raise 'No domain_name given'
17
- end
20
+ def after_configuration
21
+ unless options.tracking_id
22
+ $stderr.puts 'Google Analytics: Please specify a property ID'
23
+ raise 'No property ID given'
24
+ end
18
25
 
19
- app.send :include, InstanceMethods
26
+ if options.allow_linker and not options.domain_name
27
+ $stderr.puts 'Google Analytics: Please specify a domain_name when ' \
28
+ 'using allow_linker'
29
+ raise 'No domain_name given'
20
30
  end
21
- alias :included :registered
22
31
  end
23
32
 
24
- module InstanceMethods
33
+ helpers do
25
34
  def google_analytics_tag
26
- options = ::Middleman::GoogleAnalytics.options
27
- options.debug = development? if options.debug.nil?
28
- ga = options.debug ? 'u/ga_debug' : 'ga'
29
- domain_name = options.domain_name
30
- if tracking_id = options.tracking_id
31
- gaq = []
32
- gaq << ['_setAccount', "#{tracking_id}"]
33
- gaq << ['_setDomainName', "#{domain_name}"] if domain_name
34
- gaq << ['_setAllowLinker', true] if options.allow_linker
35
- gaq << ['_gat._anonymizeIp'] if options.anonymize_ip
36
- gaq << ['_trackPageview']
37
- %Q{<script type="text/javascript">
38
- var _gaq = _gaq || [];
39
- #{gaq.map! { |x| "_gaq.push(#{x});" }.join("\n ")}
40
- (function() {
41
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
42
- ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/#{ga}.js';
43
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
44
- })();
45
- </script>}
46
- end
35
+ @options = google_analytics_settings
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')
47
40
  end
48
41
 
49
42
  def google_analytics_universal_tag
50
- options = ::Middleman::GoogleAnalytics.options
51
- options.debug = development? if options.debug.nil?
52
- ga = options.debug ? 'u/ga_debug' : 'ga'
53
- domain_name = options.domain_name
54
- if tracking_id = options.tracking_id
55
- %Q{<script type="text/javascript">
56
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
57
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
58
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
59
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
60
- ga('create', '#{ tracking_id }', '#{ domain_name || 'auto' }'#{ options.allow_linker ? ", {'allowLinker': true}" : '' });#{
61
- options.anonymize_ip ? "\n ga('set', 'anonymizeIp', true);" : '' }
62
- ga('send', 'pageview');
63
- </script>}
64
- end
43
+ @options = google_analytics_settings
44
+ file = File.join(File.dirname(__FILE__), 'analytics.js.erb')
45
+ content = ERB.new(File.read(file)).result(binding)
46
+ content = Uglifier.compile(content) if google_analytics_settings.minify
47
+ content_tag(:script, content, type: 'text/javascript')
65
48
  end
66
49
  end
67
50
  end
@@ -0,0 +1,18 @@
1
+ <%
2
+ file = @options.debug ? 'u/ga_debug' : 'ga'
3
+ gaq = []
4
+ gaq << ['_setAccount', "#{@options.tracking_id}"]
5
+ gaq << ['_setDomainName', "#{@options.domain_name}"] if @options.domain_name
6
+ gaq << ['_setAllowLinker', true] if @options.allow_linker
7
+ gaq << ['_gat._anonymizeIp'] if @options.anonymize_ip
8
+ if build? || development? && @options.development
9
+ gaq << ['_trackPageview']
10
+ end
11
+ %>
12
+ var _gaq = _gaq || [];
13
+ <%= gaq.map! { |x| "_gaq.push(#{x});" }.join("\n ") %>
14
+ (function() {
15
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
16
+ ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/<%= file %>.js';
17
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
18
+ })();
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module GoogleAnalytics
3
- VERSION = "0.1.1"
3
+ VERSION = "1.0.0.pre"
4
4
  end
5
5
  end
@@ -3,24 +3,22 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "middleman-google-analytics/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "middleman-google-analytics"
7
- s.version = Middleman::GoogleAnalytics::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Daniel Bayerlein", "Jon Frisby"]
10
- s.email = ["daniel.bayerlein@googlemail.com", "jfrisby@mrjoy.com"]
11
- s.homepage = "https://github.com/danielbayerlein/middleman-google-analytics"
12
- s.summary = %q{A Middleman plugin for handling Google Analytics tracking code.}
13
- s.license = "MIT"
14
- # s.description = %q{A longer description of your extension}
6
+ s.name = "middleman-google-analytics"
7
+ s.version = Middleman::GoogleAnalytics::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Daniel Bayerlein", "Jon Frisby"]
10
+ s.email = ["daniel.bayerlein@googlemail.com", "jfrisby@mrjoy.com"]
11
+ s.homepage = "https://github.com/danielbayerlein/middleman-google-analytics"
12
+ s.summary = "A Middleman plugin for handling Google Analytics tracking code."
13
+ s.description = "middleman-google-analytics is a Middleman extension that generates Google Analytics tracking code, and keeps your config in config.rb, where it belongs."
14
+ s.license = "MIT"
15
15
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # The version of middleman-core your extension depends on
22
- s.add_runtime_dependency("middleman-core", [">= 3.0.6"])
23
-
24
- # Additional dependencies
25
- # s.add_runtime_dependency("gem-name", "gem-version")
21
+ s.required_ruby_version = '>= 1.9.3'
22
+ s.add_dependency("middleman-core", ["~> 3.2"])
23
+ s.add_dependency("uglifier", ["~> 2.5"])
26
24
  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: 0.1.1
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bayerlein
@@ -9,23 +9,38 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-20 00:00:00.000000000 Z
12
+ date: 2014-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 3.0.6
20
+ version: '3.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 3.0.6
28
- description:
27
+ version: '3.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: uglifier
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ description: middleman-google-analytics is a Middleman extension that generates Google
43
+ Analytics tracking code, and keeps your config in config.rb, where it belongs.
29
44
  email:
30
45
  - daniel.bayerlein@googlemail.com
31
46
  - jfrisby@mrjoy.com
@@ -46,9 +61,10 @@ files:
46
61
  - fixtures/test-app-universal/source/index.html.erb
47
62
  - fixtures/test-app/source/index.html.erb
48
63
  - lib/middleman-google-analytics.rb
64
+ - lib/middleman-google-analytics/analytics.js.erb
49
65
  - lib/middleman-google-analytics/extension.rb
66
+ - lib/middleman-google-analytics/ga.js.erb
50
67
  - lib/middleman-google-analytics/version.rb
51
- - lib/middleman_extension.rb
52
68
  - middleman-google-analytics.gemspec
53
69
  homepage: https://github.com/danielbayerlein/middleman-google-analytics
54
70
  licenses:
@@ -62,12 +78,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
78
  requirements:
63
79
  - - ">="
64
80
  - !ruby/object:Gem::Version
65
- version: '0'
81
+ version: 1.9.3
66
82
  required_rubygems_version: !ruby/object:Gem::Requirement
67
83
  requirements:
68
- - - ">="
84
+ - - ">"
69
85
  - !ruby/object:Gem::Version
70
- version: '0'
86
+ version: 1.3.1
71
87
  requirements: []
72
88
  rubyforge_project:
73
89
  rubygems_version: 2.2.2
@@ -1 +0,0 @@
1
- require 'middleman-google-analytics'