google-analytics-rails 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c2e23eb0911637dd83f62ec98c1c03256f43a5a
4
- data.tar.gz: 497a0afcd20fe6656b448f861fe73550996ac6bb
3
+ metadata.gz: 70b6e1110fba9b2d091febdb2d912910f21ccc5d
4
+ data.tar.gz: 5035c20f6adb7e9b8b26e8910cc3bc11eb042b58
5
5
  SHA512:
6
- metadata.gz: 66edf6112899995ec356fd7ae78549a95ab85f40874a2e189eaf9ba90401b3c31f2b2f56b0516395d1f548219cc01eb5de9933b927e41f934c282b20e8d14456
7
- data.tar.gz: 74fe46cefabd308f2bd9f7252121537948b170a1f700dd7cceba51427616d509568d23b345fa597808976de816049db8e9bdd1fc67206514f1b5a063641ae6c7
6
+ metadata.gz: e335e89f26431aa80ca0f0343625c5fe9a7bab1ee118455fbf9bd5212d2a09b1ed40082735d91185c1384d8807f6cd9c432e411a11106f27009f8de3e21e5b61
7
+ data.tar.gz: 14afca1b8c06c2813c679f80083f8413934b7d3d51408d5960bbf2dd80bec15f3b4d45881bf15386f61e5d34f15a810c824bad7a18826d1720ec33f5dc693909
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .yardoc
6
6
  doc
7
+ .DS_Store
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'rake'
4
4
  gem 'yard'
5
+ gem 'i18n', '< 0.7.0'
5
6
  gem 'activesupport', "~> 3.0"
6
7
 
7
8
  group :development do
@@ -1,18 +1,43 @@
1
- Fast Google Analytics setup for Rails 3. This gem is mostly intended for small to medium websites with a simple analytics strategy.
1
+ Fast Universal Google Analytics setup for Rails. This gem is mostly intended for small to medium websites with a simple analytics strategy.
2
2
 
3
3
  [![Build Status](https://travis-ci.org/bgarret/google-analytics-rails.png?branch=master)](https://travis-ci.org/bgarret/google-analytics-rails)
4
4
 
5
+ _if you require older analytics, use `0.0.6`_
6
+
5
7
  Installation
6
8
  ============
7
9
 
8
10
  Add the following to your `Gemfile`:
9
11
 
10
- gem 'google-analytics-rails'
12
+ gem 'google-analytics-rails', '1.0.0'
11
13
 
12
14
  Then run:
13
15
 
14
16
  bundle install
15
17
 
18
+ Upgrade Notes
19
+ ============
20
+
21
+ __Upgrading this gem from 0.0.6?__
22
+
23
+ Use `analytics_init` to send submissions to Analytics if you are using multiple trackers. You can supply a name to tracker by passing `:name` option.
24
+
25
+ **GoogleAnalytics::Events::SetAllowLinker** is no longer supported as an external variable being set. You can submit as normal in the `:add_events` array, but using the new `:setup` config is preferable so no extra array searching has to happen.
26
+
27
+ **GoogleAnalytics::Events::SetCustomVar** is no longer supported by Universal Analytics. These have been changed to SetCustomDimension & SetCustomMetric. By default if you use SetCustomVar, it applies as a Dimension
28
+
29
+ **GoogleAnalytics::Events::DeleteCustomVar** has been removed
30
+
31
+ **Added Event Helpers**
32
+
33
+ - GoogleAnalytics::Events::ExperimentId
34
+ - GoogleAnalytics::Events::ExperimentVariation
35
+
36
+ **TODO:** Add Double Click Snippet Support
37
+ While the code is there, and it looks like it is simply changing the end path to the JS, this feature has not been tested.
38
+
39
+
40
+
16
41
  Documentation
17
42
  =============
18
43
 
@@ -12,8 +12,8 @@ module GoogleAnalytics
12
12
  #
13
13
  # @private
14
14
  SCRIPT_SOURCES = {
15
- :default => "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'",
16
- :doubleclick => "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'",
15
+ :default => "'//www.google-analytics.com/analytics.js'",
16
+ :doubleclick => "'//stats.g.doubleclick.net/dc.js'",
17
17
  }
18
18
 
19
19
  # Get the current tracker id (*UA-xxxxxx-x*).
@@ -5,7 +5,7 @@ module GoogleAnalytics
5
5
  def initialize
6
6
  @events = []
7
7
  end
8
-
8
+
9
9
  def <<(event)
10
10
  push(event)
11
11
  end
@@ -17,21 +17,20 @@ module GoogleAnalytics
17
17
  def to_s
18
18
  <<-JAVASCRIPT
19
19
  <script type="text/javascript">
20
- var _gaq = _gaq || [];
20
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
21
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
22
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
23
+ })(window,document,'script',#{GoogleAnalytics.script_source},'ga');
21
24
  #{@events.map { |event| event.to_s }.join("\n")}
22
- (function() {
23
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
24
- ga.src = #{GoogleAnalytics.script_source};
25
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
26
- })();
27
25
  </script>
28
26
  JAVASCRIPT
29
27
  end
30
-
28
+
31
29
  private
32
-
30
+
33
31
  def renderer_for_event(event, tracker_id)
34
32
  case event
33
+ when SingleEvent then EventRenderer.new(event, tracker_id)
35
34
  when Event then EventRenderer.new(event, tracker_id)
36
35
  when EventCollection then EventCollectionRenderer.new(event, tracker_id)
37
36
  end
@@ -2,11 +2,26 @@
2
2
 
3
3
  module GoogleAnalytics
4
4
  class Event
5
- attr_reader :name, :params
6
-
7
- def initialize(name, *params)
5
+ attr_reader :action, :name, :params
6
+
7
+ def initialize(action, name, *params)
8
+ @action = action
8
9
  @name = name
9
10
  @params = params
10
11
  end
12
+
13
+ def single_event?
14
+ false
15
+ end
16
+ end
17
+ class SingleEvent
18
+ attr_reader :action, :name, :params
19
+ def initialize(action, *params)
20
+ @action = action
21
+ @params = params
22
+ end
23
+ def single_event?
24
+ true
25
+ end
11
26
  end
12
27
  end
@@ -15,7 +15,7 @@ module GoogleAnalytics
15
15
  end
16
16
 
17
17
  def <<(event)
18
- raise InvalidEventError.new(event) unless event.is_a?(Event)
18
+ raise InvalidEventError.new(event) unless event.is_a?(Event) || event.is_a?(SingleEvent)
19
19
 
20
20
  @events << event
21
21
  end
@@ -10,13 +10,19 @@ module GoogleAnalytics
10
10
  end
11
11
 
12
12
  def to_s
13
- "_gaq.push(#{array_to_json([@tracker_id ? "#{@tracker_id}.#{@event.name}" : @event.name, *@event.params])});"
13
+ if @event.class.name == 'GoogleAnalytics::Events::SetupAnalytics'
14
+ "ga('#{@event.action}',#{array_to_json([@event.name, *@event.params])});"
15
+ elsif @event.single_event?
16
+ "ga('#{@tracker_id ? [@tracker_id, @event.action].join('.') : @event.action}');"
17
+ else
18
+ "ga('#{@tracker_id ? [@tracker_id, @event.action].join('.') : @event.action}',#{array_to_json([@event.name, *@event.params])});"
19
+ end
14
20
  end
15
21
 
16
22
  private
17
23
 
18
24
  def array_to_json(array)
19
- "[" << array.map {|string| string_to_json(string) } .join(',') << "]"
25
+ array.map {|string| string_to_json(string) } .join(',')
20
26
  end
21
27
 
22
28
  def string_to_json(string)
@@ -2,68 +2,143 @@
2
2
 
3
3
  module GoogleAnalytics
4
4
  module Events
5
- class SetAccount < Event
5
+ class SetupAnalytics < Event
6
+
7
+ def initialize(account_id, opts={})
8
+ if ['auto','none'].include?(opts) || opts.empty?
9
+ super('create', account_id, opts.empty? ? 'auto' : opts)
10
+ elsif opts.is_a?(Hash)
11
+ super('create', account_id, attributes_hash(opts))
12
+ else
13
+ super('create', account_id, {:cookieDomain => opts})
14
+ end
15
+ end
16
+
17
+ private
18
+ def attributes_hash(opts={})
19
+ {
20
+ :cookieDomain => opts.delete(:cookieDomain) || 'auto',
21
+ :allowLinker => opts.delete(:allowLinker),
22
+ :cookieName => opts.delete(:cookieName),
23
+ :cookieExpires => opts.delete(:cookieExpires),
24
+ :sampleRate => opts.delete(:sampleRate),
25
+ :siteSpeedSampleRate => opts.delete(:siteSpeedSampleRate),
26
+ :name => opts.delete(:name)
27
+ }.reject{|k,v| !v }
28
+ end
29
+ end
30
+
31
+ class SetAccount
6
32
  def initialize(account_id)
7
- super('_setAccount', account_id)
33
+ warn "[REMOVED] `SetAccount` is being removed. Universal Analytics does not support this any longer. Please see GoogleAnalytics::Events::SetupAnalytics"
8
34
  end
9
35
  end
10
36
 
11
- class SetDomainName < Event
37
+ class SetDomainName
12
38
  def initialize(domain_name)
13
- super('_setDomainName', domain_name)
39
+ warn "[REMOVED] `SetDomainName` is being removed. Universal Analytics does not support this any longer. Please see GoogleAnalytics::Events::SetupAnalytics"
14
40
  end
15
41
  end
16
42
 
17
- class SetAllowLinker < Event
43
+ class SetAllowLinker
18
44
  def initialize(allow)
19
- super('_setAllowLinker', allow)
45
+ warn "[REMOVED] `SetAllowLinker` is being removed. Universal Analytics does not support this any longer. Please see GoogleAnalytics::Events::SetupAnalytics"
20
46
  end
21
47
  end
22
48
 
23
49
  class Require < Event
24
- def initialize(name, url)
25
- super('_require', name, url)
50
+ def initialize(name, url=nil)
51
+ if url
52
+ super('require', name, url)
53
+ else
54
+ super('require', name)
55
+ end
26
56
  end
27
57
  end
28
58
 
29
- class SetSiteSpeedSampleRate < Event
59
+ class SetSiteSpeedSampleRate
30
60
  # @param sample_rate [Integer] the percentage of page views that should be used
31
61
  # for page speed metrics - defaults to 1 (aka 1%) if the event is missing.
32
- # @see http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setSiteSpeedSampleRate
62
+ attr_accessor :sample_rate
33
63
  def initialize(sample_rate)
34
- super('_setSiteSpeedSampleRate', sample_rate)
64
+ @sample_rate = sample_rate
65
+ warn "[REMOVED] `SetSiteSpeedSampleRate` is being removed. Universal Analytics does not support this any longer. Please see GoogleAnalytics::Events::SetupAnalytics"
35
66
  end
36
67
  end
37
68
 
69
+ # http://misterphilip.com/universal-analytics/migration/basics
38
70
  class TrackPageview < Event
39
71
  # @param page [String] optional virtual pageview tracking
40
72
  # @see http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html#VirtualPageviews
41
- def initialize(page = nil)
42
- page && page != '' ? super('_trackPageview', page) : super('_trackPageview')
73
+ def initialize(opts = {})
74
+ # Just use default pageview if no page was given
75
+ if opts.is_a?(Hash) && opts.fetch(:page, nil) == nil
76
+ super('send', 'pageview')
77
+ # Provide only the page string if a title was not given but a page was
78
+ elsif opts.is_a?(Hash) && opts.fetch(:page, false)
79
+ super('send', 'pageview', opts.fetch(:title, false) ? opts : opts[:page])
80
+ # Print out a JSON Value for the pageview
81
+ else
82
+ super('send', 'pageview', opts)
83
+ end
43
84
  end
44
85
  end
45
86
 
46
87
  class TrackEvent < Event
47
88
  def initialize(category, action, label = nil, value = nil)
48
89
  if label || value
49
- super('_trackEvent', category.to_s, action.to_s, label ? label.to_s : nil, value ? value.to_i : nil)
90
+ super('send', 'event', category.to_s, action.to_s, label ? label.to_s : nil, value ? value.to_i : nil)
50
91
  else
51
- super('_trackEvent', category.to_s, action.to_s)
92
+ super('send', 'event', category.to_s, action.to_s)
52
93
  end
53
94
  end
54
95
  end
55
96
 
97
+ class ExperimentId < Event
98
+ def initialize(id)
99
+ super('set', 'expId', id.to_s)
100
+ end
101
+ end
102
+
103
+ class ExperimentVariation < Event
104
+ def initialize(variation_id)
105
+ super('set', 'expVar', variation_id.to_i)
106
+ end
107
+ end
108
+
109
+ # Custom Vars no longer exist in Universal Analytics
110
+ # Transfer to dimensions & metrics
111
+ # ga('set', 'dimension1', 953);
112
+ # ga('set', 'metric5', 953);
113
+ #
114
+
115
+ # Deprecated: Please use `SetCustomDimension` or `SetCustomMetric` instead
116
+ #
56
117
  class SetCustomVar < Event
57
118
  def initialize(index, name, value, opt_scope)
58
119
  raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
59
- super('_setCustomVar', index.to_i, name.to_s, value.to_s, opt_scope.to_i)
120
+ warn "[DEPRECATION] `SetCustomVar` is deprecated. Please use `SetCustomDimension` or `SetCustomMetric` instead"
121
+ super('set', "dimension#{index}", value.to_s)
122
+ end
123
+ end
124
+
125
+ class SetCustomDimension < Event
126
+ def initialize(index, value)
127
+ raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
128
+ super('set', "dimension#{index}", value.to_s)
129
+ end
130
+ end
131
+ class SetCustomMetric < Event
132
+ def initialize(index, value)
133
+ raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
134
+ super('set', "metric#{index}", value.to_s)
60
135
  end
61
136
  end
62
137
 
138
+ # Removed: There are no longer Custom Variables
63
139
  class DeleteCustomVar < Event
64
140
  def initialize(index)
65
- raise ArgumentError, "The index has to be between 1 and 5" unless (1..5).include?(index.to_i)
66
- super('_deleteCustomVar', index.to_i)
141
+ warn "[REMOVED] `DeleteCustomVar` is being removed. Universal Analytics does not support Custom Variables."
67
142
  end
68
143
  end
69
144
 
@@ -77,11 +152,11 @@ module GoogleAnalytics
77
152
  #
78
153
  # JavaScript equivalent:
79
154
  #
80
- # _gaq.push(['_gat._anonymizeIp']);
155
+ # ga('set', 'anonymizeIp', true);
81
156
  #
82
157
  class AnonymizeIp < Event
83
158
  def initialize
84
- super('_gat._anonymizeIp')
159
+ super('set', 'anonymizeIp', true)
85
160
  end
86
161
  end
87
162
 
@@ -89,20 +164,26 @@ module GoogleAnalytics
89
164
  module Ecommerce
90
165
  # JavaScript equivalent:
91
166
  #
92
- # _gaq.push(['_addTrans',
93
- # '1234', // order ID - required
94
- # 'Acme Clothing', // affiliation or store name
95
- # '11.99', // total - required
96
- # '1.29', // tax
97
- # '5', // shipping
98
- # 'San Jose', // city
99
- # 'California', // state or province
100
- # 'USA' // country
101
- # ]);
167
+ # ga('ecommerce:addTransaction', {
168
+ # 'id': '1234',
169
+ # 'affiliation': 'Acme Clothing',
170
+ # 'revenue': '11.99',
171
+ # 'shipping': '5',
172
+ # 'tax': '1.29',
173
+ # 'currency': 'EUR' // local currency code.
174
+ # });
102
175
  #
103
176
  class AddTransaction < Event
104
- def initialize(order_id, store_name, total, tax, shipping, city, state_or_province, country)
105
- super('_addTrans', order_id.to_s, store_name.to_s, total.to_s, tax.to_s, shipping.to_s, city.to_s, state_or_province.to_s, country.to_s)
177
+ def initialize(order_id, store_name, total, tax, shipping, city=nil, state_or_province=nil, country=nil)
178
+ # city.to_s, state_or_province.to_s, country.to_s
179
+
180
+ super('ecommerce:addTransaction', {
181
+ :id => order_id.to_s,
182
+ :affiliation => store_name.to_s,
183
+ :revenue => total.to_s,
184
+ :tax => tax.to_s,
185
+ :shipping => shipping.to_s
186
+ })
106
187
  end
107
188
  end
108
189
 
@@ -119,18 +200,29 @@ module GoogleAnalytics
119
200
  #
120
201
  class AddItem < Event
121
202
  def initialize(order_id, product_id, product_name, product_variation, unit_price, quantity)
122
- super('_addItem', order_id.to_s, product_id.to_s, product_name.to_s, product_variation.to_s, unit_price.to_s, quantity.to_s)
203
+ super('ecommerce:addItem', {
204
+ :id => order_id.to_s,
205
+ :sku => product_id.to_s,
206
+ :name => product_name.to_s,
207
+ :category => product_variation.to_s,
208
+ :price => unit_price.to_s,
209
+ :quantity => quantity.to_s
210
+ })
123
211
  end
124
-
125
212
  end
126
213
 
127
214
  # JavaScript equivalent:
128
215
  #
129
- # _gaq.push(['_trackTrans']);
216
+ # ga('ecommerce:send');
130
217
  #
131
- class TrackTransaction < Event
218
+ class TrackTransaction < SingleEvent
219
+ def initialize
220
+ super('ecommerce:send')
221
+ end
222
+ end
223
+ class ClearTransaction < SingleEvent
132
224
  def initialize
133
- super('_trackTrans')
225
+ super('ecommerce:clear')
134
226
  end
135
227
  end
136
228
  end
@@ -28,10 +28,7 @@ module GoogleAnalytics::Rails
28
28
  # 'Acme Clothing', # affiliation or store name
29
29
  # '11.99', # total - required
30
30
  # '1.29', # tax
31
- # '5', # shipping
32
- # 'San Jose', # city
33
- # 'California', # state or province
34
- # 'USA' # country
31
+ # '5' # shipping
35
32
  # )
36
33
  #
37
34
  # # add an item to the transaction
@@ -51,12 +48,20 @@ module GoogleAnalytics::Rails
51
48
  # Initializes the Analytics javascript. Put it in the `<head>` tag.
52
49
  #
53
50
  # @param options [Hash]
51
+ # @option options [String] :name
52
+ # The name of the Universal Analytics Tracker
53
+ # @option options [Hash] :setup
54
+ # Options for the initial Setup {GoogleAnalytics::Events::SetupAnalytics}
54
55
  # @option options [Boolean] :local (false) Sets the local development mode.
55
56
  # See {http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=741739888e14c07a&hl=en}
56
57
  # @option options [Array, GoogleAnalytics::Event] :add_events ([])
57
58
  # The page views are tracked by default, additional events can be added here.
59
+ # @option options [Boolean] :skip_pageview
60
+ # Turn off pageview tracking
58
61
  # @option options [String] :page
59
62
  # The optional virtual page view to track through {GoogleAnalytics::Events::TrackPageview}
63
+ # @option options [String] :title
64
+ # The optional virtual page view to track through {GoogleAnalytics::Events::TrackPageview}
60
65
  # @option options [String] :tracker
61
66
  # The tracker to use instead of the default {GoogleAnalytics.tracker}
62
67
  # @option options [String] :domain
@@ -68,7 +73,7 @@ module GoogleAnalytics::Rails
68
73
  # @option options [Boolean] :enhanced_link_attribution
69
74
  # See separate information for multiple links on a page that all have the same destination,
70
75
  # see {https://support.google.com/analytics/answer/2558867}.
71
- # @option options [Array, GoogleAnalytics::Events::SetCustomVar] :custom_vars ([])
76
+ # @option options [Array, GoogleAnalytics::Events::SetCustomDimension, GoogleAnalytics::Events::SetCustomMetric] :custom_vars ([])
72
77
  #
73
78
  # @example Set the local bit in development mode
74
79
  # analytics_init :local => Rails.env.development?
@@ -85,36 +90,68 @@ module GoogleAnalytics::Rails
85
90
  end
86
91
 
87
92
  local = options.delete(:local) || false
93
+ setup = options.delete(:setup) || {}
94
+ tracker_name = options.delete(:name) || setup.fetch(:name, nil)
95
+
96
+ # Determine Name
97
+ setup[:name] ||= tracker_name if tracker_name
98
+
99
+ domain = options.delete(:domain) || (local ? "none" : "auto")
100
+
101
+ skip_pageview = options.delete(:skip_pageview) || false
88
102
  anonymize = options.delete(:anonymize) || false
89
103
  custom_vars = options.delete(:custom_vars) || []
90
104
  custom_vars = [custom_vars] unless custom_vars.is_a?(Array)
105
+
91
106
  link_attribution = options.delete(:enhanced_link_attribution) || false
92
- domain = options.delete(:domain) || (local ? "none" : "auto")
107
+
108
+
93
109
  events = options.delete(:add_events) || []
94
110
  events = [events] unless events.is_a?(Array)
95
111
 
96
- queue = GAQ.new
112
+ # Convert older classes when we can
113
+ if events.any?{|x| x.class.name == 'GoogleAnalytics::Events::SetAllowLinker' }
114
+ setup[:allowLinker] = !!events.any?{|x| x.class.name == 'GoogleAnalytics::Events::SetAllowLinker' }
115
+ events.delete_if{|x| x.class.name == 'GoogleAnalytics::Events::SetAllowLinker' }
116
+ end
117
+
118
+ if events.any?{|x| x.class.name == 'GoogleAnalytics::Events::SetSiteSpeedSampleRate' }
119
+ setup[:siteSpeedSampleRate] = events.select{|x| x.class.name == 'GoogleAnalytics::Events::SetSiteSpeedSampleRate' }.first.sample_rate
120
+ events.delete_if{|x| x.class.name == 'GoogleAnalytics::Events::SetSiteSpeedSampleRate' }
121
+ end
97
122
 
123
+ queue = GAQ.new
98
124
  # unshift => reverse order
99
- events.unshift GA::Events::TrackPageview.new(options[:page])
125
+ events.unshift GA::Events::TrackPageview.new({:page => options[:page], :title => options[:title]}) unless skip_pageview
100
126
  # anonymize if needed before tracking the page view
101
127
  events.unshift GA::Events::AnonymizeIp.new if anonymize
102
128
  # custom_var if needed before tracking the page view
103
129
  custom_vars.each do |custom_var|
104
130
  events.unshift custom_var
105
131
  end
106
- events.unshift GA::Events::SetDomainName.new(domain)
132
+
133
+ events.unshift GA::Events::Require.new('linkid') if link_attribution
134
+
135
+ # If this is 'local' env, give the cookieDomain none, and allow linker
107
136
  if local
108
- events.unshift GA::Events::SetAllowLinker.new(true)
137
+ events.unshift GA::Events::SetupAnalytics.new(tracker, setup.merge({
138
+ :cookieDomain => 'none',
139
+ :allowLinker => true
140
+ }))
141
+ # If we have any configs, we'll merge the cookieDomain in
142
+ elsif setup.any?
143
+ events.unshift GA::Events::SetupAnalytics.new(tracker, setup.merge({ :cookieDomain => domain }))
144
+ # Just a normal request
145
+ else
146
+ events.unshift GA::Events::SetupAnalytics.new(tracker, domain)
109
147
  end
110
- events.unshift GA::Events::SetAccount.new(tracker)
111
- events.unshift GA::Events::Require.new(
112
- 'inpage_linkid',
113
- '//www.google-analytics.com/plugins/ga/inpage_linkid.js'
114
- ) if link_attribution
115
-
116
- events.each do |event|
117
- queue << event
148
+
149
+ events.each do |evt|
150
+ if evt.class.name == 'GoogleAnalytics::Events::SetupAnalytics'
151
+ queue.push(evt)
152
+ else
153
+ queue.push(evt, tracker_name)
154
+ end
118
155
  end
119
156
 
120
157
  queue.to_s.html_safe
@@ -145,6 +182,7 @@ module GoogleAnalytics::Rails
145
182
  # Track an ecommerce transaction
146
183
  # @see http://code.google.com/apis/analytics/docs/tracking/gaTrackingEcommerce.html
147
184
  def analytics_add_transaction(order_id, store_name, total, tax, shipping, city, state_or_province, country)
185
+ analytics_render_event(GA::Events::Require.new('ecommerce','ecommerce.js'))
148
186
  analytics_render_event(GA::Events::Ecommerce::AddTransaction.new(order_id, store_name, total, tax, shipping, city, state_or_province, country))
149
187
  end
150
188