Class: TheTracker::Trackers::GAnalytics

Inherits:
Base
  • Object
show all
Defined in:
lib/the_tracker/trackers/g_analytics.rb

Instance Attribute Summary

Attributes inherited from Base

#active

Instance Method Summary collapse

Methods inherited from Base

#body_bottom, #body_top

Constructor Details

#initialize(options) ⇒ GAnalytics

Analytics uat



6
7
8
9
# File 'lib/the_tracker/trackers/g_analytics.rb', line 6

def initialize(options)
  @options = options
  super()
end

Instance Method Details

#add_custom_var(index, name, value, scope) ⇒ Object



24
25
26
# File 'lib/the_tracker/trackers/g_analytics.rb', line 24

def add_custom_var(index, name, value, scope)
  custom_vars[index] = [name, value, scope]
end

#add_transaction(tid = 0, store = '', total = 0, tax = 0, shipping = 0, city = '', state = '', country = '') ⇒ Object



15
16
17
18
# File 'lib/the_tracker/trackers/g_analytics.rb', line 15

def add_transaction(tid=0, store='', total=0, tax=0, shipping=0, city='', state='', country='')
  tid = Time.now.to_i if (tid.nil?) or (tid.to_s == '0')
  @transaction = Transaction.new(tid, store, total, tax, shipping, city, state, country)
end

#add_transaction_item(sku = '', product = '', category = '', price = 0, quantity = 0) ⇒ Object



20
21
22
# File 'lib/the_tracker/trackers/g_analytics.rb', line 20

def add_transaction_item(sku='', product='', category='', price=0, quantity=0)
  @transaction.add_item(sku, product, category, price, quantity)
end

#headerObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/the_tracker/trackers/g_analytics.rb', line 32

def header
  return if !active
  <<-EOF
  <script type="text/javascript">//<![CDATA[
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '#{@options[:id]}']);
  #{extra_conf}
  _gaq.push(['_trackPageview']);
  (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>
  EOF
end

#nameObject



11
12
13
# File 'lib/the_tracker/trackers/g_analytics.rb', line 11

def name
  :ganalytics
end

#track_event(category, action, label = '', value = 0, non_interactive = false) ⇒ Object



28
29
30
# File 'lib/the_tracker/trackers/g_analytics.rb', line 28

def track_event(category, action, label='', value=0, non_interactive=false)
  "_gaq.push(['_trackEvent', '#{category}', '#{action}', '#{label}', #{value}, #{non_interactive}]);"
end