Class: Staccato::Tracker
- Inherits:
-
Object
- Object
- Staccato::Tracker
- Defined in:
- lib/staccato/tracker.rb
Overview
The ‘Tracker` class has methods to create all `Hit` types
using the tracker and client id
Instance Attribute Summary collapse
-
#hit_defaults ⇒ Object
Returns the value of attribute hit_defaults.
Instance Method Summary collapse
- #adapter=(adapter) ⇒ Object
- #add_adapter(adapter) ⇒ Object
-
#build_event(options = {}) ⇒ Event
Build an event.
-
#build_pageview(options = {}) ⇒ Pageview
Build a pageview.
- #build_screenview(options = {}) ⇒ Object
-
#build_transaction(options = {}) ⇒ Transaction
Build an ecommerce transaction.
-
#build_transaction_item(options = {}) ⇒ TransactionItem
Build an item in an ecommerce transaction.
-
#client_id ⇒ String
The unique client id.
- #default_uri ⇒ Object
-
#event(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an event.
-
#exception(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an exception.
-
#id ⇒ String?
The tracker id for GA.
-
#initialize(id, client_id = nil, options = {}) ⇒ Tracker
constructor
sets up a new tracker.
-
#pageview(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a pageview.
- #screenview(options = {}) ⇒ Object
-
#social(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a social event such as a Facebook Like or Twitter Share.
-
#timing(options = {}, &block) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track timing.
-
#track(params = {}) ⇒ Net::HTTPOK
post the hit to GA collection endpoint.
-
#transaction(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an ecommerce transaction.
-
#transaction_item(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an item in an ecommerce transaction.
Constructor Details
#initialize(id, client_id = nil, options = {}) ⇒ Tracker
sets up a new tracker
13 14 15 16 17 18 19 20 |
# File 'lib/staccato/tracker.rb', line 13 def initialize(id, client_id = nil, = {}) @id = id @client_id = client_id @ssl = .delete(:ssl) || false @adapters = [] self.hit_defaults = end |
Instance Attribute Details
#hit_defaults ⇒ Object
Returns the value of attribute hit_defaults.
7 8 9 |
# File 'lib/staccato/tracker.rb', line 7 def hit_defaults @hit_defaults end |
Instance Method Details
#adapter=(adapter) ⇒ Object
22 23 24 |
# File 'lib/staccato/tracker.rb', line 22 def adapter=(adapter) @adapters = [new_adapter] end |
#add_adapter(adapter) ⇒ Object
26 27 28 |
# File 'lib/staccato/tracker.rb', line 26 def add_adapter(adapter) @adapters << adapter end |
#build_event(options = {}) ⇒ Event
Build an event
80 81 82 |
# File 'lib/staccato/tracker.rb', line 80 def build_event( = {}) Staccato::Event.new(self, ) end |
#build_pageview(options = {}) ⇒ Pageview
Build a pageview
49 50 51 |
# File 'lib/staccato/tracker.rb', line 49 def build_pageview( = {}) Staccato::Pageview.new(self, ) end |
#build_screenview(options = {}) ⇒ Object
64 65 66 |
# File 'lib/staccato/tracker.rb', line 64 def build_screenview( = {}) Staccato::Screenview.new(self, ) end |
#build_transaction(options = {}) ⇒ Transaction
Build an ecommerce transaction
141 142 143 |
# File 'lib/staccato/tracker.rb', line 141 def build_transaction( = {}) Staccato::Transaction.new(self, ) end |
#build_transaction_item(options = {}) ⇒ TransactionItem
Build an item in an ecommerce transaction
154 155 156 |
# File 'lib/staccato/tracker.rb', line 154 def build_transaction_item( = {}) Staccato::TransactionItem.new(self, ) end |
#client_id ⇒ String
The unique client id
38 39 40 |
# File 'lib/staccato/tracker.rb', line 38 def client_id @client_id ||= Staccato.build_client_id end |
#default_uri ⇒ Object
170 171 172 |
# File 'lib/staccato/tracker.rb', line 170 def default_uri Staccato.ga_collection_uri(@ssl) end |
#event(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an event
92 93 94 |
# File 'lib/staccato/tracker.rb', line 92 def event( = {}) build_event().track! end |
#exception(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an exception
113 114 115 |
# File 'lib/staccato/tracker.rb', line 113 def exception( = {}) Staccato::Exception.new(self, ).track! end |
#id ⇒ String?
The tracker id for GA
32 33 34 |
# File 'lib/staccato/tracker.rb', line 32 def id @id end |
#pageview(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a pageview
60 61 62 |
# File 'lib/staccato/tracker.rb', line 60 def pageview( = {}) build_pageview().track! end |
#screenview(options = {}) ⇒ Object
68 69 70 |
# File 'lib/staccato/tracker.rb', line 68 def screenview( = {}) build_screenview().track! end |
#social(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a social event such as a Facebook Like or Twitter Share
103 104 105 |
# File 'lib/staccato/tracker.rb', line 103 def ( = {}) Staccato::Social.new(self, ).track! end |
#timing(options = {}, &block) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track timing
134 135 136 |
# File 'lib/staccato/tracker.rb', line 134 def timing( = {}, &block) Staccato::Timing.new(self, ).track!(&block) end |
#track(params = {}) ⇒ Net::HTTPOK
post the hit to GA collection endpoint
166 167 168 |
# File 'lib/staccato/tracker.rb', line 166 def track(params={}) post(params) end |
#transaction(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an ecommerce transaction
147 148 149 |
# File 'lib/staccato/tracker.rb', line 147 def transaction( = {}) build_transaction().track! end |
#transaction_item(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an item in an ecommerce transaction
160 161 162 |
# File 'lib/staccato/tracker.rb', line 160 def transaction_item( = {}) build_transaction_item().track! end |