Class: GoogleAnalyticsTools::AsyncTrackingQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/google_analytics_tools/tracking/async_tracking_queue.rb

Constant Summary collapse

SCRIPT =
<<-JAVASCRIPT
<script type="text/javascript">
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
JAVASCRIPT

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAsyncTrackingQueue

Returns a new instance of AsyncTrackingQueue.


19
20
21
# File 'lib/google_analytics_tools/tracking/async_tracking_queue.rb', line 19

def initialize
  @events = []
end

Class Method Details

.scriptObject


15
16
17
# File 'lib/google_analytics_tools/tracking/async_tracking_queue.rb', line 15

def self.script
  SCRIPT
end

Instance Method Details

#<<(event) ⇒ Object


23
24
25
# File 'lib/google_analytics_tools/tracking/async_tracking_queue.rb', line 23

def <<(event)
  push(event)
end

#push(event, tracker_id = nil) ⇒ Object


27
28
29
# File 'lib/google_analytics_tools/tracking/async_tracking_queue.rb', line 27

def push(event, tracker_id = nil)
  @events << renderer_for_event(event, tracker_id)
end

#to_sObject


31
32
33
34
35
36
37
38
# File 'lib/google_analytics_tools/tracking/async_tracking_queue.rb', line 31

def to_s
<<-JAVASCRIPT
<script type="text/javascript">
var _gaq = _gaq || [];
#{@events.map { |event| event.to_s }.join("\n")}
</script>
JAVASCRIPT
end