Class: TheTracker::Trackers::GUniversal
- Defined in:
- lib/the_tracker/trackers/g_universal.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Base
Instance Method Summary collapse
- #add_custom_var(type, index, value) ⇒ Object
- #add_transaction(tid = 0, store = '', total = 0, tax = 0, shipping = 0) ⇒ Object
- #add_transaction_item(sku = '', product = '', category = '', price = 0, quantity = 0) ⇒ Object
- #add_user_id(uid) ⇒ Object
- #header ⇒ Object
-
#initialize(options) ⇒ GUniversal
constructor
Universal Analytics.
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ GUniversal
Universal Analytics
8 9 10 11 12 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 8 def initialize() @name = .delete(:name) || :guniversal @options = super() end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 5 def name @name end |
Instance Method Details
#add_custom_var(type, index, value) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 23 def add_custom_var(type, index, value) if (type == :dimension) custom_dimensions[index] = value else custom_metrics[index] = value end end |
#add_transaction(tid = 0, store = '', total = 0, tax = 0, shipping = 0) ⇒ Object
14 15 16 17 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 14 def add_transaction(tid=0, store='', total=0, tax=0, shipping=0) tid = Time.now.to_i if (tid.nil?) or (tid.to_s == '0') @transaction = EcommerceTransaction.new(tid, store, total, tax, shipping) end |
#add_transaction_item(sku = '', product = '', category = '', price = 0, quantity = 0) ⇒ Object
19 20 21 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 19 def add_transaction_item(sku='', product='', category='', price=0, quantity=0) @transaction.add_item(sku, product, category, price, quantity) end |
#add_user_id(uid) ⇒ Object
31 32 33 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 31 def add_user_id(uid) @uid = uid end |
#header ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/the_tracker/trackers/g_universal.rb', line 35 def header return if !active <<-EOF <!-- Google Analytics --> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '#{@options[:id]}', 'auto', {#{create_conf}}); ga('#{name}.send', 'pageview'); #{extra_conf} </script> <!-- End Google Analytics --> EOF end |