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
-
#build_event(options = {}) ⇒ Event
Build an event.
-
#build_pageview(options = {}) ⇒ Pageview
Build a pageview.
-
#client_id ⇒ String
The unique client id.
-
#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, hit_defaults = {}) ⇒ Tracker
constructor
sets up a new tracker.
-
#pageview(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a pageview.
-
#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, hit_defaults = {}) ⇒ Tracker
sets up a new tracker
13 14 15 16 17 18 |
# File 'lib/staccato/tracker.rb', line 13 def initialize(id, client_id = nil, hit_defaults = {}) @id = id @client_id = client_id self.hit_defaults = 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
#build_event(options = {}) ⇒ Event
Build an event
62 63 64 |
# File 'lib/staccato/tracker.rb', line 62 def build_event( = {}) Staccato::Event.new(self, ) end |
#build_pageview(options = {}) ⇒ Pageview
Build a pageview
39 40 41 |
# File 'lib/staccato/tracker.rb', line 39 def build_pageview( = {}) Staccato::Pageview.new(self, ) end |
#client_id ⇒ String
The unique client id
28 29 30 |
# File 'lib/staccato/tracker.rb', line 28 def client_id @client_id ||= Staccato.build_client_id end |
#event(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an event
74 75 76 |
# File 'lib/staccato/tracker.rb', line 74 def event( = {}) build_event().track! end |
#exception(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an exception
95 96 97 |
# File 'lib/staccato/tracker.rb', line 95 def exception( = {}) Staccato::Exception.new(self, ).track! end |
#id ⇒ String?
The tracker id for GA
22 23 24 |
# File 'lib/staccato/tracker.rb', line 22 def id @id end |
#pageview(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a pageview
50 51 52 |
# File 'lib/staccato/tracker.rb', line 50 def pageview( = {}) build_pageview().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
85 86 87 |
# File 'lib/staccato/tracker.rb', line 85 def ( = {}) Staccato::Social.new(self, ).track! end |
#timing(options = {}, &block) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track timing
116 117 118 |
# File 'lib/staccato/tracker.rb', line 116 def timing( = {}, &block) Staccato::Timing.new(self, ).track!(&block) end |
#track(params = {}) ⇒ Net::HTTPOK
post the hit to GA collection endpoint
134 135 136 |
# File 'lib/staccato/tracker.rb', line 134 def track(params={}) post(Staccato.tracking_uri, params) end |
#transaction(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an ecommerce transaction
122 123 124 |
# File 'lib/staccato/tracker.rb', line 122 def transaction( = {}) Staccato::Transaction.new(self, ).track! end |
#transaction_item(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an item in an ecommerce transaction
128 129 130 |
# File 'lib/staccato/tracker.rb', line 128 def transaction_item( = {}) Staccato::TransactionItem.new(self, ).track! end |