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
-
#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
12 13 14 15 16 17 |
# File 'lib/staccato/tracker.rb', line 12 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
#client_id ⇒ String
The unique client id
27 28 29 |
# File 'lib/staccato/tracker.rb', line 27 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
50 51 52 |
# File 'lib/staccato/tracker.rb', line 50 def event( = {}) Staccato::Event.new(self, ).track! end |
#exception(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track an exception
71 72 73 |
# File 'lib/staccato/tracker.rb', line 71 def exception( = {}) Staccato::Exception.new(self, ).track! end |
#id ⇒ String?
The tracker id for GA
21 22 23 |
# File 'lib/staccato/tracker.rb', line 21 def id @id end |
#pageview(options = {}) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track a pageview
38 39 40 |
# File 'lib/staccato/tracker.rb', line 38 def pageview( = {}) Staccato::Pageview.new(self, ).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
61 62 63 |
# File 'lib/staccato/tracker.rb', line 61 def ( = {}) Staccato::Social.new(self, ).track! end |
#timing(options = {}, &block) ⇒ <Net::HTTPOK] the GA `/collect` endpoint always returns a 200
Track timing
92 93 94 |
# File 'lib/staccato/tracker.rb', line 92 def timing( = {}, &block) Staccato::Timing.new(self, ).track!(&block) end |
#track(params = {}) ⇒ Net::HTTPOK
post the hit to GA collection endpoint
110 111 112 |
# File 'lib/staccato/tracker.rb', line 110 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
98 99 100 |
# File 'lib/staccato/tracker.rb', line 98 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
104 105 106 |
# File 'lib/staccato/tracker.rb', line 104 def transaction_item( = {}) Staccato::TransactionItem.new(self, ).track! end |