Class: Staccato::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/staccato/tracker.rb

Overview

The ‘Tracker` class has methods to create all `Hit` types

using the tracker and client id

Author:

  • Tony Pitale

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @id = id
  @client_id = client_id
  @ssl = options.delete(:ssl) || false
  @adapters = []

  self.hit_defaults = options
end

Instance Attribute Details

#hit_defaultsObject

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 = [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(options = {})
  Staccato::Event.new(self, options)
end

#build_pageview(options = {}) ⇒ Pageview

Build a pageview



49
50
51
# File 'lib/staccato/tracker.rb', line 49

def build_pageview(options = {})
  Staccato::Pageview.new(self, options)
end

#build_screenview(options = {}) ⇒ Object



64
65
66
# File 'lib/staccato/tracker.rb', line 64

def build_screenview(options = {})
  Staccato::Screenview.new(self, options)
end

#build_transaction(options = {}) ⇒ Transaction

Build an ecommerce transaction



141
142
143
# File 'lib/staccato/tracker.rb', line 141

def build_transaction(options = {})
  Staccato::Transaction.new(self, options)
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(options = {})
  Staccato::TransactionItem.new(self, options)
end

#client_idString

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_uriObject



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(options = {})
  build_event(options).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(options = {})
  Staccato::Exception.new(self, options).track!
end

#idString?

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(options = {})
  build_pageview(options).track!
end

#screenview(options = {}) ⇒ Object



68
69
70
# File 'lib/staccato/tracker.rb', line 68

def screenview(options = {})
  build_screenview(options).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 social(options = {})
  Staccato::Social.new(self, options).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(options = {}, &block)
  Staccato::Timing.new(self, options).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(options = {})
  build_transaction(options).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(options = {})
  build_transaction_item(options).track!
end